:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --line: #e2e8f0;
  --text: #172033;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16865b;
  --orange: #d97706;
  --red: #dc2626;
  --editor: #111827;
  --editor-line: #263247;
  --shadow: 0 18px 55px rgba(40, 55, 80, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 15% 15%, rgba(37, 99, 235, .13), transparent 34%),
    radial-gradient(circle at 85% 90%, rgba(22, 134, 91, .11), transparent 32%),
    var(--bg);
}
.login-card { width: min(440px, 100%); padding: 42px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 54px; height: 54px; place-items: center; border-radius: 15px; background: linear-gradient(145deg, var(--blue), #0ea5e9); color: #fff; font-weight: 800; letter-spacing: -.04em; box-shadow: 0 9px 25px rgba(37,99,235,.25); }
.brand-mark.small { width: 40px; height: 40px; border-radius: 11px; font-size: 14px; flex: 0 0 auto; }
.eyebrow { margin: 20px 0 8px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
h1 { margin: 0; font-size: clamp(25px, 4vw, 34px); letter-spacing: -.035em; }
h2 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); line-height: 1.65; }
label { display: block; margin: 24px 0 8px; font-size: 13px; font-weight: 700; }
input { width: 100%; padding: 13px 14px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; outline: none; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.primary, .secondary, .ghost { border-radius: 9px; padding: 10px 15px; border: 1px solid transparent; font-weight: 700; font-size: 13px; }
.primary { color: #fff; background: var(--blue); box-shadow: 0 5px 14px rgba(37,99,235,.18); }
.primary:hover { background: var(--blue-dark); }
.secondary { color: #334155; background: #fff; border-color: #cbd5e1; }
.secondary:hover { background: #f8fafc; }
.ghost { color: #475569; background: transparent; }
.ghost:hover { background: #eef2f7; }
.wide { width: 100%; margin-top: 22px; padding: 13px; }
.form-message { min-height: 22px; margin: 12px 0 0; color: var(--red); font-size: 13px; }
.quiet-link { display: inline-block; margin-top: 18px; color: var(--muted); font-size: 13px; text-decoration: none; }
.quiet-link:hover { color: var(--blue); }

.app-shell { min-height: 100vh; }
.topbar { position: sticky; z-index: 20; top: 0; height: 68px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); }
.brand-row, .top-actions, .brand { display: flex; align-items: center; }
.brand { gap: 11px; color: var(--text); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.top-actions { gap: 8px; }
.state-pill { margin-right: 5px; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.state-pill.clean { color: #166534; background: #dcfce7; }
.state-pill.dirty { color: #9a3412; background: #ffedd5; }
.state-pill.saving { color: #1e40af; background: #dbeafe; }

.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.sidebar { position: sticky; top: 68px; height: calc(100vh - 68px); overflow-y: auto; padding: 25px 16px; border-right: 1px solid var(--line); background: #fff; }
.sidebar-section + .sidebar-section { margin-top: 26px; }
.nav-label { margin: 0 10px 8px; color: #94a3b8; font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.nav-button { width: 100%; min-height: 41px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; border: 0; border-radius: 9px; color: #475569; background: transparent; text-align: left; font-size: 13px; }
.nav-button:hover { color: var(--text); background: #f1f5f9; }
.nav-button.active { color: #1d4ed8; background: #eff6ff; font-weight: 750; }
.nav-icon { color: #94a3b8; }
.sidebar-note { margin-top: 28px; padding: 14px; border: 1px solid #fed7aa; border-radius: 10px; background: #fff7ed; color: #9a3412; font-size: 12px; }
.sidebar-note p { margin: 6px 0 0; line-height: 1.55; }

.content { width: 100%; max-width: 1520px; margin: 0 auto; padding: 34px clamp(22px, 4vw, 54px) 60px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 28px; margin-bottom: 25px; }
.page-heading .eyebrow { margin-top: 0; }
.page-heading .muted { margin: 8px 0 0; }
.revision-box { min-width: 160px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.revision-box span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.revision-box code { display: block; margin-top: 5px; color: #334155; font-size: 12px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 285px; gap: 22px; align-items: start; }
.editor-card { overflow: hidden; border: 1px solid #263247; border-radius: 14px; background: var(--editor); box-shadow: var(--shadow); }
.editor-toolbar { height: 43px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--editor-line); background: #182235; }
.syntax-label { color: #7dd3fc; font: 700 11px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .12em; }
.editor-toolbar .muted { color: #94a3b8; font-size: 11px; }
#file-editor { display: block; width: 100%; min-height: calc(100vh - 255px); resize: vertical; padding: 21px; border: 0; outline: 0; color: #e5edf8; background: var(--editor); font: 13px/1.72 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; }
#file-editor::selection { background: rgba(59,130,246,.4); }
.help-column { display: grid; gap: 14px; }
.info-card { position: relative; padding: 18px 18px 18px 52px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.info-card p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.card-icon { position: absolute; top: 18px; left: 17px; display: grid; width: 23px; height: 23px; place-items: center; border-radius: 50%; font-size: 12px; font-weight: 900; }
.accent-blue .card-icon { color: #1d4ed8; background: #dbeafe; }
.accent-orange .card-icon { color: #b45309; background: #ffedd5; }
.accent-green .card-icon { color: #047857; background: #d1fae5; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.summary-card { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.summary-card span { color: var(--muted); font-size: 12px; }
.summary-card strong { display: block; margin-top: 8px; font-size: 25px; letter-spacing: -.03em; }
.table-card { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 8px 30px rgba(40,55,80,.05); }
.table-heading { min-height: 65px; padding: 14px 19px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.filter-row { display: flex; padding: 3px; border-radius: 8px; background: #f1f5f9; }
.filter { padding: 6px 10px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 11px; }
.filter.active { color: var(--text); background: #fff; box-shadow: 0 1px 4px rgba(15,23,42,.12); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 13px 19px; border-bottom: 1px solid #edf2f7; text-align: left; font-size: 12px; }
th { color: var(--muted); background: var(--surface-muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
tbody tr:hover { background: #f8fafc; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; font-weight: 750; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.success { color: #047857; background: #ecfdf5; }
.status.failed, .status.interrupted { color: #b91c1c; background: #fef2f2; }
.status.running { color: #1d4ed8; background: #eff6ff; }
.status.skipped { color: #a16207; background: #fefce8; }
.empty-state { padding: 45px; color: var(--muted); text-align: center; }
.toast { position: fixed; z-index: 50; right: 24px; bottom: 24px; max-width: 390px; padding: 13px 16px; border-radius: 10px; color: #fff; background: #172033; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: #991b1b; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 8px; background: #f1f5f9; }
.mobile-only { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1000px) {
  .editor-grid { grid-template-columns: 1fr; }
  .help-column { grid-template-columns: repeat(3, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { height: auto; min-height: 64px; padding: 10px 13px; flex-wrap: wrap; }
  .brand-row { gap: 8px; }
  .brand small { display: none; }
  .top-actions { width: 100%; order: 2; overflow-x: auto; padding-bottom: 2px; }
  .top-actions .state-pill { margin-right: auto; white-space: nowrap; }
  .workspace { display: block; }
  .sidebar { position: fixed; z-index: 30; top: 0; left: 0; width: min(310px, 86vw); height: 100vh; transform: translateX(-105%); box-shadow: var(--shadow); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 27px 16px 45px; }
  .page-heading { align-items: start; }
  .revision-box { display: none; }
  .help-column { grid-template-columns: 1fr; }
  #file-editor { min-height: 58vh; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .table-heading { align-items: start; flex-direction: column; }
}

@media (max-width: 480px) {
  .login-card { padding: 30px 22px; }
  .top-actions .secondary, .top-actions .ghost { padding: 9px 11px; }
  .summary-grid { grid-template-columns: 1fr; }
}
