/* Work Assistant Mini App — dark operations dashboard.
   Semantic tokens only; components never use raw colors. */
:root {
  --bg: #020617;
  --surface: #0b1224;
  --surface-2: #111b30;
  --surface-3: #16213a;
  --line: #24314d;
  --line-strong: #334155;
  --text: #f8fafc;
  --muted: #a3b1c6;
  --faint: #6b7a94;
  --accent: #22c55e;
  --accent-strong: #16a34a;
  --on-accent: #03210f;
  --warn: #f59e0b;
  --danger: #f87171;
  --danger-strong: #dc2626;
  --info: #38bdf8;
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 12px;
  --nav-h: 64px;
  --topbar-h: 52px;
  --dur: 200ms;
  --ease: cubic-bezier(.2,.8,.2,1);
  --shadow: 0 8px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums; touch-action: manipulation;
  overflow-x: hidden;
}
a { color: var(--info); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 12px; top: 12px; }
:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; }

/* layout */
.app { display: flex; flex-direction: column; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  padding-left: 8px; padding-right: 8px;
  background: rgba(2,6,23,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-title { grid-column: 2; text-align: center; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#back-btn { grid-column: 1; }
#refresh-btn { grid-column: 3; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--text);
  display: grid; place-items: center; transition: background var(--dur) var(--ease);
}
.icon-btn:active { background: var(--surface-3); }
.icon-btn svg { width: 24px; height: 24px; }
.view {
  flex: 1; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  max-width: 720px; width: 100%; margin: 0 auto; outline: none;
}
.view.no-nav { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
@media (min-width: 768px) { .view { padding-left: 24px; padding-right: 24px; } }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(11,18,36,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.nav button {
  border: 0; background: transparent; color: var(--faint); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em; position: relative; transition: color var(--dur) var(--ease); min-height: 44px;
}
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--accent); }
.nav button .badge { position: absolute; top: 8px; left: calc(50% + 6px); }

/* typography */
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 6px; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 17px; line-height: 1.3; margin: 0; font-weight: 700; }
h3 { font-size: 15px; margin: 0; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.prewrap { white-space: pre-wrap; word-break: break-word; }
.mark { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; background: var(--accent); color: var(--on-accent); font-weight: 800; margin-bottom: 14px; }

/* blocks */
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.section { margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.accent { border-color: rgba(34,197,94,.45); background: linear-gradient(160deg, rgba(34,197,94,.14), var(--surface-2) 60%); }
.card.warn { border-color: rgba(245,158,11,.45); }
.card.danger { border-color: rgba(248,113,113,.45); }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (min-width: 560px) { .grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); } }
.metric { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-height: 76px; display: flex; flex-direction: column; justify-content: center; text-align: left; color: inherit; }
.metric .value { font-size: 24px; font-weight: 800; line-height: 1.15; }
.metric .label { color: var(--muted); font-size: 13px; margin-top: 2px; }
button.metric:active { background: var(--surface-3); }
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; min-height: 56px; color: inherit;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
button.row:active { background: var(--surface-3); transform: scale(.995); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .sub { color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.row .chev { color: var(--faint); flex: none; }
.row .chev svg { width: 20px; height: 20px; }
.kv { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 1.4; background: var(--surface-3); color: var(--muted); border: 1px solid var(--line-strong); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--accent); border-color: rgba(34,197,94,.4); }
.pill.warn { color: var(--warn); border-color: rgba(245,158,11,.4); }
.pill.danger { color: var(--danger); border-color: rgba(248,113,113,.4); }
.pill.info { color: var(--info); border-color: rgba(56,189,248,.4); }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger-strong); color: #fff; font-size: 11px; font-weight: 800; }
.note { border-left: 3px solid var(--warn); background: rgba(245,158,11,.08); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.note.ok { border-color: var(--accent); background: rgba(34,197,94,.08); }
.note.info { border-color: var(--info); background: rgba(56,189,248,.08); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.state { text-align: center; padding: 48px 12px; }
.state.compact { padding: 24px 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface-3); color: var(--text); font-weight: 700; font-size: 15px;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-strong); }
.btn.danger { background: transparent; border-color: rgba(248,113,113,.6); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.inline { width: auto; min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.btn-row.single { grid-template-columns: 1fr; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .help { font-size: 12px; color: var(--faint); }
.field .error { font-size: 13px; color: var(--danger); }
.input, textarea.input {
  width: 100%; min-height: 48px; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-size: 16px; transition: border-color var(--dur) var(--ease);
}
.input:focus { border-color: var(--accent); outline: none; }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.45; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; padding: 4px; }
.segmented button { border: 0; border-radius: 9px; background: transparent; color: var(--muted); min-height: 40px; font-weight: 700; }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.file-drop { border: 1px dashed var(--line-strong); border-radius: 12px; padding: 16px; text-align: center; color: var(--muted); background: var(--surface); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-3); border: 1px solid var(--line); display: grid; place-items: center; color: var(--faint); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; padding: 3px 6px; background: rgba(2,6,23,.75); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery { display: flex; flex-direction: column; gap: 10px; }
.gallery figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gallery img { width: 100%; height: auto; display: block; max-height: 70vh; object-fit: contain; background: #000; }
.gallery figcaption { padding: 8px 12px; font-size: 13px; color: var(--muted); }
.gallery .doc { padding: 14px; display: flex; gap: 10px; align-items: center; }
.media-loading { min-height: 160px; display: grid; place-items: center; color: var(--faint); }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); animation: fade var(--dur) var(--ease); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--surface-2); border-top: 1px solid var(--line-strong); border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow: auto; box-shadow: var(--shadow); animation: rise 240ms var(--ease);
  max-width: 720px; margin: 0 auto; }
.sheet .grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 0 auto 12px; }
.sheet h2 { margin-bottom: 6px; }
.sheet .actions { margin-top: 16px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* toast */
.toast-root { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; margin: 0 auto; max-width: 560px; width: 100%; background: var(--surface-3); border: 1px solid var(--line-strong); border-left: 4px solid var(--accent); color: var(--text); padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow); animation: rise 220ms var(--ease); font-size: 14px; }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); min-height: 64px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.screen-enter { animation: enter 220ms var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
.vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
label.btn { cursor: pointer; }

/* access control + inbox */
.access-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.access-card + .access-card { margin-top: 10px; }
.access-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.access-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.access-line + .access-line { border-top: 1px solid var(--line); }
.access-line .names { min-width: 0; }
.access-line .surface { font-size: 14px; font-weight: 600; }
.access-line .access-state { font-size: 12px; color: var(--muted); margin-top: 2px; }
.access-line .access-state.blocked { color: var(--danger); }
.access-line .access-state.open { color: var(--accent); }
.switch {
  flex: none; width: 52px; height: 32px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); position: relative; padding: 0; margin: 8px 0;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--faint); transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--on-accent); }
.switch[disabled] { opacity: .4; }
.switch-wrap { display: grid; place-items: center; min-width: 44px; min-height: 44px; }
.msg-list { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 10px 12px; }
.msg .meta { font-size: 11px; color: var(--faint); margin-top: 6px; }
.msg .body { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.msg img { width: 100%; border-radius: 10px; display: block; margin-top: 8px; background: #000; }
.msg.unseen { border-color: rgba(34,197,94,.5); }
.day-sep { text-align: center; font-size: 12px; color: var(--faint); margin: 8px 0; }

/* menu tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  min-height: 112px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface-2); color: inherit; text-align: left;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tile:active { background: var(--surface-3); transform: scale(.985); }
.tile-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); flex: none; }
.tile-icon svg { width: 22px; height: 22px; }
.tile-title { display: block; font-size: 14px; font-weight: 700; line-height: 1.25; }
.tile-meta { display: block; font-size: 12px; color: var(--faint); margin-top: auto; line-height: 1.35; }
.tile.accent { border-color: rgba(34,197,94,.4); }
.tile.accent .tile-icon { background: rgba(34,197,94,.16); color: var(--accent); }
.tile.alert { border-color: rgba(245,158,11,.45); }
.tile.alert .tile-icon { background: rgba(245,158,11,.16); color: var(--warn); }
.tile .badge { position: absolute; top: 12px; right: 12px; }
.tile.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: 64px; gap: 12px; }
.tile.wide .tile-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tile.wide .tile-meta { margin-top: 2px; }
