:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-soft: #f1f5f9;
    --line: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --primary: #0f4c81;
    --primary-dark: #0b3b65;
    --success: #168a55;
    --warning: #b7791f;
    --danger: #c2410c;
    --radius: 12px;
    --shadow: 0 12px 30px rgba(15, 23, 42, .07);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
}

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

p {
    margin: 0 0 10px;
}

.container {
    width: min(1120px, calc(100% - 32px));
    margin: 24px auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.container.sm {
    max-width: 560px;
}

.container.md {
    max-width: 860px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    color: #fff;
    background: var(--primary);
}

.topbar h1,
.topbar h2 {
    margin: 0;
    font-size: 18px;
}

.layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 24px;
    width: min(1180px, calc(100% - 32px));
    margin: 24px auto;
}

.sidebar,
.panel,
.card,
.form-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.sidebar,
.panel,
.card {
    padding: 22px;
}

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

.sidebar a {
    display: block;
    padding: 10px 12px;
    margin: 4px 0;
    color: var(--text);
    text-decoration: none;
    border-radius: 10px;
}

.sidebar a:hover,
.sidebar a.active {
    color: var(--primary);
    background: #eaf2f9;
}

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

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 16px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.full {
    grid-column: 1 / -1;
}

.form-box {
    padding: 18px;
    margin-bottom: 20px;
    background: var(--surface-soft);
}

.form-group {
    margin-bottom: 14px;
}

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

input,
select,
textarea {
    width: 100%;
    padding: 10px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

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

textarea.code {
    min-height: 260px;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
}

input[readonly] {
    color: var(--muted);
    background: #eef2f7;
}

.help {
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
}

.btn,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 9px 14px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--primary);
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover,
button:hover {
    background: var(--primary-dark);
}

.btn.block,
button.block {
    width: 100%;
}

.btn.muted {
    background: #64748b;
}

.btn.success {
    background: var(--success);
}

.btn.warning {
    color: #261600;
    background: #facc15;
}

.btn.danger {
    background: #b91c1c;
}

.btn.small {
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
}

.alert {
    padding: 12px 14px;
    margin-bottom: 16px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #eef2ff;
}

.alert.success {
    color: #14532d;
    background: #dcfce7;
    border-color: #bbf7d0;
}

.alert.error {
    color: #7f1d1d;
    background: #fee2e2;
    border-color: #fecaca;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

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

th {
    color: #334155;
    background: var(--surface-soft);
    font-weight: 700;
}

tr:hover td {
    background: #f8fafc;
}

.nowrap {
    white-space: nowrap;
}

.empty {
    padding: 22px;
    color: var(--muted);
    text-align: center;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge.active {
    color: #075985;
    background: #e0f2fe;
}

.badge.reserve {
    color: #854d0e;
    background: #fef3c7;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.stat {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.stat strong {
    display: block;
    font-size: 24px;
    color: var(--primary);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-box {
    width: min(380px, 100%);
    padding: 26px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.login-title {
    text-align: center;
    margin-bottom: 20px;
}

@media (max-width: 820px) {
    .layout,
    .grid-2,
    .grid-3,
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .topbar,
    .page-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .page-actions {
        justify-content: flex-start;
    }
}

/* Template editor */
.container.wide {
    width: min(1380px, calc(100% - 32px));
}

.muted-text {
    margin: 0;
    color: var(--muted);
}

.template-form {
    background: #f8fafc;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip-row .chip {
    min-height: 30px;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    color: var(--primary);
    background: #fff;
    font-size: 12px;
    font-weight: 700;
}

.chip-row .chip:hover {
    color: #fff;
    background: var(--primary);
}

.template-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
    gap: 16px;
    margin: 14px 0 18px;
}

.editor-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    overflow: hidden;
}

.editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
}

.editor-status {
    color: var(--muted);
    font-size: 12px;
}

.mini-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.editor-toolbar button {
    min-height: 30px;
    padding: 5px 9px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    color: var(--text);
    background: #fff;
    font-size: 12px;
}

.editor-toolbar button:hover {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.paper-frame {
    display: block;
    width: 100%;
    height: 660px;
    border: 0;
    background: #fff;
}

.paper-frame.sample {
    height: 520px;
}

.template-code {
    min-height: 660px;
    border: 0;
    border-radius: 0;
    font-size: 12px;
    line-height: 1.45;
}

.sample-panel {
    margin-bottom: 18px;
}

.help.inline {
    margin: 0;
}

@media (max-width: 980px) {
    .template-workspace {
        grid-template-columns: 1fr;
    }

    .paper-frame,
    .template-code {
        min-height: 520px;
    }
}

button.success {
    background: var(--success);
}

button.success:hover {
    background: #126b43;
}

.template-note {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 10px 12px;
    margin: 4px 0 14px;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    color: #1e3a8a;
    background: #eff6ff;
    font-size: 13px;
}

.template-note code {
    padding: 1px 5px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .75);
}

@media (max-width: 720px) {
    .template-note {
        display: block;
    }

    .template-note strong {
        display: block;
        margin-bottom: 4px;
    }
}

.back-home-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 42px;
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #64748b;
    background: #64748b;
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
}

.back-home-button:hover {
    background: #475569;
    border-color: #475569;
    color: #ffffff;
}