/* Light, quiet workspace: a pale side rail, white canvas, 12px radii, hairline shadows instead of
   borders, Inter (Noto Sans Thai for Thai). Dark mode follows the system. */
:root {
    --bg: #ffffff; --rail: #fafafa; --panel: #ffffff; --sunk: #f9f9fc;
    --text: #1b1b1e; --muted: #565b61; --faint: #85898e;
    --line: rgba(215, 216, 218, 0.6); --line-strong: #d7d8da; --hover: #f2f2f5; --selected: #ececef;
    --accent: #0b57d0; --primary: #1b1b1e; --on-primary: #ffffff;
    --shadow: 0 2px 1px rgba(27, 27, 30, 0.04), 0 0 1px rgba(27, 27, 30, 0.4);
    --warn-bg: #fef3e0; --warn: #8a4f00; --bad-bg: #fce8e6; --bad: #b3261e;
    --ok-bg: #e6f4ea; --ok: #146c2e; --info-bg: #e8f0fe; --info: #0b57d0;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131314; --rail: #1b1b1e; --panel: #1e1f22; --sunk: #18181b;
        --text: #e3e3e6; --muted: #a9acb1; --faint: #85898e;
        --line: rgba(255, 255, 255, 0.08); --line-strong: #3a3b3f; --hover: #26272b; --selected: #2f3034;
        --accent: #a8c7fa; --primary: #e3e3e6; --on-primary: #131314;
        --shadow: 0 0 0 1px rgba(255, 255, 255, 0.07);
        --warn-bg: #3b2b10; --warn: #f5c56b; --bad-bg: #3c1715; --bad: #f2b8b5;
        --ok-bg: #12301c; --ok: #8fd6a4; --info-bg: #1b2a44; --info: #a8c7fa;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font-family: "Inter", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon {
    font-family: "Material Symbols Outlined"; font-weight: normal; font-style: normal; font-size: 18px;
    line-height: 1; letter-spacing: normal; text-transform: none; white-space: nowrap; direction: ltr;
    display: inline-block; width: 18px; overflow: hidden; flex: none;
    font-feature-settings: "liga"; -webkit-font-feature-settings: "liga";
}

/* ---- side rail ---- */
body.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
    position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 8px;
    background: var(--rail); border-right: 1px solid var(--line); padding: 14px 8px 10px;
}
.brand {
    display: flex; align-items: center; gap: 8px; padding: 4px 8px 12px;
    color: var(--text); font-size: 17px; font-weight: 500; letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand .icon { font-size: 22px; width: 22px; color: var(--accent); }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side .section {
    color: var(--faint); font-size: 12px; letter-spacing: 0.04em; padding: 14px 8px 4px;
}
.side .section:first-child { padding-top: 4px; }
.side nav a {
    display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 8px; border-radius: 12px;
    color: var(--muted); font-weight: 500;
}
.side nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.side nav a.active { background: var(--selected); color: var(--text); }
.who {
    display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 8px; border-radius: 12px;
    background: var(--panel); box-shadow: var(--shadow);
}
.who .avatar {
    width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none;
    background: #c5221f; color: #fff; font-size: 12px; font-weight: 600;
}
.who .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

/* ---- canvas ---- */
main { padding: 28px 32px 48px; max-width: 1440px; width: 100%; }
body.bare main { max-width: none; }
h1 { font-size: 24px; font-weight: 500; letter-spacing: -0.015em; margin: 0 0 20px; }
h2 { font-size: 16px; font-weight: 500; margin: 28px 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13px; }
ul.muted { padding-left: 20px; margin: 0 0 16px; }

.panel {
    background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
    padding: 16px; margin-bottom: 16px;
}

/* ---- count tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.tile {
    display: block; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
    padding: 12px 14px; color: var(--text); transition: background 0.12s;
}
.tile:hover { background: var(--hover); text-decoration: none; }
.tile b { display: block; font-size: 26px; font-weight: 500; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }
.tile b { overflow-wrap: anywhere; }
.tile b.nowrap { white-space: nowrap; overflow-wrap: normal; font-size: 22px; }
.tile.wide { grid-column: span 2; }
@media (max-width: 420px) { .tile.wide { grid-column: auto; } .tile.wide b { font-size: 20px; } }
.tile.active { background: var(--selected); box-shadow: inset 0 0 0 1px var(--faint); }

/* ---- tables ---- */
.scroll { overflow-x: auto; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 16px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); }
main > table { border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; margin-bottom: 16px; }
.panel table, .scroll table { background: transparent; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
th { font-size: 12px; color: var(--faint); font-weight: 500; background: var(--sunk); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--sunk); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- tags ---- */
.tag {
    display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px;
    font-size: 12px; font-weight: 500; margin-right: 4px;
}
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.info { background: var(--info-bg); color: var(--info); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; word-break: break-all; }

/* ---- forms ---- */
form.inline { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea {
    min-height: 34px; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
    background: var(--panel); font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
input[type=file] { padding: 5px; }
button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 16px; border-radius: 12px; cursor: pointer; font-weight: 500;
    background: var(--primary); color: var(--on-primary); border: 1px solid var(--primary);
}
button:hover { opacity: 0.88; }
button.secondary { background: var(--panel); color: var(--text); border-color: var(--line-strong); }
button.secondary:hover { background: var(--hover); opacity: 1; }
button.ghost {
    height: 28px; width: 28px; padding: 0; border-radius: 8px; background: transparent;
    border-color: transparent; color: var(--muted);
}
button.ghost:hover { background: var(--hover); color: var(--text); opacity: 1; }

.msg { padding: 10px 14px; border-radius: 12px; margin-bottom: 16px; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.bad { background: var(--bad-bg); color: var(--bad); }
pre {
    background: var(--sunk); padding: 14px; border-radius: 12px; overflow: auto; max-height: 480px;
    font-size: 12.5px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; background: var(--sunk); padding: 1px 5px; border-radius: 6px; }

/* ---- sign-in ---- */
body.bare { min-height: 100vh; background: var(--rail); }
.login { max-width: 380px; margin: 12vh auto 0; padding: 28px; }
.login h1 { font-size: 22px; margin-bottom: 18px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login button { margin-top: 4px; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }

/* ---- narrow screens: the rail becomes a top bar ---- */
@media (max-width: 860px) {
    body.app { display: block; }
    .side {
        position: sticky; z-index: 2; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
        gap: 4px 8px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line);
    }
    .brand { padding: 4px; flex: 1; }
    .side nav { order: 3; flex: 0 0 100%; flex-direction: row; overflow-x: auto; gap: 4px; }
    .side .section { display: none; }
    .side nav a { white-space: nowrap; flex: none; }
    .who { box-shadow: none; background: transparent; padding: 0; }
    .who .name { display: none; }
    main { padding: 18px 16px 40px; }
    .grid2 { grid-template-columns: 1fr; }
}
