/* R3COMM Client Connect - one stylesheet. Tokens first, then layout, then components. */
:root {
  --bg: #F3F6F4; --panel: #FFFFFF; --ink: #17302A; --ink-soft: #5B6E69; --line: #D9E2DE;
  --action: #0F7B6C; --action-ink: #FFFFFF; --warn: #B7781C; --error: #A8352B; --ok: #2E7D4F;
  --in-bubble: #FFFFFF; --out-bubble: #DCEFE8; --rail: #17302A; --rail-ink: #CFE0DA;
  --code-bg: #E8EFEC; --bar-track: #E6EDEA; --thread-bg: #F7FAF8; --hover: #EEF4F1; --note-bg: #FBF3E6; --note-line: #ECD3A6;
  --radius: 6px; --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}
/* Dark theme: same variables, different values. Applied when the user chose
   "dark", or when the OS is dark and the user has not chosen "light". */
:root[data-theme="dark"],
:root:not([data-theme="light"]):not([data-theme="dark"]).system-dark {
  --bg: #121A18; --panel: #1A2421; --ink: #E4ECE9; --ink-soft: #93A6A0; --line: #2C3B37;
  --action: #3DB39E; --action-ink: #0E1A17; --warn: #D9A04B; --error: #E07068; --ok: #5CC08A;
  --in-bubble: #22302C; --out-bubble: #1E4A40; --rail: #0C1210; --rail-ink: #A9BDB6;
  --code-bg: #26332F; --bar-track: #26332F; --thread-bg: #151E1B; --hover: #22302C; --note-bg: #332A17; --note-line: #5A4620;
  color-scheme: dark;
}
:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--action); }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 24px 0 8px; }
p { margin: 0 0 10px; max-width: 70ch; }
code { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 13px; background: var(--code-bg, #E8EFEC); padding: 1px 4px; border-radius: 3px; }

/* Layout: rail + content */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; }
.rail .brand { color: #fff; font-weight: 600; font-size: 15px; margin-bottom: 18px; padding: 0 8px; }
.rail a { color: var(--rail-ink); text-decoration: none; padding: 8px 10px; border-radius: var(--radius); display: flex; justify-content: space-between; }
.rail a:hover, .rail a.active { background: rgba(255,255,255,.1); color: #fff; }
.rail .section { font-size: 12px; color: #86A199; margin: 14px 10px 4px; }
.rail .spacer { flex: 1; }
.rail form { margin: 0; }
.rail select { width: 100%; background: #23433B; color: #fff; border: 1px solid #3A5C53; border-radius: var(--radius); padding: 6px; font: inherit; }
.rail .me { font-size: 13px; padding: 8px 10px; color: #fff; }
.rail .me small { display: block; color: #86A199; }
.rail button.link { background: none; border: 0; color: var(--rail-ink); padding: 8px 10px; cursor: pointer; font: inherit; text-align: left; width: 100%; border-radius: var(--radius); }
.rail button.link:hover { background: rgba(255,255,255,.1); color: #fff; }
.content { padding: 28px 32px; min-width: 0; }
.badge { background: var(--action); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; }

/* Flash messages */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border-left: 4px solid var(--action); background: var(--panel); }
.flash.warn { border-color: var(--warn); } .flash.error { border-color: var(--error); }

/* Forms and buttons */
label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); font: inherit; background: var(--panel); color: var(--ink); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--action); outline-offset: 1px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; } .row .field { flex: 1; min-width: 140px; margin: 0; }
button, .btn { font: inherit; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--action); background: var(--action); color: var(--action-ink); cursor: pointer; }
button.quiet, .btn.quiet { background: var(--panel); color: var(--ink); border-color: var(--line); }
button.danger { background: var(--panel); color: var(--error); border-color: var(--error); }
button:disabled { opacity: .5; cursor: not-allowed; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; }
.muted { color: var(--ink-soft); font-size: 13px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { font-weight: 600; color: var(--ink-soft); font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.wrap { overflow-x: auto; }

/* Overview: the day meter is the one memorable element */
.meter { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.meter .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.meter .count { font-size: 34px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.meter .count small { font-size: 15px; font-weight: 400; color: var(--ink-soft); margin-left: 6px; }
.meter .bar { height: 18px; background: var(--bar-track); border-radius: 4px; overflow: hidden; position: relative; }
.meter .bar > span { display: block; height: 100%; background: var(--action); transition: width .4s; }
.meter.warn .bar > span { background: var(--warn); } .meter.over .bar > span { background: var(--error); }
.meter .bar i { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(23,48,42,.25); }
.meter .foot { display: flex; gap: 20px; margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.stats { display: flex; gap: 28px; margin: 6px 0 22px; }
.stats div b { display: block; font-size: 22px; font-weight: 600; } .stats div span { font-size: 13px; color: var(--ink-soft); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 140px; padding: 0 4px; }
.week .col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; }
.week .col b { background: var(--action); border-radius: 3px 3px 0 0; } .week .col i { background: var(--action); opacity: .45; }
.week .col span { font-size: 11px; color: var(--ink-soft); text-align: center; margin-top: 4px; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 300px 1fr 280px; gap: 0; height: calc(100vh - 56px); border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); overflow: hidden;
  grid-template-rows: minmax(0, 1fr); } /* one row exactly as tall as the box, so long threads scroll inside it */
.inbox.two { grid-template-columns: 300px 1fr; }
.list { border-right: 1px solid var(--line); overflow-y: auto; }
.list .filter { padding: 10px; border-bottom: 1px solid var(--line); display: flex; gap: 6px; }
.list .filter-form { gap: 6px; flex-wrap: nowrap; } .list .filter-form select { flex: 1; min-width: 0; }
.thread .assign { font-size: 13px; margin-top: 2px; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin-left: 6px; }
.inline-form select { width: auto; padding: 2px 6px; font-size: 13px; }
.inline-form .link-button { color: var(--action); margin-top: 0; font-size: 13px; }
.list a.item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.list a.item:hover, .list a.item.active { background: var(--hover); }
.list .name { font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.list .meta { font-size: 12px; color: var(--ink-soft); display: flex; justify-content: space-between; margin-top: 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 4px; } .dot.closed { background: #B0BDB8; }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; } /* min-height 0: let .msgs shrink and scroll */
.thread .top { flex-shrink: 0; padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.thread .top b { font-size: 15px; }
.thread .top button { white-space: nowrap; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; background: var(--thread-bg); }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--in-bubble); word-wrap: break-word; }
.msg .body { white-space: pre-wrap; }
.msg-img { display: block; max-width: 100%; max-height: 260px; border-radius: 6px; margin-bottom: 4px; } /* photo in the thread */
.msg-file { display: inline-block; margin-bottom: 4px; } /* document / audio / video download */
.ticket-dialog { max-width: 560px; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: inherit; padding: 18px; }
.ticket-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.ticket-description { white-space: pre-wrap; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.msg.note { align-self: center; max-width: 90%; background: transparent; border-style: dashed; color: var(--ink-soft); font-size: 13px; text-align: center; }
.msg.outbound { align-self: flex-end; background: var(--out-bubble); border-color: transparent; }
.msg .time { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 4px; }
.msg .time.failed { color: var(--error); }
.link-button { background: none; border: 0; padding: 0; margin-top: 4px; color: var(--error); font-size: 12px; text-decoration: underline; cursor: pointer; } /* Delete on a failed message */
.compose { border-top: 1px solid var(--line); padding: 12px 18px; flex-shrink: 0; } /* reply box always visible */
.compose textarea { height: 70px; resize: vertical; }
.compose .actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.compose .closed-note { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 10px; font-size: 13px; }
.side { border-left: 1px solid var(--line); padding: 14px; overflow-y: auto; font-size: 14px; }
.side h3 { margin: 0 0 10px; font-size: 14px; }
.side dl { margin: 0 0 12px; } .side dt { font-size: 12px; color: var(--ink-soft); } .side dd { margin: 0 0 6px; }
.empty { padding: 40px; text-align: center; color: var(--ink-soft); }
.login { max-width: 360px; margin: 12vh auto; }
.login .panel { padding: 28px; }
.status-pill { font-size: 11px; padding: 1px 6px; border-radius: 3px; background: var(--bar-track); }
.status-pill.failed, .status-pill.delivery_failed { background: #F6E0DD; color: var(--error); }
.status-pill.delivered { background: #DDF0E5; color: var(--ok); }
details summary { cursor: pointer; color: var(--action); font-size: 13px; }
@media (max-width: 900px) { .shell { grid-template-columns: 1fr; } .rail { flex-direction: row; flex-wrap: wrap; } .inbox, .inbox.two { grid-template-columns: 1fr; grid-template-rows: none; height: auto; } .msgs { max-height: 60vh; } .side, .list { border: 0; } .stats { flex-wrap: wrap; } }
@media (prefers-reduced-motion: reduce) { .meter .bar > span { transition: none; } }
/* Two-step login: QR code and backup codes */
.qr { background: #fff; display: inline-block; padding: 10px; border-radius: var(--radius); margin: 8px 0; }
.qr svg { display: block; width: 200px; height: 200px; }
.codes { columns: 2; list-style: none; padding: 0; font-size: 16px; line-height: 2; max-width: 360px; }
