:root {
    --bg: #ffffff;
    --surface: #f7f7f5;
    --hover: #f1f1ef;
    --line: #ececea;
    --text: #37352f;
    --muted: #787774;
    --faint: #b9b8b4;
    --inverse: #ffffff;
    --active: #d9a13b;
    --idle: #4dab9a;
    --done: #9b9a97;
    --dead: #e0533d;
    --bar: #37352f;
    --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: "Roboto Mono", ui-monospace, "SF Mono", Menlo, monospace;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #191919;
    --surface: #202020;
    --hover: #262626;
    --line: #2d2d2d;
    --text: #e6e5e3;
    --muted: #9b9b98;
    --faint: #5c5c5a;
    --inverse: #191919;
    --bar: #e6e5e3;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

.shell {
    max-width: 760px;
    margin: 0 auto;
    padding: 0 20px calc(40px + env(safe-area-inset-bottom));
}

/* Top bar */
.top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 0 10px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.brand .sep { color: var(--faint); margin: 0 6px; }
.live { display: flex; align-items: center; gap: 7px; }
.pulse {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--faint);
}
.live.is-on .pulse { background: var(--idle); animation: pulse 2s ease-in-out infinite; }
.live.is-err .pulse { background: var(--dead); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Tabs */
.tabs {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    gap: 22px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    margin: 0 -20px;
    padding: 0 20px;
}
.tab {
    background: none;
    border: 0;
    padding: 12px 0 11px;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 1.5px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--text); }

.view { display: none; }
.view.is-active { display: block; }

h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 30px 0 22px;
}

.section-head {
    margin: 34px 0 6px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Overview stats */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.stats:empty, .metrics:empty { display: none; }
.stat { padding: 14px 14px 12px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat-label {
    display: flex; align-items: center; gap: 6px;
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.stat-value { font-family: var(--mono); font-size: 26px; font-weight: 500; margin-top: 4px; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.dot.active { background: var(--active); }
.dot.idle { background: var(--idle); }
.dot.done { background: var(--done); }
.dot.dead { background: var(--dead); }

/* Lists */
.list { border-top: 1px solid var(--line); }
.row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 6px;
    margin: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: none;
    text-align: left;
}
button.row, a.row { cursor: pointer; }
button.row:hover, a.row:hover { background: var(--hover); }
a.row { color: inherit; text-decoration: none; }
.row-main { flex: 1; min-width: 0; }
.row-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.row-title.mono { font-size: 14px; }
.row-sub {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.row-side {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    text-align: right;
}
.row-side .arrow { color: var(--faint); margin-left: 6px; }
.empty { padding: 18px 6px; color: var(--muted); font-size: 14px; border-bottom: 1px solid var(--line); }

/* Limits */
.limit { padding: 12px 6px; border-bottom: 1px solid var(--line); }
.limit-top { display: flex; justify-content: space-between; font-size: 14px; }
.limit-top .mono { font-size: 12px; color: var(--muted); }
.bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--bar); border-radius: 2px; transition: width 0.4s ease; }
.bar > i.warn { background: var(--active); }
.bar > i.crit { background: var(--dead); }

/* Server metrics */
.metrics {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.metric {
    padding: 14px 14px 13px;
    border-bottom: 1px solid var(--line);
    min-width: 0;
}
.metric:nth-child(odd) { border-right: 1px solid var(--line); }
.metric:nth-last-child(-n + 2) { border-bottom: 0; }
.metric-label {
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.metric-value { font-family: var(--mono); font-size: 22px; font-weight: 500; margin-top: 4px; white-space: nowrap; }
.metric-value small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.metric-sub { font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { display: block; width: 100%; height: 28px; margin-top: 8px; }
.spark path { fill: none; stroke: var(--text); stroke-width: 1.25; vector-effect: non-scaling-stroke; }
.spark .area { fill: var(--surface); stroke: none; }

.table { border-top: 1px solid var(--line); font-size: 12.5px; }
.tr { display: grid; grid-template-columns: 1fr 84px 60px; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--line); }
.tr span:not(:first-child) { text-align: right; color: var(--muted); }
.tr span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr.th { color: var(--muted); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; }

/* Files */
.crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 14px;
}
.crumbs button {
    background: none; border: 0; padding: 2px 4px; border-radius: 4px;
    color: var(--muted); cursor: pointer;
}
.crumbs button:hover { background: var(--hover); color: var(--text); }
.crumbs button:last-child { color: var(--text); }
.crumbs .slash { color: var(--faint); }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
    background: none;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
}
.chip:hover { background: var(--hover); color: var(--text); }
.chip-danger { color: var(--dead); }

.new-row { display: flex; gap: 6px; margin-bottom: 14px; }
.new-row input {
    flex: 1;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--text);
    outline: none;
}
.new-row input:focus { border-color: var(--muted); }

.icon { width: 16px; height: 16px; flex: none; color: var(--muted); }

.btn {
    background: var(--text);
    color: var(--inverse);
    border: 1px solid var(--text);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-ghost { background: none; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { color: var(--text); background: var(--hover); }

/* Editor */
.editor-head { padding-top: 24px; }
.editor-head .crumbs { margin-bottom: 10px; }
.editor-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-bottom: 12px; }
.editor-actions .mono { font-size: 11.5px; margin-right: auto; }
#editor-text {
    display: block;
    width: 100%;
    height: calc(100vh - 190px);
    min-height: 300px;
    resize: none;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    font-size: 12.5px;
    line-height: 1.6;
    tab-size: 4;
    outline: none;
    white-space: pre;
    overflow: auto;
}
#editor-text:focus { border-color: var(--faint); }
.notice {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-size: 14px;
}

/* Google Drive upload */
.upload-card { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
#drive-file { display: none; }
.upload-line { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.upload-line span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-bar { margin: 10px 0 8px; height: 5px; }
#drive-detail { font-size: 11.5px; }
.drive-link { display: inline-block; margin-top: 14px; text-decoration: none; }
.drive-hint { font-size: 13px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: var(--text);
    color: var(--inverse);
    font-size: 12px;
    padding: 8px 14px;
    border-radius: 6px;
    max-width: calc(100% - 40px);
    z-index: 20;
}

@media (max-width: 520px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat:nth-child(3) { border-left: 0; }
    .stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
    h1 { font-size: 24px; margin: 24px 0 18px; }
    .metric-value { font-size: 19px; }
}
