/* SMS-Bridge: shared design tokens.
 *
 * Deliberately restrained: a neutral grey scale, one accent, 1px borders
 * instead of shadows, small radii and no gradients. The dashboard picks up the
 * same variables, so the look only has to be defined once.
 */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-alt: #fafafa;
  --line: #e5e7eb;
  --line-strong: #d4d4d8;
  --text: #18181b;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warn: #92400e;
  --warn-soft: #fffbeb;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --radius: 6px;
  --radius-sm: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --shadow-pop: 0 4px 16px rgba(24, 24, 27, .1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-alt); border: 1px solid var(--line);
       border-radius: var(--radius-sm); padding: 1px 5px; }

/* ---------------------------------------------------------------- controls */
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--text); border-radius: var(--radius); padding: 7px 14px;
  font: 500 13px/1.4 var(--font); cursor: pointer;
  /* inline-flex so <a class="btn"> and <button class="btn"> produce the same
   * box: an anchor is inline by default and would otherwise be shorter. */
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}
.btn:hover { background: var(--surface-alt); }
.btn:active { background: #f4f4f5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }
.btn-danger:hover { background: #fee2e2; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .55; cursor: default; }

/* Every text-like control.
 *
 * NOT `input[type=text]`: that is an attribute selector and only matches markup
 * that literally says type="text". An `<input>` with no type attribute *behaves*
 * as a text field but does not match, so it kept the browser default box - which
 * is how ten fields ended up with a 2px inset border, 1px 2px padding and Arial
 * while the field next to them was fully styled.
 */
input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]):not([type=file]),
select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  font: 13.5px/1.5 var(--font);
  transition: border-color .14s ease, box-shadow .14s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; min-height: 72px; font-family: var(--mono); font-size: 12.5px; }
/* Native checkboxes, but in the app's accent instead of the OS default blue. */
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.hint { font-size: 12.5px; color: var(--text-faint); margin-top: 5px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); }
.checkbox input { width: auto; margin: 0; }

/* ----------------------------------------------------------------- layout */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 14.5px; font-weight: 600; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.topbar nav { display: flex; gap: 4px; align-items: center; }
/* Not scoped to `nav`: on the settings page the logout form sits beside the nav
 * rather than inside it, so the same button rendered as an unstyled default box
 * there while looking right on the dashboard. */
.topbar a, .topbar button.link {
  color: var(--text-muted); font-size: 13px; padding: 6px 10px;
  border-radius: var(--radius-sm); border: 0; background: none; cursor: pointer;
  font-family: var(--font);
}
.topbar a:hover, .topbar button.link:hover {
  background: var(--surface-alt); color: var(--text); text-decoration: none;
}
.topbar a.active { color: var(--text); background: var(--surface-alt); }

.page { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }
.page-narrow { max-width: 720px; }
h1 { font-size: 18px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 14px; }
.sub { color: var(--text-muted); margin: 0 0 22px; font-size: 13.5px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }

/* ------------------------------------------------------------------ forms */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.actions .spacer { flex: 1; }

/* ---------------------------------------------------------------- banners */
.banner {
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px;
  margin-bottom: 16px; border: 1px solid var(--line);
}
.banner-error { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.banner-warn { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); }
.banner-ok { background: var(--ok-soft); border-color: #bbf7d0; color: var(--ok); }

/* -------------------------------------------------------------- key/value */
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; word-break: break-all; }

.header-row { display: grid; grid-template-columns: 1fr 1fr 32px; gap: 8px; margin-bottom: 8px; }
.header-row button {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer; font-size: 15px; line-height: 1;
}
.header-row button:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  /* overflow-y must be stated: declaring only overflow-x leaves overflow-y as
   * `visible`, which the spec turns into `auto` - and the active tab's
   * margin-bottom:-1px is exactly 1px of vertical overflow, so a vertical
   * scrollbar appeared in a strip that never scrolls vertically. */
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin;
}
.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.tabs::-webkit-scrollbar-track { background: transparent; }
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 8px 14px; margin-bottom: -1px; white-space: nowrap;
  font: 400 13.5px/1.5 var(--font); color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color .14s ease, border-color .14s ease;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  color: var(--text); font-weight: 500; border-bottom-color: var(--accent);
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-panel[hidden] { display: none; }

/* ------------------------------------------------------------------ table */
.log-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.log-table th {
  text-align: left; font-weight: 500; color: var(--text-muted); font-size: 12px;
  padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--surface);
}
.log-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.log-table tr:hover td { background: var(--surface-alt); }
.log-time { color: var(--text-faint); white-space: nowrap; font-family: var(--mono); }
.log-source { color: var(--text-muted); white-space: nowrap; }
.log-msg { font-family: var(--mono); white-space: pre-wrap; word-break: break-word; }
.log-scroll { max-height: 460px; overflow: auto; border: 1px solid var(--line);
              border-radius: var(--radius); }

.pill { display: inline-block; padding: 1px 7px; border-radius: 999px;
        font-size: 11.5px; border: 1px solid var(--line); background: var(--surface-alt);
        color: var(--text-muted); }
.pill-INFO { color: #1d4ed8; background: var(--accent-soft); border-color: #dbeafe; }
.pill-WARNING { color: var(--warn); background: var(--warn-soft); border-color: #fde68a; }
.pill-ERROR, .pill-CRITICAL { color: var(--danger); background: var(--danger-soft);
                              border-color: #fecaca; }
.pill-DEBUG { color: var(--text-faint); }
.pill-OK { color: var(--ok); background: var(--ok-soft); border-color: #bbf7d0; }

/* ------------------------------------------------------------ conversations */
.chat { display: grid; grid-template-columns: 308px 1fr; height: calc(100vh - 52px); }

.peers { border-right: 1px solid var(--line); background: var(--surface);
         display: flex; flex-direction: column; min-height: 0; }
.peers-head { padding: 10px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.peers-head input { flex: 1; }
.peer-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.peer {
  padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
  transition: background-color .12s ease;
}
.peer:hover { background: var(--surface-alt); }
.peer.active { background: var(--accent-soft); }
.peer-name { font-weight: 500; font-size: 13.5px; }
.peer-time { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; }
.peer-preview { color: var(--text-muted); font-size: 12.5px; grid-column: 1 / 2;
                overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-badge { grid-column: 2; grid-row: 2; justify-self: end;
              background: var(--accent); color: #fff; border-radius: 999px;
              font-size: 11px; min-width: 18px; text-align: center; padding: 1px 6px; }
.peers-empty, .thread-empty { color: var(--text-faint); font-size: 13px; padding: 20px 14px; }

.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.thread-head { padding: 11px 18px; border-bottom: 1px solid var(--line);
               background: var(--surface); font-size: 13.5px; font-weight: 500; }
.thread-head .muted { color: var(--text-muted); font-weight: 400; margin-left: 8px; font-size: 12.5px; }
.bubbles { flex: 1; overflow-y: auto; padding: 18px; display: flex;
           flex-direction: column; gap: 10px; min-height: 0; }
.bubble { max-width: min(560px, 72%); padding: 8px 12px; border-radius: 10px;
          font-size: 13.5px; line-height: 1.55; white-space: pre-wrap;
          word-break: break-word; border: 1px solid var(--line); }
.bubble-in { align-self: flex-start; background: var(--surface); }
.bubble-out { align-self: flex-end; background: var(--accent-soft); border-color: #dbeafe; }
.bubble-time { display: block; margin-top: 4px; font-size: 11px;
               color: var(--text-faint); font-family: var(--mono); }
.bubble-out .bubble-time { text-align: right; }
.bubble.failed { border-color: #fecaca; background: var(--danger-soft); }
.day-sep { align-self: center; color: var(--text-faint); font-size: 11.5px; margin: 6px 0; }

.composer { border-top: 1px solid var(--line); background: var(--surface);
            padding: 10px 14px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 40px; max-height: 140px;
                     font-family: var(--font); font-size: 13.5px; }
.composer .btn { height: 36px; }
@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; }
  .chat.show-thread .peers { display: none; }
  .chat:not(.show-thread) .thread { display: none; }
}

/* --------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(24, 24, 27, .38); padding: 20px;
}
.overlay[hidden] { display: none; }

.busy {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 24px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-pop); font-size: 13.5px;
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 20px 22px; width: 100%; max-width: 400px; box-shadow: var(--shadow-pop);
}
.modal h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.modal p { margin: 0; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }
.modal .actions { margin-top: 18px; }

/* ------------------------------------------------------------------- auth */
.auth-body { display: flex; align-items: center; justify-content: center;
             min-height: 100vh; padding: 24px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 28px 26px;
}
.auth-title { font-size: 17px; font-weight: 600; margin: 0 0 2px; letter-spacing: -.01em; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
.auth-form .btn { margin-top: 20px; }
.auth-form input { margin-bottom: 14px; }

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page { padding: 16px 14px 40px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
}
