/* AI Virtual Holding — dashboard styles. No framework, no external fonts. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #1b1f24;
  --muted: #5d6673;
  --primary: #1f5fbf;
  --primary-contrast: #ffffff;
  --primary-soft: #e6eefb;
  --ok: #16794a;
  --ok-soft: #e3f4ea;
  --warn: #a15c00;
  --warn-soft: #fdf1dc;
  --err: #b42318;
  --err-soft: #fde8e6;
  --info: #3b5bdb;
  --info-soft: #e8ecfd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --sidebar: 236px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1d222a;
    --border: #2a313b;
    --text: #e7eaee;
    --muted: #98a2b0;
    --primary: #6aa2ff;
    --primary-contrast: #0b1220;
    --primary-soft: #1a2944;
    --ok: #4cc38a;
    --ok-soft: #12291e;
    --warn: #f0b354;
    --warn-soft: #2e2413;
    --err: #ff7b72;
    --err-soft: #331816;
    --info: #8da4ff;
    --info-soft: #1b2140;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1d222a;
  --border: #2a313b;
  --text: #e7eaee;
  --muted: #98a2b0;
  --primary: #6aa2ff;
  --primary-contrast: #0b1220;
  --primary-soft: #1a2944;
  --ok: #4cc38a;
  --ok-soft: #12291e;
  --warn: #f0b354;
  --warn-soft: #2e2413;
  --err: #ff7b72;
  --err-soft: #331816;
  --info: #8da4ff;
  --info-soft: #1b2140;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 16px 16px 12px; }
.brand-lg { font-size: 20px; padding: 0 0 4px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 5px; flex: none;
  background: conic-gradient(#f4d35e 0 25%, #5dd39e 0 50%, #93c5fd 0 75%, #e07a2f 0);
  box-shadow: inset 0 0 0 3px #1f3a5f;
}
#nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 1px; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 12px 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--text);
  text-decoration: none !important;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link .count { margin-left: auto; font-size: 11px; background: var(--err); color: #fff; border-radius: 9px; padding: 0 6px; }
.nav-ico { width: 18px; text-align: center; opacity: 0.85; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sidebar-foot #user-name { flex: 1 0 100%; font-size: 12.5px; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
#menu-btn { display: none; }
.view { padding: 20px 24px 48px; max-width: 1280px; width: 100%; outline: none; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 19; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform 0.18s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  #menu-btn { display: inline-flex; }
  .topbar { padding: 8px 16px; }
  .view { padding: 16px 16px 40px; }
  #queue-pill { display: none; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none !important; min-height: 34px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, black); }
.btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 4px 9px; min-height: 28px; font-size: 13px; }
.btn-icon { padding: 4px 8px; }
.btn-block { width: 100%; }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.badge { display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.b-completed, .b-ok, .b-active, .b-sent, .b-approved { background: var(--ok-soft); color: var(--ok); }
.b-failed, .b-error, .b-auth_error, .b-quota, .b-rejected, .b-unsupported { background: var(--err-soft); color: var(--err); }
.b-pending, .b-assigned, .b-rate_limited, .b-sending, .b-inactive { background: var(--warn-soft); color: var(--warn); }
.b-processing, .b-running, .b-info { background: var(--info-soft); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; width: 100%; min-height: 34px;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--primary); }
input[type="color"] { padding: 2px; height: 34px; width: 48px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.form-error { color: var(--err); min-height: 1.2em; margin: 0; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 12px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none !important; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.list { display: flex; flex-direction: column; }
.list-item { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; }
.list-item:last-child { border-bottom: 0; }

/* business cards */
.biz-card { display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--biz, var(--primary)); }
.biz-logo {
  width: 44px; height: 44px; border-radius: 9px; flex: none; object-fit: cover; background: var(--biz, var(--primary));
  color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px;
}
.biz-logo-lg { width: 64px; height: 64px; font-size: 24px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }

/* org chart */
.org { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.org-node { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; display: flex; gap: 10px; align-items: center; min-width: 190px; box-shadow: var(--shadow); }
.org-node .who { font-weight: 600; }
.org-level { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; width: 100%; }
.org-branch { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding: 12px; border: 1px dashed var(--border); border-radius: 12px; min-width: 220px; flex: 1 1 240px; max-width: 360px; }
.org-branch h4 { font-size: 13px; display: flex; gap: 6px; align-items: center; }
.org-connector { width: 2px; height: 16px; background: var(--border); }
.avatar-canvas { image-rendering: pixelated; flex: none; }

/* markdown output */
.md { overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; font-size: 15px; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { margin: 8px 0; font-size: 13px; }
.md blockquote { border-left: 3px solid var(--border); margin: 6px 0; padding-left: 10px; color: var(--muted); }
.result-box { max-height: 520px; overflow-y: auto; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 620px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; max-height: 88vh; }
.modal-wide { max-width: 900px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow); font-size: 13.5px; }
.toast-error { background: var(--err); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }

/* office */
.office-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .office-layout { grid-template-columns: minmax(0, 1fr); } }
.office-panel { max-height: 78vh; overflow-y: auto; position: sticky; top: 64px; }
@media (max-width: 1100px) { .office-panel { position: static; max-height: none; } }
.office-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.office-tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.office-tab.active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.office-tab .count { font-size: 11px; background: var(--info); color: #fff; border-radius: 9px; padding: 0 6px; }
.office-zoom { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; z-index: 2; }
.office-zoom .btn { min-width: 30px; background: rgba(23, 27, 33, 0.82); color: #fff; border-color: rgba(255, 255, 255, 0.2); }
.office-biz-link { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.office-biz-link:hover { border-color: var(--primary); }
.state-chip { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 5px; color: #fff; background: var(--c); }
.office-wrap { position: relative; background: #2a2a35; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.office-wrap canvas { display: block; width: 100%; image-rendering: pixelated; cursor: grab; touch-action: none; outline: none; }
.office-wrap canvas:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.office-tip {
  position: absolute; z-index: 3; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow); max-width: 260px; pointer-events: auto;
}
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.timeline { font-size: 12.5px; }
.timeline .list-item { padding: 6px 0; }
.kbd { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: 0 5px; border-radius: 4px; }
