:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #dfe3ea;
  --text: #1c2430;
  --muted: #667085;
  --accent: #1f5fd0;
  --accent-soft: #e6eefc;
  --danger: #c0362c;
  --ok: #1f7a48;
  --warn: #a15c00;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  padding: 7px 12px;
}
button:hover { background: #f0f3f8; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #1a51b3; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.link:hover { text-decoration: underline; background: none; }

input[type=text], input[type=password], input[type=search], input[type=number], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label { display: block; font-weight: 600; margin: 12px 0 4px; }
.hint { color: var(--muted); font-size: 12.5px; }
.error { color: var(--danger); margin-top: 10px; min-height: 1.4em; }

/* ---------- sign-in and setup ---------- */

.center {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card .primary { width: 100%; margin-top: 18px; padding: 10px; }
.addr-row { display: flex; align-items: center; gap: 6px; }
.addr-row span { color: var(--muted); white-space: nowrap; }

/* ---------- app shell ---------- */

.shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; height: 100%; }

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; width: 188px; flex: none; }
.topbar .search { flex: 1; max-width: 560px; }
.topbar .who { margin-left: auto; text-align: right; line-height: 1.25; }
.topbar .who small { color: var(--muted); display: block; }

.sidebar { padding: 14px 10px; border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; }
.sidebar .primary { width: 100%; padding: 10px; margin-bottom: 14px; }
.nav-title { margin: 18px 10px 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.nav-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
}
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .badge { font-size: 12px; font-weight: 700; }

.main { overflow-y: auto; padding: 18px 22px; min-width: 0; }
.main h2 { margin: 0 0 14px; font-size: 18px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel.pad { padding: 18px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 6px; font-size: 15px; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- message list ---------- */

.msg-row {
  display: grid;
  grid-template-columns: 200px 1fr auto;
  gap: 12px;
  align-items: baseline;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  text-align: left;
}
.msg-row:last-child { border-bottom: 0; }
.msg-row:hover { background: #f7f9fc; }
.msg-row.unread { background: #fff; font-weight: 700; }
.msg-row.unread .snippet { font-weight: 400; }
.msg-row .who, .msg-row .line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row .snippet { color: var(--muted); }
.msg-row .when { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-weight: 400; }

.tag { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 10px; margin-right: 6px; }
.tag.failed { background: #fbe9e7; color: var(--danger); }
.tag.partial { background: #fff1dc; color: var(--warn); }
.tag.ok { background: #e3f4ea; color: var(--ok); }

/* ---------- message view ---------- */

.msg-head { padding: 18px; border-bottom: 1px solid var(--line); }
.msg-head h2 { margin: 0 0 10px; font-size: 19px; overflow-wrap: anywhere; }
.msg-head .meta { color: var(--muted); overflow-wrap: anywhere; }
.msg-head .meta b { color: var(--text); }
.msg-body { padding: 18px; }
.msg-body pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.msg-body iframe { width: 100%; height: 60vh; border: 0; }
.status-box { margin: 0 18px 18px; padding: 10px 12px; border-radius: 6px; background: #f4f6f9; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.attachments { padding: 0 18px 18px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachments a { border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; color: var(--accent); text-decoration: none; }
.attachments a:hover { background: var(--accent-soft); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.mono, .mono { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; overflow-wrap: anywhere; word-break: break-all; }
td.actions { white-space: nowrap; }
td.actions button { padding: 4px 9px; margin-right: 4px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.radio-row { display: flex; gap: 18px; margin: 6px 0; }
.radio-row label { font-weight: 400; margin: 0; display: flex; gap: 6px; align-items: center; }
.result { margin-top: 10px; padding: 10px 12px; border-radius: 6px; background: #f4f6f9; overflow-wrap: anywhere; }
.result.ok { background: #e3f4ea; color: var(--ok); }
.result.bad { background: #fbe9e7; color: var(--danger); }

/* ---------- dialogs ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.dialog {
  width: 100%;
  max-width: 680px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
}
.dialog.small { max-width: 420px; }
.dialog h3 { margin: 0 0 4px; font-size: 17px; }
.dialog textarea { min-height: 220px; resize: vertical; }
.dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1c2430;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  max-width: calc(100% - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 20;
}
#toast.show { opacity: 1; }

/* ---------- phones ---------- */

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .brand { width: auto; }
  .topbar .search { order: 3; flex-basis: 100%; max-width: none; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px; align-items: center; }
  .sidebar .primary { width: auto; margin: 0; padding: 7px 12px; flex: none; }
  .nav-title { display: none; }
  .nav-item { width: auto; flex: none; gap: 6px; }
  .main { padding: 14px 16px; }
  .msg-row { grid-template-columns: 1fr auto; }
  .msg-row .line { grid-column: 1 / -1; grid-row: 2; }
  .grid2 { grid-template-columns: 1fr; }
}
