/* Operations Console — design system. Dark-first, desktop-first, tablet-friendly.
   Presentation only; no business logic lives here or anywhere in the frontend. */

:root {
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #171e2b;
  --elevated: #1c2434;
  --border: #232c3d;
  --border-strong: #303b50;
  --text: #e6edf3;
  --muted: #8b97a7;
  --faint: #5b6675;
  --accent: #4f8cff;
  --accent-dim: #2b4a80;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --info: #58a6ff;
  --purple: #a371f7;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --sidebar-w: 236px;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --elevated: #ffffff;
  --border: #dde3ec;
  --border-strong: #c6cfdd;
  --text: #131822;
  --muted: #5b6675;
  --faint: #8b97a7;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Layout: sidebar + main */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  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; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), var(--purple)); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.brand .name { font-weight: 650; letter-spacing: -0.2px; }
.brand .sub { color: var(--faint); font-size: 11px; }

.nav { padding: 10px 8px; flex: 1; }
.nav-group-label { color: var(--faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em; padding: 12px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm); color: var(--muted); cursor: pointer; font-weight: 500; white-space: nowrap; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: #fff; }
.nav-item .ico { width: 16px; height: 16px; flex: none; opacity: 0.9; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }

.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

/* Topbar */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: color-mix(in oklab, var(--bg) 82%, transparent); backdrop-filter: blur(8px); z-index: 5; }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 620; letter-spacing: -0.2px; }
.topbar .spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; }

.content { padding: 22px; max-width: 2200px; width: 100%; margin: 0 auto; }

/* Status dot */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px color-mix(in oklab, var(--faint) 22%, transparent); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ok) 22%, transparent); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in oklab, var(--warn) 22%, transparent); }
.dot.danger { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 22%, transparent); }
.dot.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Cards + grid */
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card > .card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card > .card-head h3 { margin: 0; font-size: 13px; font-weight: 620; }
.card > .card-head .sub { color: var(--faint); font-size: 12px; }
.card > .card-body { padding: 14px 16px; }
.card > .card-body.flush { padding: 0; }

/* KPI */
.kpi { display: flex; flex-direction: column; gap: 6px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.kpi .label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 26px; font-weight: 680; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.kpi .value .unit { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .foot { color: var(--faint); font-size: 11.5px; }
.kpi.accent { border-color: var(--accent-dim); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--border-strong); color: var(--muted); background: var(--surface-2); text-transform: capitalize; }
.badge.ok { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 40%, var(--border)); }
.badge.warn { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 40%, var(--border)); }
.badge.danger { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 40%, var(--border)); }
.badge.info { color: var(--info); border-color: color-mix(in oklab, var(--info) 40%, var(--border)); }
.badge.purple { color: var(--purple); border-color: color-mix(in oklab, var(--purple) 40%, var(--border)); }

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; color: var(--faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 10px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
table.tbl td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: var(--surface-2); }
table.tbl td.mono, table.tbl td .mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* Empty / states */
.empty { display: grid; place-items: center; gap: 8px; padding: 40px 16px; color: var(--muted); text-align: center; }
.empty .big { font-size: 15px; color: var(--text); font-weight: 600; }
.empty .hint { font-size: 12.5px; color: var(--faint); max-width: 440px; }
.notice { padding: 12px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); color: var(--muted); font-size: 12.5px; background: var(--surface-2); }

/* Live feed */
.feed { display: flex; flex-direction: column; }
.feed-row { display: flex; align-items: baseline; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.feed-row:last-child { border-bottom: none; }
.feed-row .t { color: var(--faint); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.feed-row .sys { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.feed-row .type { font-weight: 600; }

/* Per-task activity — one box per task with its action timeline */
.task-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; padding: 14px 16px; }
.task-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 13px; display: flex; flex-direction: column; gap: 10px; }
.task-box-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-box-head .task-issue { font-weight: 700; font-size: 13px; color: var(--text); }
.task-box-head .task-acct { margin-left: auto; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.task-now { font-size: 12px; font-weight: 600; color: var(--warn); padding: 4px 9px; border-radius: var(--radius-sm); border: 1px solid color-mix(in oklab, var(--warn) 40%, var(--border)); background: color-mix(in oklab, var(--warn) 12%, transparent); }
.task-actions { display: flex; flex-direction: column; gap: 5px; }
.task-action { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 5px; border-radius: var(--radius-sm); }
.task-action .task-stage { font-weight: 600; color: var(--text); text-transform: capitalize; }
.task-action .task-detail { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-action .task-time { margin-left: auto; color: var(--faint); font-size: 11px; white-space: nowrap; }
.task-action.running { background: color-mix(in oklab, var(--warn) 12%, transparent); }
.task-action.running .badge, .task-now.running { animation: pulse 1.6s ease-in-out infinite; }
.task-reason { font-size: 12.5px; font-weight: 600; color: var(--text); margin: 6px 0; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid color-mix(in oklab, var(--danger) 45%, var(--border)); background: color-mix(in oklab, var(--danger) 12%, transparent); line-height: 1.4; }

/* Forms / buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 550; font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input, .field select { background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text); padding: 9px 11px; font: inherit; font-size: 13px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.section-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 6px; }
.section-head .desc { color: var(--muted); font-size: 12.5px; }
.mb { margin-bottom: 14px; }

/* Responsive: tablet-friendly */
@media (max-width: 1080px) {
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform 0.2s ease; width: 260px; }
  .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }

/* Manual Start/Stop work control (idle-by-default) */
.workctl { display: inline-flex; align-items: center; gap: 10px; }
.workstate { font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border-strong); }
.workstate.on { color: #fff; background: var(--ok, #1a7f45); border-color: transparent; }
.workstate.off { color: var(--muted, #888); }
.btn.danger { background: var(--danger, #b3261e); border-color: var(--danger, #b3261e); color: #fff; }

/* Login screen (shown until a valid access token is entered) */
.login-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: var(--bg, #0d1117); padding: 20px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface, #161b22); border: 1px solid var(--border-strong, #30363d); border-radius: 14px; padding: 28px 24px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.login-logo { width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 11px; background: var(--accent, #2f81f7); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; letter-spacing: .5px; }
.login-card h2 { margin: 0 0 4px; font-size: 18px; }
.login-sub { margin: 0 0 18px; color: var(--muted, #8b949e); font-size: 13px; }
.login-input { width: 100%; box-sizing: border-box; padding: 11px 13px; border-radius: 9px; border: 1px solid var(--border-strong, #30363d); background: var(--surface-2, #0d1117); color: var(--text, #e6edf3); font-size: 15px; margin-bottom: 12px; }
.login-btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.login-err { color: var(--danger, #f85149); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* Jira Run control (account picker + Run button) */
.run-control { display: inline-flex; align-items: center; gap: 6px; }
.acct-select { padding: 5px 7px; border-radius: var(--radius-sm, 7px); border: 1px solid var(--border-strong, #30363d); background: var(--surface-2, #0d1117); color: var(--text, #e6edf3); font: inherit; font-size: 12.5px; max-width: 190px; }

/* Live agent count on a task box */
.task-agents { font-size: 12px; font-weight: 700; color: #fff; background: var(--accent, #2f81f7); padding: 2px 8px; border-radius: 999px; }

/* Clickable task box + expand hint */
.task-box.clickable { cursor: pointer; transition: border-color .15s; }
.task-box.clickable:hover { border-color: var(--accent, #2f81f7); }
.task-expand-hint { margin-top: 8px; font-size: 11.5px; color: var(--accent, #2f81f7); }

/* Live agent-output drawer (click a task) */
.drawer-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.55); display: flex; align-items: stretch; justify-content: center; padding: 24px; }
.drawer { width: 100%; max-width: 900px; display: flex; flex-direction: column; background: var(--surface, #161b22); border: 1px solid var(--border-strong, #30363d); border-radius: 14px; overflow: hidden; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border, #21262d); }
.drawer-title { font-weight: 700; font-size: 14px; }
.drawer-log { flex: 1; overflow-y: auto; user-select: text; -webkit-user-select: text; padding: 14px 16px; font-size: 13px; line-height: 1.5; background: var(--surface-2, #0d1117); }
.drawer-line { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.03); white-space: pre-wrap; word-break: break-word; }

/* ---- Mobile / phone responsiveness ---- */
html, body { max-width: 100%; overflow-x: hidden; }         /* never scroll the page sideways */
.tbl-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl-wrap table.tbl { min-width: 100%; }                    /* fill the container first (use wide screens); scroll only when truly too narrow */
@media (max-width: 720px) { .tbl-wrap table.tbl { min-width: 620px; } }   /* on small screens keep columns legible + scroll */

@media (max-width: 640px) {
  .content { padding: 12px; }
  .card > .card-body { padding: 12px; }
  .topbar { gap: 8px; padding: 10px 12px; }
  .topbar h1 { font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .conn .conn-text, .topbar .workstate { display: none; }   /* keep the dots/buttons, drop long text */
  .workctl { gap: 6px; }
  .workctl .btn { padding: 6px 10px; font-size: 12.5px; }
  .task-grid { grid-template-columns: 1fr; }
  .acct-select { max-width: 130px; }
  /* Live agent-output drawer fills the screen on a phone */
  .drawer-overlay { padding: 0; }
  .drawer { max-width: 100%; border-radius: 0; height: 100%; }
  table.tbl th, table.tbl td { padding: 9px 10px; }
  .kpi { padding: 12px; }
}

/* Continue button + error lines in the agent drawer */
.drawer-actions { display: inline-flex; gap: 8px; align-items: center; }
.drawer-line.err { color: var(--danger, #f85149); font-weight: 600; }
.task-continue { margin-left: auto; padding: 4px 10px; font-size: 12px; }
.task-ctl { padding: 3px 9px; font-size: 12px; }
.task-box-head .task-ctl:first-of-type { margin-left: auto; }

/* Resume message box in the agent drawer */
.drawer-foot { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border, #21262d); background: var(--surface, #161b22); }
.drawer-msg { flex: 1; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border-strong, #30363d); background: var(--surface-2, #0d1117); color: var(--text, #e6edf3); font: inherit; font-size: 13px; }
@media (max-width: 640px) { .drawer-foot { flex-wrap: wrap; } .drawer-msg { min-width: 0; } }

/* Per-task token usage */
.task-tok { font-size: 11.5px; font-weight: 600; color: var(--muted, #8b949e); font-variant-numeric: tabular-nums; }
.drawer-tok { font-size: 12.5px; font-weight: 600; color: var(--muted, #8b949e); margin-right: 12px; font-variant-numeric: tabular-nums; }

/* Important milestone lines in the agent report — bold, set off with "===" double rules top & bottom */
.drawer-important { font-weight: 700; color: var(--text, #e6edf3); margin: 12px 0; padding: 8px 2px; border-top: 3px double var(--border-strong, #30363d); border-bottom: 3px double var(--border-strong, #30363d); letter-spacing: .2px; }
.drawer-important.err { color: var(--danger, #f85149); border-color: var(--danger, #f85149); }

/* Project switcher in the sidebar brand */
.project-select { margin-top: 3px; width: 100%; max-width: 150px; font-size: 11.5px; padding: 3px 6px; border-radius: var(--radius-sm, 7px); border: 1px solid var(--border-strong, #30363d); background: var(--surface-2, #0d1117); color: var(--muted, #8b97a7); font-weight: 600; cursor: pointer; }
.project-select:hover { color: var(--text, #e6edf3); border-color: var(--accent, #4f8cff); }

/* Account usage progress bars (V1-style) */
.usage { min-width: 150px; }
.usage-bar { height: 8px; border-radius: 999px; background: var(--surface-2, #171e2b); border: 1px solid var(--border, #232c3d); overflow: hidden; }
.usage-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.usage-fill.ok { background: var(--ok, #3fb950); }
.usage-fill.warn { background: var(--warn, #d29922); }
.usage-fill.danger { background: var(--danger, #f85149); }
.usage-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px; font-size: 11px; }
.usage-meta .usage-pct { font-weight: 600; color: var(--text, #e6edf3); }

/* Add-Project form + folder picker */
.pf-field { display: block; margin-bottom: 10px; }
.pf-label { display: block; font-size: 12px; color: var(--muted, #8b97a7); margin-bottom: 3px; font-weight: 600; }
.pf-field .login-input { margin-bottom: 0; }
.fp-list { display: flex; flex-direction: column; border: 1px solid var(--border, #232c3d); border-radius: var(--radius-sm, 7px); overflow: hidden; }
.fp-row { padding: 8px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border, #232c3d); }
.fp-row:last-child { border-bottom: none; }
.fp-row:hover { background: var(--surface-2, #171e2b); color: var(--accent, #4f8cff); }

/* Rules page */
.rules-list { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; }
.rule-card { border: 1px solid var(--border, #232c3d); border-radius: var(--radius, 10px); padding: 12px 14px; background: var(--surface-2, #171e2b); }
.rule-card.inactive { opacity: 0.6; }
.rule-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.rule-title { font-weight: 650; font-size: 14px; }
.rule-text { font-size: 13px; color: var(--muted, #8b97a7); line-height: 1.5; white-space: pre-wrap; }
textarea.login-input { resize: vertical; font-family: inherit; }

/* Ticket detail + chat drawer */
.ticket-link { color: var(--accent, #4f8cff); cursor: pointer; }
.ticket-link:hover { text-decoration: underline; }
.ticket-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; flex: 1; min-height: 0; }
.ticket-detail { padding: 16px; overflow: auto; border-right: 1px solid var(--border, #232c3d); }
.ticket-status { display: flex; align-items: center; gap: 8px; }
.ticket-desc { font-size: 13px; line-height: 1.55; white-space: pre-wrap; color: var(--text, #e6edf3); background: var(--surface-2, #171e2b); border: 1px solid var(--border, #232c3d); border-radius: var(--radius-sm, 7px); padding: 10px 12px; }
.ticket-comments-h { font-weight: 650; font-size: 12.5px; margin: 14px 0 6px; color: var(--muted, #8b97a7); }
.ticket-comment { border-top: 1px solid var(--border, #232c3d); padding: 8px 0; font-size: 12.5px; }
.ticket-comment-a { font-weight: 600; color: var(--muted, #8b97a7); display: block; margin-bottom: 2px; }
.ticket-chat { display: flex; flex-direction: column; min-height: 0; }
.ticket-chat-h { padding: 12px 16px; border-bottom: 1px solid var(--border, #232c3d); font-weight: 650; font-size: 13px; }
.chat-log { flex: 1; overflow: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { border-radius: 10px; padding: 8px 11px; font-size: 13px; line-height: 1.5; max-width: 92%; }
.chat-msg.user { align-self: flex-end; background: var(--accent-dim, #2b4a80); }
.chat-msg.agent { align-self: flex-start; background: var(--surface-2, #171e2b); border: 1px solid var(--border, #232c3d); }
.chat-role { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint, #5b6675); margin-bottom: 3px; }
.chat-text { white-space: pre-wrap; }
.chat-controls { border-top: 1px solid var(--border, #232c3d); padding: 10px 16px; display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 720px) { .ticket-body { grid-template-columns: 1fr; } .ticket-detail { border-right: none; border-bottom: 1px solid var(--border, #232c3d); } }

/* ============================================================================
   Mobile / touch UX polish
   ============================================================================ */
* { -webkit-tap-highlight-color: transparent; }
.nav-scrim { display: none; }

@media (max-width: 820px) {
  /* Nav drawer: roomy width, tap targets, scrim, notch-safe */
  .sidebar { width: min(85vw, 300px); }
  .brand { padding: 16px 16px calc(14px + env(safe-area-inset-top)); }
  .app.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.55); }
  .nav-item { padding: 12px 14px; font-size: 15px; border-radius: 9px; }
  .nav-group-label { font-size: 11px; padding: 14px 12px 6px; }
  .menu-toggle { display: inline-flex !important; min-height: 40px; }

  /* Touch-friendly controls; 16px inputs stop iOS from zooming on focus */
  .btn { padding: 9px 14px; font-size: 14px; min-height: 42px; }
  input, textarea, select, .login-input, .acct-select, .project-select, .drawer-msg { font-size: 16px; }
  .acct-select, .project-select { min-height: 40px; }

  /* KPI 2-up rather than four stacked */
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .kpi { padding: 13px; }
  .kpi .value { font-size: 22px; }

  /* Topbar: notch-safe, single tidy row */
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 12px 10px; gap: 8px; }
  .topbar h1 { font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 640px) {
  .content { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }
  .section-head { flex-wrap: wrap; row-gap: 8px; }
  .section-head .desc { flex-basis: 100%; }
  .grid { gap: 12px; }

  /* Full-screen sheet drawers with sticky, notch-safe head + foot */
  .drawer-overlay { padding: 0; }
  .drawer { max-width: 100%; width: 100%; height: 100%; border-radius: 0; border: none; }
  .drawer-head { position: sticky; top: 0; z-index: 3; flex-wrap: nowrap; gap: 6px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--surface, #161b22); }
  .drawer-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .drawer-head .btn { padding: 8px 10px; font-size: 12.5px; min-height: 38px; }
  .drawer-head .drawer-tok { display: none; }               /* tokens already shown on the task box */
  .drawer-foot { position: sticky; bottom: 0; flex-wrap: wrap; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .drawer-msg { flex: 1 1 100%; min-width: 0; }

  /* Ticket drawer: stack detail over chat, each area scrolls, fills the sheet */
  .ticket-body { display: flex; flex-direction: column; overflow: hidden; }
  .ticket-detail { border-right: none; border-bottom: 1px solid var(--border, #232c3d); flex: 0 0 auto; max-height: 42vh; }
  .ticket-chat { flex: 1 1 auto; min-height: 0; }
  .chat-controls .run-control { flex-wrap: wrap; }
  .chat-controls .run-control .btn { flex: 1 1 auto; justify-content: center; }
  .chat-msg { max-width: 100%; }

  /* Task boxes: full width, comfy padding */
  .task-grid { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .task-box { padding: 14px; }
  .task-box-head { flex-wrap: wrap; row-gap: 4px; }

  /* Tables scroll sideways but rows/taps are bigger; run-control wraps */
  table.tbl th, table.tbl td { padding: 11px 12px; }
  .run-control { flex-wrap: wrap; gap: 6px; }
  .acct-select { max-width: 48vw; }

  /* Folder picker + rules: bigger taps */
  .fp-row { padding: 12px; }
  .rule-card { padding: 14px; }
  .usage-bar { height: 9px; }
}

/* Landscape phone / small tablet: 2-up task boxes */
@media (min-width: 641px) and (max-width: 900px) {
  .task-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Task timeline rows: on phones, let the detail wrap to its own line instead of clipping */
@media (max-width: 640px) {
  .task-action { flex-wrap: wrap; row-gap: 2px; }
  .task-action .task-detail { white-space: normal; overflow: visible; text-overflow: clip; flex: 1 1 100%; padding-left: 30px; color: var(--muted, #8b97a7); }
  .task-now { white-space: normal; }
}

/* Tables → stacked labeled cards on phones (no more sideways scrolling to see Status/Run) */
@media (max-width: 640px) {
  .tbl-wrap { overflow-x: visible; }
  .tbl-wrap table.tbl { min-width: 0; display: block; }
  .tbl-wrap table.tbl thead { display: none; }
  .tbl-wrap table.tbl tbody { display: block; }
  .tbl-wrap table.tbl tr { display: block; border: 1px solid var(--border, #232c3d); border-radius: 10px; padding: 10px 12px; margin: 0 12px 10px; background: var(--surface-2, #171e2b); }
  .tbl-wrap table.tbl tr:hover td { background: transparent; }
  .tbl-wrap table.tbl td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border: none; text-align: right; }
  .tbl-wrap table.tbl td::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint, #5b6675); font-weight: 600; text-align: left; flex: 0 0 auto; }
  .tbl-wrap table.tbl td:empty, .tbl-wrap table.tbl td[data-label=""]::before { display: none; }
  .tbl-wrap table.tbl td .run-control { justify-content: flex-end; flex-wrap: wrap; }
  .tbl-wrap table.tbl td.mono { word-break: break-word; }
  .tbl-wrap table.tbl td .usage { min-width: 60%; }
}

/* Ticket detail drawer — phone layout: one scrolling column, sticky chat input, no wasted space */
@media (max-width: 640px) {
  .ticket-body { display: block; flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .ticket-detail { max-height: none; border-right: none; border-bottom: 1px solid var(--border, #232c3d); overflow: visible; }
  .ticket-status { flex-wrap: wrap; row-gap: 8px; }
  .ticket-status .run-control { flex-wrap: wrap; gap: 6px; }
  .ticket-chat { display: block; min-height: 0; }
  .ticket-chat-h { position: sticky; top: 0; z-index: 1; background: var(--surface, #161b22); }
  .chat-log { overflow: visible; min-height: 120px; }
  .chat-controls { position: sticky; bottom: 0; background: var(--surface, #161b22); box-shadow: 0 -6px 14px rgba(0,0,0,.35); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* Bulletproof full-screen sheet on phones: the drawer itself is the fixed viewport-filling panel */
@media (max-width: 640px) {
  .drawer-overlay { padding: 0; background: var(--bg, #0b0e14); }
  .drawer { position: fixed; inset: 0; width: auto; max-width: none; height: auto; border: none; border-radius: 0; }
}

/* Jira status filter chips */
.status-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border, #232c3d); }
.status-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--border-strong, #30363d); background: var(--surface-2, #171e2b); color: var(--muted, #8b97a7); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.status-chip:hover { color: var(--text, #e6edf3); border-color: var(--accent, #4f8cff); }
.status-chip.active { background: var(--accent-dim, #2b4a80); color: #fff; border-color: transparent; }
.status-chip .chip-n { font-size: 11px; opacity: .7; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .status-filter { padding: 10px 12px; } .status-chip { min-height: 34px; } }

/* Jira toolbar + bulk actions */
.jira-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px 0; }
.bulk-bar { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bulk-count { font-weight: 700; color: var(--accent, #4f8cff); font-size: 13px; }
.tbl td input[type="checkbox"], .tbl th input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; accent-color: var(--accent, #4f8cff); }
@media (max-width: 640px) { .jira-toolbar { padding: 12px 12px 0; } }

/* ---- Access-request banner (task needs access → Allow/Deny) ---- */
.areq-bar { display: flex; flex-direction: column; gap: 8px; }
.areq-bar:not(:empty) { padding: 10px 16px 0; }
.areq-card {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid color-mix(in oklab, var(--warn) 55%, var(--border));
  background: color-mix(in oklab, var(--warn) 14%, var(--surface));
}
.areq-title { font-weight: 700; }
.areq-reason { color: var(--muted); font-size: 13px; flex: 1; min-width: 180px; }
.areq-input { flex: 1; min-width: 220px; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); color: var(--text); font-family: var(--mono); font-size: 12px; }

/* ---- Jira list: hardware/human-needed rows + project labels ---- */
.tbl tr.needs-row td { background: color-mix(in oklab, var(--warn) 13%, transparent); }
.tbl tr.needs-row td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.jira-labels { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.jira-label { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
