:root {
  color-scheme: dark;
  --bg: #12171d;
  --bg-deep: #0d1116;
  --panel: #19212a;
  --panel-strong: #202b35;
  --line: #34424e;
  --line-soft: #26333e;
  --text: #eaf0f5;
  --muted: #9babb9;
  --faint: #718391;
  --green: #4dd28a;
  --green-bg: #173a2b;
  --red: #ff7075;
  --red-bg: #45252a;
  --yellow: #f3c56a;
  --yellow-bg: #49391f;
  --blue: #6bb6e8;
  --blue-bg: #1b384d;
  --focus: #83c9ff;
  --shadow: 0 16px 45px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 460px); gap: 7vw; align-items: center; justify-content: center; padding: 48px 32px; background: radial-gradient(circle at 20% 20%, #1e3140 0, transparent 36%), linear-gradient(145deg, #0e1318, #171e26); }
.auth-brand { max-width: 510px; }
.brand-mark { display: inline-flex; width: 60px; height: 60px; border: 1px solid #588db0; align-items: center; justify-content: center; background: #183345; color: #e6f6ff; font-size: 20px; font-weight: 800; letter-spacing: 0; }
.brand-mark.small { width: 30px; height: 30px; font-size: 11px; }
.eyebrow { margin: 0 0 7px; color: var(--blue); text-transform: uppercase; font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.auth-brand h1 { margin: 8px 0 14px; font-size: 44px; line-height: 1; letter-spacing: 0; }
.auth-brand > p:not(.eyebrow) { color: var(--muted); font-size: 18px; line-height: 1.5; margin: 0; }
.auth-notes { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 9px; }
.auth-notes span { color: #bbd0df; border: 1px solid var(--line); background: #16222c; padding: 7px 10px; font-size: 12px; }
.auth-card { padding: 28px; border: 1px solid var(--line); background: #171f27; box-shadow: var(--shadow); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.auth-tabs.single { grid-template-columns: 1fr; }
.tab-button { color: var(--muted); background: transparent; padding: 11px; border: 0; border-bottom: 2px solid transparent; }
.tab-button.is-active { color: var(--text); border-color: var(--blue); }

label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 3px; color: var(--text); background: #111820; padding: 9px 10px; outline: none; min-height: 38px; }
input:focus, select:focus { border-color: var(--focus); box-shadow: 0 0 0 2px rgba(131, 201, 255, .16); }
input[type="checkbox"] { width: 16px; min-height: auto; height: 16px; accent-color: var(--green); }
.form-help { min-height: 20px; color: var(--faint); font-size: 12px; line-height: 1.4; }
.button { border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: #27333e; padding: 9px 12px; min-height: 38px; line-height: 1; white-space: nowrap; }
.button:hover { border-color: #5c7080; background: #303f4c; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button:focus-visible, .icon-button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.button.primary { background: #257e56; border-color: #3db577; color: #fff; font-weight: 700; }
.button.primary:hover { background: #2d9869; }
.button.secondary { background: #254459; border-color: #4f92bd; }
.button.ghost { background: transparent; color: var(--muted); }
.button.danger { background: var(--red-bg); border-color: #a75c61; color: #ffd9da; }
.button.small { min-height: 27px; padding: 5px 8px; font-size: 12px; }
.wide { width: 100%; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; min-height: 100vh; background: var(--bg-deep); border-right: 1px solid var(--line-soft); padding: 17px 13px; position: sticky; top: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; padding: 4px 6px 23px; }
.main-nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 10px 11px; border: 1px solid transparent; border-radius: 4px; color: var(--muted); background: transparent; text-align: left; }
.nav-item:hover { color: var(--text); background: #172029; }
.nav-item.is-active { color: #ecf7ff; background: #1a3445; border-color: #335e78; }
.count-badge { min-width: 20px; padding: 2px 5px; text-align: center; background: #2f684e; color: #e6ffef; font-size: 11px; border-radius: 10px; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; padding: 16px 6px 2px; }
.engine-state { padding: 8px; background: #18222b; color: var(--muted); border-left: 3px solid var(--yellow); font-size: 11px; line-height: 1.4; }
.engine-state.ok { border-color: var(--green); }
.engine-state.error { border-color: var(--red); }
.user-email { color: #b4c4cf; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

.workspace { min-width: 0; padding: 0 25px 32px; }
.topbar { min-height: 91px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line-soft); margin-bottom: 22px; }
.topbar h2 { margin: 0; font-size: 25px; letter-spacing: 0; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.clock-summary { max-width: 480px; color: var(--muted); font-size: 12px; text-align: right; }
.page { display: none; }
.page.is-active { display: block; }
.notice { margin-bottom: 15px; padding: 11px 13px; border-left: 3px solid var(--blue); background: #172a36; color: #bed8e9; line-height: 1.4; }
.clock-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; margin-bottom: 18px; }
.clock-card { padding: 12px; border: 1px solid var(--line); background: var(--panel); min-height: 139px; }
.clock-card h4 { margin: 0 0 9px; text-transform: uppercase; font-size: 12px; color: #d7e5ee; }
.clock-card .server-time { color: var(--green); font-size: 16px; font-weight: 700; }
.clock-card .clock-meta { margin-top: 6px; color: var(--muted); font-size: 11px; }
.clock-card.error .server-time { color: var(--red); }
.clock-offset { font-weight: 700; }
.clock-offset.positive { color: #8be6b2; }
.clock-offset.negative { color: #ff9fa2; }
.clock-offset.neutral { color: #c5d5df; }

.panel, .table-panel { border: 1px solid var(--line); background: var(--panel); }
.panel { padding: 17px; }
.table-panel { overflow: hidden; }
.panel-heading { display: flex; justify-content: space-between; gap: 18px; align-items: start; padding: 15px 16px; border-bottom: 1px solid var(--line); }
.panel-heading h3, .timing-panel h3 { margin: 0; font-size: 16px; }
.panel-heading p, .timing-panel p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.inline-field { width: min(230px, 40vw); }
.table-wrap { width: 100%; overflow: auto; max-height: calc(100vh - 292px); }
.table-wrap.compact { margin-top: 17px; max-height: 300px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; z-index: 1; background: #202b35; color: #c5d5df; font-size: 11px; font-weight: 650; text-align: left; white-space: nowrap; }
th, td { border-bottom: 1px solid var(--line-soft); padding: 8px 9px; vertical-align: middle; }
td { color: #deebf3; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: #21303a; }
td.wrap { white-space: normal; min-width: 230px; }
.positive { color: #b7f0d0 !important; background: var(--green-bg); }
.negative { color: #ffd0d2 !important; background: var(--red-bg); }
.warning { color: #ffe4a4 !important; background: var(--yellow-bg); }
.muted { color: var(--muted); }
.state { display: inline-block; padding: 4px 7px; border: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 650; }
.state.open { color: #c8ffe0; background: var(--green-bg); border-color: #3a7d59; }
.state.armed, .state.ready { color: #d8ebf7; background: var(--blue-bg); border-color: #3e7290; }
.state.error, .state.cancelled { color: #ffd6d8; background: var(--red-bg); border-color: #945459; }
.state.closed { color: #cbced4; background: #283038; }
.state.draft { color: #e8d7af; background: #3f3420; border-color: #876e3d; }
.action-cell { display: flex; gap: 5px; align-items: center; }
.table-edit-button { min-height: 26px; padding: 4px 7px; border: 1px dashed #5e91ae; border-radius: 3px; color: #d8f0ff; background: #1a3546; font-size: 12px; text-align: left; }
.table-edit-button:hover { border-style: solid; border-color: var(--focus); background: #22455a; }
.table-edit-button[disabled] { cursor: default; border-color: transparent; color: #deebf3; background: transparent; padding-left: 0; }

.plans-layout, .account-grid, .admin-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(270px, .65fr); gap: 17px; margin-bottom: 17px; }
.manual-plan-panel { display: grid; gap: 14px; }
.timing-panel { border-left: 3px solid var(--blue); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.form-grid .wide-field, .form-grid .checkbox-label { grid-column: 1 / -1; }
.checkbox-label { display: flex; align-items: center; gap: 8px; min-height: 38px; color: #c9d6df; }
.warning-check { color: #ffd4a0; }
.filter-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; align-items: end; }
.filters-panel { margin-bottom: 16px; }
.totals-grid { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.total-card { padding: 12px; border: 1px solid var(--line); background: var(--panel); }
.total-card span { display: block; color: var(--muted); font-size: 11px; }
.total-card strong { display: block; margin-top: 5px; font-size: 18px; }

.account-grid { align-items: start; }
.admin-layout { align-items: stretch; }
.admin-help-panel { border-left: 3px solid var(--blue); }
.admin-help-panel h3 { margin: 0; font-size: 16px; }
.admin-help-panel p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end; }
.settings-grid .wide-field { grid-column: 1 / -1; }
.checkbox-row, .offset-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-row label { display: flex; align-items: center; gap: 6px; color: #d7e3ea; padding: 5px 7px; border: 1px solid var(--line); background: #111820; }
.offset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.offsets-section { padding: 12px; background: #162029; border: 1px solid var(--line-soft); }
.offsets-section h4 { margin: 0 0 10px; font-size: 12px; color: #ccdce6; }
.credentials-form { margin-top: 14px; }

.details-dialog { width: min(1050px, 92vw); max-height: 86vh; color: var(--text); background: #151e27; border: 1px solid #4b6374; box-shadow: var(--shadow); padding: 0; }
.details-dialog::backdrop { background: rgba(5, 8, 10, .72); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 16px; }
.icon-button { width: 32px; height: 30px; border: 1px solid var(--line); background: #28333d; color: var(--text); }
.details-dialog pre { margin: 0; padding: 18px; max-height: 73vh; overflow: auto; white-space: pre-wrap; color: #c9dce8; font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.plan-edit-dialog { width: min(430px, calc(100vw - 28px)); color: var(--text); background: #151e27; border: 1px solid #4b6374; box-shadow: var(--shadow); padding: 0; }
.plan-edit-dialog::backdrop { background: rgba(5, 8, 10, .72); }
.plan-edit-body { display: grid; gap: 15px; padding: 18px; }
.plan-edit-fields { display: grid; gap: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 20px; top: 20px; z-index: 10; min-width: 250px; max-width: 410px; padding: 12px 14px; background: #263540; border-left: 4px solid var(--blue); box-shadow: var(--shadow); color: #ecf7ff; }
.toast.error { border-color: var(--red); background: #40262a; }
.toast.ok { border-color: var(--green); background: #1b3c2d; }

@media (max-width: 1120px) {
  .account-grid, .plans-layout, .admin-layout { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .auth-shell { grid-template-columns: 1fr; padding: 30px 20px; }
  .auth-brand h1 { font-size: 36px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; height: auto; position: static; padding: 10px; }
  .main-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nav-item { font-size: 11px; justify-content: center; text-align: center; }
  .sidebar-bottom { display: none; }
  .workspace { padding: 0 12px 22px; }
  .topbar { min-height: 76px; }
  .topbar h2 { font-size: 20px; }
  .clock-summary { display: none; }
  .form-grid, .filter-grid, .settings-grid { grid-template-columns: 1fr; }
  .offset-grid { grid-template-columns: 1fr 1fr; }
  .totals-grid { grid-template-columns: 1fr 1fr; }
  .table-wrap { max-height: calc(100vh - 230px); }
}
