/* EmCapture UI. Light/dark, comfortable/compact density, responsive (phone, tablet, desktop). */
:root {
  --accent: #1f6f8b;
  --accent-2: #eea62e;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --panel-2: #eef3f6;
  --text: #17232e;
  --muted: #5d6f7d;
  --line: #d6e0e7;
  --ok: #1e8a4c;
  --warn: #b7791f;
  --err: #c53030;
  --info: #2b6cb0;
  --radius: 10px;
  --gap: 14px;
  --pad: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --side: 232px;
}
[data-theme="dark"] {
  --bg: #0e1620;
  --panel: #16222e;
  --panel-2: #1d2c3b;
  --text: #e6eef5;
  --muted: #95a7b6;
  --line: #2b3d4f;
}
[data-density="compact"] { --gap: 8px; --pad: 9px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
h1 { font-size: 1.5rem; margin: 0 0 6px; }
h2 { font-size: 1.2rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.fine { font-size: 0.78rem; color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* buttons + inputs */
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 9px; min-height: 30px; font-size: 0.85rem; }
.btn.icon { width: 40px; padding: 0; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.accent { background: var(--accent-2); border-color: var(--accent-2); color: #1a1a1a; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.row { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); }
.card + .card { margin-top: var(--gap); }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.chip.ok { color: var(--ok); border-color: var(--ok); }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.chip.err { color: var(--err); border-color: var(--err); }
.chip.info { color: var(--info); border-color: var(--info); }
.badge { font-size: 0.75rem; padding: 3px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.badge.test { background: #fff4d6; color: #7a4f00; }
.badge.live { background: #ffe0e0; color: #7a0000; }
[data-theme="dark"] .badge.test { background: #3a2f10; color: #f6d27a; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: calc(var(--pad) * 0.6) var(--pad); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
tr.click:hover td { background: var(--panel-2); cursor: pointer; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: var(--gap); }
.tab { background: none; border: none; padding: 10px 12px; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; font: inherit; min-height: 42px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.page-head { display: flex; align-items: center; gap: var(--gap); flex-wrap: wrap; margin-bottom: var(--gap); }
.page-head h2 { margin: 0; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* login */
.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(160deg, #1f6f8b, #0e3a4a); }
.login-card { background: var(--panel); color: var(--text); padding: 28px; border-radius: 14px; width: min(380px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { text-align: center; }
.login-card p { text-align: center; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; margin: 0 auto 8px; letter-spacing: 0.5px; }
.brand-mark.sm { width: 34px; height: 34px; margin: 0; font-size: 0.85rem; }

/* app shell */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-head { display: flex; gap: 10px; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
#nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; overflow-y: auto; flex: 1; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; min-height: 40px; }
#nav a:hover { background: var(--panel-2); }
#nav a.active { background: var(--accent); color: #fff; }
#nav .count { margin-left: auto; font-size: 0.75rem; background: var(--accent-2); color: #1a1a1a; border-radius: 999px; padding: 1px 7px; }
.side-foot { padding: 12px; border-top: 1px solid var(--line); }
.main-wrap { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; gap: 8px; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
#menu-btn { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 560px; }
.search-wrap input { min-height: 40px; }
.search-results { position: absolute; top: 44px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.18); max-height: 420px; overflow-y: auto; z-index: 40; }
.search-results a { display: block; padding: 10px 12px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--line); }
.search-results a:hover { background: var(--panel-2); }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.view { padding: 18px; max-width: 1400px; width: 100%; margin: 0 auto; outline: none; }

/* assistant */
.assistant { position: fixed; right: 16px; bottom: 16px; width: min(380px, calc(100vw - 32px)); height: min(560px, 75vh); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 44px rgba(0,0,0,.25); display: flex; flex-direction: column; padding: 12px; z-index: 60; }
.assistant-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.assistant-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px; }
.msg { padding: 8px 11px; border-radius: 10px; max-width: 90%; white-space: pre-wrap; font-size: 0.93rem; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.bot { align-self: flex-start; background: var(--panel-2); }
.assistant-form { display: flex; gap: 6px; margin-top: 8px; }
.assistant-form input { flex: 1; }

/* toasts + modal */
.toast-root { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1d2c3b; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 22px rgba(0,0,0,.25); max-width: 92vw; }
.toast.err { background: #7a1f1f; }
.toast.ok { background: #1e5b3a; }
.modal-back { position: fixed; inset: 0; background: rgba(5,12,18,.55); display: grid; place-items: center; z-index: 90; padding: 14px; }
.modal { background: var(--panel); color: var(--text); border-radius: 14px; width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* schedule */
.week { display: grid; grid-template-columns: 56px repeat(7, minmax(120px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--panel); }
.week .hour { font-size: 0.72rem; color: var(--muted); border-top: 1px solid var(--line); padding: 2px 4px; height: 48px; }
.week .dayhead { position: sticky; top: 0; background: var(--panel-2); padding: 8px; font-size: 0.85rem; text-align: center; border-bottom: 1px solid var(--line); z-index: 2; }
.week .daycol { position: relative; border-left: 1px solid var(--line); min-height: calc(48px * 12); }
.week .slot { height: 48px; border-top: 1px solid var(--line); }
.evt { position: absolute; left: 4px; right: 4px; border-radius: 7px; padding: 4px 6px; font-size: 0.78rem; background: var(--accent); color: #fff; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.evt.completed { background: #2f855a; }
.evt.cancelled { background: #888; text-decoration: line-through; }
.evt.draft { outline: 2px dashed var(--accent-2); outline-offset: -2px; }
.evt .t { font-weight: 600; }
.travel { position: absolute; left: 4px; right: 4px; border-radius: 6px; font-size: 0.7rem; background: repeating-linear-gradient(45deg, #eef3f6, #eef3f6 6px, #dde7ee 6px, #dde7ee 12px); color: #35495a; padding: 2px 4px; border: 1px dashed #8aa0b0; }
.travel.warn { background: repeating-linear-gradient(45deg, #ffe7e7, #ffe7e7 6px, #ffd0d0 6px, #ffd0d0 12px); border-color: var(--err); color: #7a0000; }
.day-list .item { display: flex; gap: 10px; padding: 10px; border-bottom: 1px solid var(--line); align-items: center; }
.day-list .item .time { width: 110px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* notes editor */
.note-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap); align-items: start; }
.note-main { min-width: 0; }
.note-side { position: sticky; top: 72px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); margin-bottom: var(--gap); }
.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.section-head h3 { margin: 0; flex: 1; }
.field-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ai-sugg { margin-top: 6px; background: var(--panel-2); border-radius: 8px; padding: 8px; font-size: 0.9rem; border-left: 3px solid var(--accent-2); white-space: pre-wrap; }
.issue { padding: 8px 10px; border-radius: 8px; margin-bottom: 6px; font-size: 0.88rem; border-left: 4px solid var(--info); background: var(--panel-2); }
.issue.error { border-left-color: var(--err); }
.issue.warning { border-left-color: var(--warn); }
.issue .fix { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.sig-box { border: 1px dashed var(--muted); border-radius: 10px; background: #fff; position: relative; }
.sig-box canvas { width: 100%; height: 160px; display: block; touch-action: none; border-radius: 10px; }
.sig-img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; height: 90px; object-fit: contain; }
.drag-note { font-size: 0.78rem; color: var(--muted); }
.draft-bar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; background: #fff4d6; color: #5c3c00; margin-bottom: var(--gap); font-size: 0.9rem; }
[data-theme="dark"] .draft-bar { background: #3a2f10; color: #f6d27a; }

/* claims */
.scrub-ok { color: var(--ok); font-weight: 600; }
.timeline li { margin-bottom: 8px; }

/* responsive */
@media (max-width: 1024px) {
  .note-layout { grid-template-columns: 1fr; }
  .note-side { position: static; }
  .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s ease; z-index: 70; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.3); }
  #menu-btn { display: inline-flex; }
  .user-chip span { display: none; }
  .view { padding: 12px; }
  .assistant { left: 8px; right: 8px; width: auto; bottom: 8px; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .topbar { flex-wrap: wrap; }
  .search-wrap { order: 5; flex-basis: 100%; max-width: none; }
  .week { grid-template-columns: 40px repeat(7, 110px); }
  input, select, textarea { font-size: 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .note-side .card { padding: 10px; }
}
@media print {
  .sidebar, .topbar, .assistant, .toast-root, .no-print { display: none !important; }
  .app { display: block; }
  .view { padding: 0; }
  .card, .section { border: none; }
  body { background: #fff; color: #000; }
}
