:root {
    --bg: #faf7f4;
    --surface: #ffffff;
    --surface-2: #f3ede7;
    --border: #e3dad0;
    --text: #2f2a26;
    --muted: #7d7268;
    --accent: #c2763f;
    --accent-dim: #e8c9ae;
    --danger: #c2453f;
    --warn: #d99012;
    --ok: #4e9c6b;
    --sidebar-w: 232px;
    --sidebar-collapsed-w: 60px;
    --header-h: 56px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; font-size: 12px; }

/* ---------- Header ---------- */
.site-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}

.logo-link { text-decoration: none; flex-shrink: 0; }
.logo-link:hover { text-decoration: none; }
.site-title { font-size: 1.15rem; font-weight: 700; color: var(--accent); letter-spacing: .5px; }

/* ---------- Top hot menu (icons) ---------- */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    gap: 16px;
}

.hot-menu { display: flex; align-items: center; gap: 4px; }

.hot-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--muted);
    transition: background .15s, color .15s;
}

.hot-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.hot-link.active { background: var(--accent-dim); color: var(--text); }
.hot-icon svg { width: 19px; height: 19px; display: block; }

/* ---------- Account area (sign in / profile) ---------- */
.account-menu { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.account-form { margin: 0; }

.account-link {
    display: inline-flex;
    align-items: center;
    height: 32px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: none;
    font: inherit;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s;
}

.account-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.account-link.active { background: var(--accent-dim); color: var(--text); }

.context-switcher { display: flex; align-items: center; gap: 10px; }
.context-label { color: var(--muted); font-size: 12px; white-space: nowrap; }

.context-switcher select,
.form-grid select,
.form-grid input,
.form-grid textarea,
.army input,
.army select,
.pref-table select,
.bill-table input,
.member-table input,
.chat-composer input {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 13px;
    font-family: inherit;
}

/* ---------- Sidebar toggle ---------- */
.menu-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 60;
    width: 36px;
    height: 36px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

.menu-toggle span { display: block; height: 2px; background: var(--text); margin: 0 auto; width: 18px; }

/* ---------- Layout ---------- */
.container { display: flex; align-items: stretch; min-height: calc(100vh - var(--header-h)); }

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 45;
}
.mobile-overlay.active { display: block; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 10px 0;
    transition: width .18s ease;
}

.sidebar.collapsed { width: var(--sidebar-collapsed-w); }
.sidebar.collapsed .menu-text,
.sidebar.collapsed .submenu-arrow { display: none; }
.sidebar.collapsed .submenu { display: none; }
.sidebar.collapsed .menu-link { justify-content: center; padding: 10px 0; }

.sidebar-menu { position: sticky; top: calc(var(--header-h) + 10px); }
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-item { position: relative; }

.menu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    color: var(--muted);
    font-weight: 500;
    transition: background .15s, color .15s;
}

.menu-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.menu-link.active { color: var(--text); background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }

.menu-icon { display: inline-flex; flex-shrink: 0; }
.menu-icon svg { width: 18px; height: 18px; display: block; }
.menu-text { flex: 1; }
.submenu-arrow { color: var(--muted); transition: transform .15s; }
.menu-item.open .submenu-arrow { transform: rotate(90deg); }

.submenu { list-style: none; margin: 0; padding: 0; max-height: 0; overflow: hidden; transition: max-height .18s ease; }
.menu-item.open > .submenu { max-height: 500px; }
.submenu-link { display: block; padding: 7px 14px 7px 42px; color: var(--muted); font-size: 13px; }
.submenu-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.submenu-link.active { color: var(--accent); }
.submenu-separator { height: 1px; background: var(--border); margin: 6px 14px; }

/* ---------- Flyout (collapsed sidebar) ---------- */
.flyout-panel { display: none; }

.sidebar.collapsed .menu-item:hover .flyout-panel {
    display: block;
    position: absolute;
    left: 100%;
    top: 0;
    min-width: 190px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 0 8px 8px 0;
    padding: 8px 0;
    z-index: 50;
}

.flyout-header { display: block; padding: 6px 14px; font-weight: 600; color: var(--text); font-size: 13px; }
.flyout-menu { list-style: none; margin: 0; padding: 0; }
.flyout-link { display: block; padding: 6px 14px; color: var(--muted); font-size: 13px; }
.flyout-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.flyout-link.active { color: var(--accent); }

/* ---------- Main content ---------- */
.main-content { flex: 1; padding: 22px 26px; min-width: 0; }
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.5rem; }
.page-description { margin: 0; color: var(--muted); }

/* ---------- Cards ---------- */
.context-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 18px;
}

.context-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.context-key { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.context-value { display: block; font-size: 15px; font-weight: 600; margin-top: 2px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

.card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    color: var(--text);
    transition: border-color .15s, transform .15s;
}

.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.card h2 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }
.card-muted { opacity: .55; }
.card-muted:hover { transform: none; border-color: var(--border); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 1.05rem; }
.panel-sub { margin: 14px 0 8px; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* ---------- Toolbar / badges ---------- */
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar-right { justify-content: flex-end; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}
.badge-active { background: var(--accent-dim); color: var(--text); border-color: var(--accent); }
a.badge:hover { text-decoration: none; color: var(--text); }

.btn {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 7px;
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { text-decoration: none; filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

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

/* Row actions: vote up and mark done sit inside table cells */
.inline-form { display: inline; margin: 0; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 7px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn svg { width: 16px; height: 16px; }

.task-votes { white-space: nowrap; }
.vote-count { margin-left: 8px; color: var(--muted); font-variant-numeric: tabular-nums; }
.note-when { color: var(--muted); font-size: 12px; white-space: nowrap; }

.completed-list { list-style: none; margin: 0; padding: 0; }
.completed-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.completed-list li:last-child { border-bottom: none; }
.completed-when { color: var(--muted); font-size: 12px; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.data-table th, .data-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table thead th { background: var(--surface-2); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table.matrix th { white-space: nowrap; }
.row-today { background: rgba(194, 118, 63, .10); }

/* The two figures the page exists to deliver, big enough to read at a glance.
   The pretax number is the aside, so it sits in the corner in muted small text */
.total-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 16px; }

.total-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px 28px;
}
.total-card-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.total-card-value { display: block; margin-top: 4px; font-size: 2rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.total-card-pretax { position: absolute; right: 18px; bottom: 9px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Amount boxes line up under the column heading they are typed into */
.bill-table input { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }

/* The household list is edited in place, so every row is a row of boxes. They
   share the width rather than each claiming a default one, which is what keeps
   eight columns on the screen instead of behind a scrollbar */
.member-table { table-layout: fixed; }
.member-table th, .member-table td { padding: 7px 8px; }
.member-table input[type="text"],
.member-table input[type="email"] { width: 100%; min-width: 0; }
.member-table input[type="checkbox"] { margin: 0; }
.member-table .col-flag { width: 74px; text-align: center; }
.member-table .col-state { width: 90px; }
.member-table .col-actions { width: 150px; white-space: nowrap; }

/* ---------- Stance / severity chips ---------- */
.stance, .sev {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 5px;
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.stance-nap, .stance-truce { color: var(--ok); border-color: var(--ok); }
.stance-alliance, .stance-vassal { color: var(--accent); border-color: var(--accent); }
.stance-war, .stance-hostile { color: var(--danger); border-color: var(--danger); }

.sev-low { color: var(--muted); }
.sev-medium { color: var(--warn); border-color: var(--warn); }
.sev-high, .sev-critical { color: var(--danger); border-color: var(--danger); }

/* ---------- Empty state ---------- */
.empty-state {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 34px 20px;
    text-align: center;
}
.empty-title { margin: 0 0 6px; font-weight: 600; }
.empty-text { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; max-width: 900px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-grid label.full { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; }

/* ---------- Vacation planner ---------- */
/* Each row posts on its own, so the forms sit outside the table and the
   controls reach them by their form attribute */
.row-form { display: none; }
.row-actions { white-space: nowrap; }
.row-actions .icon-btn + .icon-btn { margin-left: 6px; }
.ruled-out td { opacity: .55; }
/* "Ignore for now" sits next to its label rather than above it, so the row
   stays one line high like the dropdowns beside it */
.check-inline { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.check-inline input { margin: 0; }
.check-inline span { font-size: .85rem; color: var(--muted); }
/* Says what just happened to the row that saved itself; empty most of the time,
   so it reserves its width to stop the Clear button shifting under the cursor */
.save-state { display: inline-block; min-width: 52px; font-size: 12px; color: var(--muted); }
.save-state.save-ok { color: var(--accent); }
.save-state.save-bad { color: #b4402f; }

/* ---------- Chat ---------- */
.chat-window {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    min-height: 260px;
    margin-bottom: 12px;
}
.chat-message { padding: 8px 0; border-bottom: 1px solid var(--border); }
.chat-author { font-weight: 600; }
.chat-time { color: var(--muted); font-size: 12px; margin-left: 8px; }
.chat-body { margin: 4px 0 0; }
.chat-composer { display: flex; gap: 8px; }
.chat-composer input { flex: 1; }

/* ---------- Guides ---------- */
.guide-list { list-style: none; margin: 0; padding: 0; }
.guide-list li { padding: 7px 0; border-bottom: 1px solid var(--border); }
.guide-list li:last-child { border-bottom: none; }
.guide-summary { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

.guide-body { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.guide-body h2 { margin: 18px 0 8px; font-size: 1.05rem; }
.guide-body h2:first-child { margin-top: 0; }
.guide-body p, .guide-body li { font-size: 14px; }
.guide-body .data-table { margin-bottom: 6px; }
.guide-lead { color: var(--muted); margin-top: 0; }

.guide-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

.guide-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
}

.guide-card h2 { margin: 0 0 10px; font-size: .95rem; }
.guide-card-tag { display: block; color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 2px; }
.guide-card .card-label { margin: 10px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.guide-card .label-do { color: var(--ok); }
.guide-card .label-dont { color: var(--warn); }
.guide-card ul { margin: 0; padding-left: 18px; }
.guide-card ul li { font-size: 13px; margin-bottom: 3px; }
.guide-card-live { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.guide-card-live .guide-card-tag { color: var(--warn); }
.tag-live { color: var(--bg); background: var(--warn); border-radius: 3px; padding: 1px 5px; margin-left: 4px; }

.hero-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 9px 12px; margin: 0 0 18px; }
.hero-strip-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.hero-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 13px 4px 4px;
    color: var(--text);
    font-size: 13px;
    transition: border-color .15s;
}
.hero-chip:hover { border-color: var(--accent); text-decoration: none; }
.hero-chip-more { padding: 6px 13px; color: var(--muted); font-size: 12px; }
.hero-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent-dim);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.hero-portrait { object-fit: cover; background: var(--surface-2); }

/* ---------- Fight simulator ---------- */
.sim-armies { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* min-inline-size lets the fieldset shrink so .table-scroll scrolls the grid
   instead of the whole page. */
.army { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; min-width: 0; min-inline-size: 0; }
.army legend { padding: 0 6px; font-weight: 600; color: var(--accent); }
/* Tier grid: headers sit directly over their column, boxes share their borders. */
.army-matrix { border-collapse: collapse; }
.army-matrix td { padding: 0; }
.army-matrix thead th {
    padding: 0 0 5px;
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.army-matrix tbody th { padding: 0 10px 0 0; text-align: left; color: var(--muted); font-weight: 500; white-space: nowrap; }
.army-matrix input { display: block; width: 62px; padding: 6px; text-align: center; border-radius: 0; }
.army-matrix td + td input { margin-left: -1px; }
.army-matrix tbody tr + tr input { margin-top: -1px; }
.matrix-total-row th { padding-top: 10px !important; color: var(--text) !important; }
.head-unit { display: block; font-size: 9px; opacity: .7; font-weight: 400; }
.warehouse-cell { padding: 0 0 0 14px !important; }
.warehouse-cell input { width: 74px; text-align: right; }
.chest-cell { color: var(--muted); }
.matrix-total-row .army-total { padding-top: 10px; color: var(--text); font-weight: 600; }
.army-matrix .army-total-head { padding-left: 14px; text-align: right; }
.army-matrix .army-total { padding-left: 14px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.army-power-cell { font-variant-numeric: tabular-nums; }
.train-more {
    display: inline-block;
    margin-left: 7px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--warn);
    color: var(--bg);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .4px;
    vertical-align: 1px;
}
.army-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; margin-top: 12px; }
.army-stat { color: var(--muted); font-size: 13px; }
.army-stat strong { color: var(--text); font-variant-numeric: tabular-nums; margin-left: 2px; }
.army-stat-input { display: inline-flex; align-items: center; gap: 8px; }
.army-stat-input input { width: 64px; text-align: center; }
.army-stat-split { font-size: 12px; opacity: .75; }

/* ---------- Backpack calculator ---------- */
.backpack-totals { margin-bottom: 18px; }
.backpack-totals .context-note { color: var(--muted); font-size: 11px; font-weight: 400; }
.coins-field { display: flex; align-items: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.coins-field label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.coins-field input { width: 120px; text-align: right; }
.coins-field .hint { margin: 0; }
.chest-field label { gap: 5px; }
.chest-field input { width: 64px; }
.chest-label { color: var(--muted); font-size: 13px; }
.balance-ref { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 4px; }
.balance-over { color: var(--ok); }
.balance-short { color: var(--warn); }
.balance-level { color: var(--muted); }
.balance-empty { color: var(--muted); opacity: .5; }
.res-icon { display: inline-flex; vertical-align: -3px; margin-right: 7px; color: var(--muted); }
.res-icon svg { width: 15px; height: 15px; }
.denomination-head { text-align: center; border-bottom: 1px solid var(--border); padding-bottom: 3px !important; }
.storage-head { font-size: 10px !important; opacity: .7; padding-top: 3px !important; }

.page-credit { margin: 22px 0 0; color: var(--muted); font-size: 12px; }

.notice-banner {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    padding: 11px 14px;
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}
.army-stat-split strong { font-weight: 500; }

/* Counts are typed, not stepped: no spinner arrows on the army inputs. */
.army input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.army input[type="number"]::-webkit-outer-spin-button,
.army input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.table-scroll { overflow-x: auto; }
.matrix-side th { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.casualty-injured { color: var(--warn); }
.casualty-dead { color: var(--danger); }

.sim-form .form-actions { margin-top: 14px; }
.sim-result { margin-top: 22px; }
.result-winner { font-size: 1.2rem; margin: 0 0 12px; }
.result-attacker { color: var(--accent); }
.result-defender { color: var(--warn); }
.result-draw { color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .menu-toggle { display: flex; }
    .site-header { padding-left: 56px; }
    .context-label { display: none; }

    .sidebar {
        position: fixed;
        top: var(--header-h);
        bottom: 0;
        left: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .sidebar.active { transform: translateX(0); }
    .main-content { padding: 16px; }
}
