:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #16202e;
    --muted: #5b6b80;
    --border: #dbe3ee;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --danger: #b42318;
    --danger-hover: #912018;
    --success-bg: #e7f6ec;
    --success-text: #14532d;
    --error-bg: #fdecec;
    --error-text: #8a1c12;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1220;
        --surface: #151d2e;
        --surface-2: #1b2537;
        --text: #e6ecf5;
        --muted: #9aabc2;
        --border: #2a3a55;
        --primary: #6d9bff;
        --primary-hover: #8db2ff;
        --danger: #ff7b72;
        --danger-hover: #ff9b94;
        --success-bg: #11301f;
        --success-text: #9ae6b4;
        --error-bg: #3a1414;
        --error-text: #ffb4ab;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
                 "Noto Sans", "PingFang TC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 1rem; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 60px;
    flex-wrap: wrap;
    padding-top: .5rem;
    padding-bottom: .5rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    color: var(--text);
    font-weight: 700;
    letter-spacing: .01em;
}
.brand:hover { text-decoration: none; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-size: .72rem;
    font-weight: 800;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.topnav a { color: var(--muted); font-weight: 600; }
.topnav a:hover { color: var(--text); text-decoration: none; }

.langs { display: inline-flex; gap: .35rem; flex-wrap: wrap; }
.langs a {
    padding: .2rem .5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .78rem;
    color: var(--muted);
}
.langs a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.main { padding: 1.5rem 1rem 3rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

h1 { font-size: 1.5rem; margin: 0 0 .35rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.1rem 0 .75rem; }
.card > h2:first-of-type { margin-top: 1.1rem; }
p { margin: .35rem 0 .9rem; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.strong { font-weight: 600; }
.right { text-align: right; }
.breadcrumb { margin: 0 0 1rem; font-weight: 600; }

.alert {
    border-radius: 10px;
    padding: .7rem .9rem;
    margin: 0 0 1rem;
    font-size: .92rem;
    border: 1px solid transparent;
}
.alert-error { background: var(--error-bg); color: var(--error-text); border-color: currentColor; }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: currentColor; }

label { display: block; font-weight: 600; font-size: .9rem; }
label span { display: block; margin-bottom: .3rem; }
label small { display: block; font-weight: 400; color: var(--muted); margin-top: .25rem; }

input[type="text"], input[type="password"], input[type="number"], select {
    width: 100%;
    padding: .6rem .7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
}

.stack { display: grid; gap: 1rem; }
.stack .button { width: 100%; }

.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: .9rem 1rem;
    align-items: start;
    margin-bottom: 1rem;
}
.grid-form .grow { grid-column: span 2; }
.form-actions { display: flex; align-items: end; }
.form-actions .button { min-height: 42px; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .55rem .95rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}
.button:hover { text-decoration: none; border-color: var(--muted); }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.button.danger:hover { background: var(--danger); color: #fff; }
.button.ghost { background: transparent; }
.button.small { padding: .35rem .6rem; font-size: .82rem; }

.link-button {
    background: none;
    border: 0;
    padding: 0;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.link-button:hover { color: var(--text); }

.inline { display: inline; margin: 0; }
.actions { display: flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .65rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    padding: .12rem .45rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: .76rem;
    font-weight: 700;
    letter-spacing: .03em;
}
.content { word-break: break-word; font-size: .88rem; }

.auth-card { max-width: 420px; margin: 3vh auto 0; }

.footer {
    padding-top: 1rem;
    padding-bottom: 2rem;
    color: var(--muted);
    font-size: .8rem;
}

@media (max-width: 720px) {
    .grid-form { grid-template-columns: 1fr; }
    .grid-form .grow { grid-column: auto; }
    .form-actions .button { width: 100%; }

    .table-wrap { overflow: visible; }
    table, thead, tbody, tr, td { display: block; width: 100%; }
    thead { display: none; }
    tbody tr {
        border: 1px solid var(--border);
        border-radius: 10px;
        margin-bottom: .7rem;
        padding: .35rem .65rem;
        background: var(--surface-2);
    }
    td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 1rem;
        border-bottom: 1px dashed var(--border);
        padding: .5rem 0;
        text-align: right;
    }
    td:last-child { border-bottom: 0; }
    td::before {
        content: attr(data-label);
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--muted);
        font-weight: 700;
        text-align: left;
        flex: 0 0 42%;
    }
    td.actions { justify-content: flex-end; flex-wrap: wrap; }
}
