/*
 * Kemori admin console. Mobile first: one column, 16px gutters, 44px touch targets and
 * 16px form text (no iOS zoom on focus). From 900px, `.layout-split` becomes two columns.
 * Served same-origin under a CSP without 'unsafe-inline' — keep every style in this file.
 */

:root {
    color-scheme: light dark;
    --bg: #f5f6f4;
    --surface: #ffffff;
    --text: #1d2320;
    --muted: #5b655f;
    --border: #d9ded9;
    --accent: #1b6fa8;
    --accent-text: #ffffff;
    --danger: #b3261e;
    --danger-text: #ffffff;
    --notice-bg: #e6f1f8;
    --env-bg: #fde7c8;
    --env-text: #6b3d00;
    --focus: #1b6fa8;
    --radius: 12px;
    --gutter: 16px;
    font-family: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121614;
        --surface: #1c211e;
        --text: #e7ebe8;
        --muted: #a3ada6;
        --border: #313934;
        --accent: #7cc4f0;
        --accent-text: #0b1f2c;
        --danger: #f2b8b5;
        --danger-text: #3b0b08;
        --notice-bg: #17303f;
        --env-bg: #4a2f0c;
        --env-text: #fde7c8;
        --focus: #7cc4f0;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--accent);
}

h1,
h2,
h3 {
    line-height: 1.25;
    margin: 0 0 12px;
}

h1 {
    font-size: 1.375rem;
}

h2 {
    font-size: 1.125rem;
}

p {
    margin: 0 0 12px;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* Header ------------------------------------------------------------------ */

.admin-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

.admin-header__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px var(--gutter);
    min-height: 56px;
}

.admin-brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.admin-env {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--env-bg);
    color: var(--env-text);
    font-size: 0.8125rem;
    font-weight: 600;
}

.admin-who {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.875rem;
    overflow-wrap: anywhere;
}

.admin-logout {
    margin: 0;
}

/* Layout ------------------------------------------------------------------ */

.admin-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--gutter);
    padding-bottom: calc(var(--gutter) * 2 + env(safe-area-inset-bottom));
}

.stack > * + * {
    margin-top: 12px;
}

.layout-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--gutter);
}

@media (min-width: 900px) {
    .layout-split {
        grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    }
}

/* Cards ------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--gutter);
    margin-bottom: var(--gutter);
    overflow-wrap: anywhere;
}

.card--narrow {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.muted {
    color: var(--muted);
}

.notice {
    background: var(--notice-bg);
    border-radius: var(--radius);
    padding: 12px var(--gutter);
    margin: 0 0 var(--gutter);
}

.notice--danger {
    color: var(--danger);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 0.8125rem;
}

/* Buttons and forms ------------------------------------------------------- */

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.button--block {
    width: 100%;
}

.button--quiet {
    background: transparent;
    color: var(--accent);
    border-color: var(--border);
}

.button--danger {
    background: var(--danger);
    color: var(--danger-text);
}

button:disabled,
.button[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}

input,
select,
textarea {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.field {
    margin-bottom: var(--gutter);
}

.field-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 6px;
}

/* Lists and tables -------------------------------------------------------- */

.list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.list > li {
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.list > li:first-child {
    border-top: 0;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 600;
}

dl {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px 12px;
    margin: 0;
}

dt {
    color: var(--muted);
    font-size: 0.875rem;
}

dd {
    margin: 0 0 8px;
}

@media (min-width: 600px) {
    dl {
        grid-template-columns: max-content minmax(0, 1fr);
    }

    dd {
        margin: 0;
    }
}
