:root {
    --ink: #241f1c;
    --muted: #756b64;
    --line: #e8e1db;
    --canvas: #f7f4f1;
    --paper: #fffdfa;
    --accent: #8b5d3b;
    --accent-dark: #684128;
    --danger: #a53f3f;
    --success: #2f6b4b;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); color: var(--ink); }
a { color: inherit; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.65rem, 3vw, 2.25rem); font-weight: 500; }
h2 { margin-bottom: .35rem; font-family: Georgia, serif; font-size: 1.45rem; font-weight: 500; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 240px; display: flex; flex-direction: column; padding: 1.5rem 1rem; color: #f9f3ec; background: #241f1c; }
.brand, .auth-brand { display: flex; align-items: center; gap: .7rem; font-family: Georgia, serif; text-decoration: none; font-size: 1.08rem; }
.brand span, .auth-brand span { display: grid; width: 2.5rem; height: 2.5rem; place-items: center; border: 1px solid #a87b58; border-radius: 50%; font-size: .9rem; letter-spacing: .08em; }
.sidebar nav { display: grid; gap: .3rem; margin-top: 2.5rem; }
.sidebar nav a, .nav-button { display: block; width: 100%; padding: .75rem .85rem; border: 0; border-radius: .55rem; color: #d9d0c9; background: transparent; font: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.sidebar nav a:hover, .nav-button:hover { color: white; background: #3a312c; }
.logout-form { margin-top: auto; }
.main { min-height: 100vh; margin-left: 240px; padding: 2rem clamp(1rem, 4vw, 3.5rem) 4rem; }
.topbar { display: flex; align-items: center; min-height: 4.25rem; margin-bottom: 1.5rem; }

.panel, .stat-card, .auth-card { border: 1px solid var(--line); border-radius: .9rem; background: var(--paper); box-shadow: 0 8px 28px rgba(50, 38, 29, .05); }
.panel { margin-bottom: 1.25rem; padding: clamp(1rem, 2.5vw, 1.5rem); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.panel-heading h2, .panel-heading p { margin-bottom: 0; }
.eyebrow { margin-bottom: .3rem; color: var(--accent); font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.muted, .hint { color: var(--muted); line-height: 1.55; }
.hint { margin: 1rem 0 0; font-size: .82rem; }
.empty { margin: 2rem 0; color: var(--muted); text-align: center; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.stat-card { display: grid; gap: .5rem; padding: 1.5rem; text-decoration: none; transition: transform .15s ease, border-color .15s ease; }
.stat-card:hover { transform: translateY(-2px); border-color: #cdb6a3; }
.stat-card span, .stat-card small { color: var(--muted); }
.stat-card strong { font-family: Georgia, serif; font-size: 2.8rem; font-weight: 400; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 1.25rem; align-items: start; }

.form-stack { display: grid; gap: 1rem; }
label { display: grid; gap: .45rem; color: #4b423c; font-size: .84rem; font-weight: 650; }
label small { color: var(--muted); font-weight: 400; }
input, textarea, select { width: 100%; border: 1px solid #d9cfc7; border-radius: .5rem; padding: .72rem .8rem; color: var(--ink); background: #fff; font: inherit; font-size: .94rem; outline: none; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 93, 59, .12); }
.field-error { color: var(--danger); font-weight: 600; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.code-editor { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; }
.editor-form { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 1.25rem; align-items: start; }
.editor-form .panel { margin: 0; }
.form-main { display: grid; gap: 1rem; }
.form-side { position: sticky; top: 1rem; display: grid; gap: 1rem; }
.source-note { padding: .75rem .9rem; border-left: 3px solid var(--accent); color: #68574b; background: #f5ede6; font-size: .85rem; line-height: 1.5; }

.button { display: inline-flex; min-height: 2.55rem; align-items: center; justify-content: center; gap: .4rem; border: 1px solid transparent; border-radius: .5rem; padding: .62rem .9rem; font: inherit; font-size: .86rem; font-weight: 700; text-decoration: none; cursor: pointer; }
.button-primary { color: white; background: var(--accent); }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { border-color: #d9cfc7; color: var(--ink); background: white; }
.button-secondary:hover { border-color: #bda99b; background: #fbf7f3; }
.button-danger { margin-top: 1rem; border-color: #e5bcbc; color: var(--danger); background: #fff7f7; }
.import-actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.25rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: .7rem .75rem; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
td { padding: .85rem .75rem; border-bottom: 1px solid #eee8e3; font-size: .88rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.record-link, .text-link { color: var(--accent-dark); font-weight: 700; text-decoration: none; }
.record-link:hover, .text-link:hover { text-decoration: underline; }
.row-meta { display: block; margin-top: .25rem; color: var(--muted); font-size: .76rem; }
.product-cell { display: flex; min-width: 240px; align-items: center; gap: .75rem; }
.product-cell img { width: 44px; height: 44px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: .4rem; object-fit: cover; }
.badge { display: inline-flex; border-radius: 999px; padding: .25rem .55rem; color: #5d5149; background: #eee7e1; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.badge-completed { color: #24593d; background: #e1f1e8; }
.badge-failed { color: #8c3232; background: #f8e1e1; }
.badge-running { color: #765215; background: #f7edce; }
.error-row td { padding-top: .3rem; color: var(--danger); font-size: .78rem; }
.search-form { display: flex; width: min(100%, 430px); gap: .5rem; }
.pagination { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: 1.25rem; }
.pagination a { display: grid; min-width: 2.25rem; height: 2.25rem; place-items: center; border: 1px solid var(--line); border-radius: .4rem; background: white; font-size: .8rem; text-decoration: none; }
.pagination a.active { border-color: var(--accent); color: white; background: var(--accent); }

.alert { margin-bottom: 1.25rem; border: 1px solid; border-radius: .6rem; padding: .8rem 1rem; font-size: .88rem; line-height: 1.45; }
.alert-success { border-color: #b9dac7; color: #24593d; background: #edf8f1; }
.alert-error { border-color: #e7bcbc; color: #8c3232; background: #fff0f0; }
.auth-body { display: grid; min-height: 100vh; place-items: center; padding: 1.25rem; background: #241f1c; }
.auth-shell { width: min(100%, 430px); }
.auth-brand { justify-content: center; margin-bottom: 1.25rem; color: #f9f3ec; }
.auth-card { padding: clamp(1.4rem, 5vw, 2.25rem); }
.auth-card h1 { margin-bottom: .55rem; }
.auth-card .form-stack { margin-top: 1.5rem; }

@media (max-width: 850px) {
    .sidebar { position: static; width: auto; flex-direction: row; align-items: center; padding: .85rem 1rem; overflow-x: auto; }
    .sidebar .brand { flex: 0 0 auto; font-size: 0; }
    .sidebar nav { display: flex; margin: 0 0 0 1rem; }
    .sidebar nav a, .nav-button { white-space: nowrap; }
    .logout-form { margin: 0 0 0 auto; }
    .main { margin-left: 0; padding-top: 1.25rem; }
    .content-grid, .editor-form { grid-template-columns: 1fr; }
    .form-side { position: static; }
}

@media (max-width: 580px) {
    .sidebar .brand { display: none; }
    .sidebar nav { margin-left: 0; }
    .sidebar nav a, .nav-button { padding: .55rem .65rem; font-size: .8rem; }
    .topbar { min-height: 3rem; }
    .stats-grid, .field-grid, .field-grid.three { grid-template-columns: 1fr; }
    .panel-heading { align-items: stretch; flex-direction: column; }
    .search-form { width: 100%; }
}
