:root {
    --bg: #f4f3ee;
    --surface: #ffffff;
    --border: #e7e5df;
    --border-strong: #d9d6ce;
    --text: #1c2321;
    --muted: #6b726f;
    --faint: #9aa09d;
    --primary: #0b5a49;
    --primary-dark: #08483a;
    --primary-soft: #e6f2ee;
    --amber: #c27c0e;
    --amber-soft: #fdf3e1;
    --red: #c2410c;
    --red-soft: #fdecea;
    --blue-soft: #e9efff;
    --blue: #3b5bdb;
    --purple-soft: #f1ebff;
    --purple: #7048e8;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 25, .04);
    --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 600; }
h1 em { font-style: italic; color: var(--primary); }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.icon { flex-shrink: 0; vertical-align: middle; }
.container { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.accent { color: var(--primary); font-weight: 600; }
.nowrap { white-space: nowrap; }
.warn-text { color: var(--amber); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; gap: 20px; height: 64px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border: 2px solid var(--primary); border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: var(--primary); }
.topbar-search { flex: 1; max-width: 420px; margin: 0 auto; position: relative; }
.topbar-search .icon, .search-field .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.topbar-search input, .search-field input { width: 100%; height: 38px; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 0 12px 0 36px; font: inherit; color: var(--text); }
.topbar-search input:focus, .search-field input:focus { outline: none; border-color: var(--primary); background: #fff; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.user-menu-panel { position: absolute; right: 0; top: 42px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 180px; box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.user-menu-name { padding: 8px 10px; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: none; font: inherit; color: var(--text); border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--bg); }

.tabs { display: flex; gap: 4px; padding-bottom: 8px; overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap; }
.tab:hover { background: var(--bg); text-decoration: none; }
.tab.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- Page ---------- */
.page { padding-top: 28px; padding-bottom: 40px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.head-actions { display: flex; align-items: center; gap: 10px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 13px; margin-bottom: -8px; }
.link-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.footer { display: flex; justify-content: space-between; padding: 24px 20px 32px; color: var(--muted); font-size: 12px; }
.footer strong { color: var(--primary); }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.card-head.padded { padding: 20px 20px 0; }
.card-head h2 { margin-bottom: 2px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.span-2 { grid-column: span 2; }

.stat-card { display: flex; flex-direction: column; gap: 2px; }
.stat-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.stat-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.stat-green { background: var(--primary-soft); color: var(--primary); }
.stat-blue { background: var(--blue-soft); color: var(--blue); }
.stat-purple { background: var(--purple-soft); color: var(--purple); }
.stat-amber { background: var(--amber-soft); color: var(--amber); }
.stat-label { text-transform: uppercase; font-size: 11px; letter-spacing: .04em; color: var(--muted); font-weight: 500; display: block; }
.stat-value { font-size: 28px; font-weight: 500; line-height: 1.2; display: block; }
.stat-value small { font-size: 15px; color: var(--muted); }
.small-value { font-size: 18px; font-weight: 600; }
.stat-link { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.stat-link.center { justify-content: center; border-top: 0; padding-top: 0; }
.trend { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.trend-up { background: var(--primary-soft); color: var(--primary); }
.trend-down { background: var(--red-soft); color: var(--red); }

.summary-strip { display: grid; grid-template-columns: repeat(4, 1fr); padding: 0; }
.summary-strip > div { padding: 16px 20px; border-right: 1px solid var(--border); }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip .stat-value { font-size: 22px; }

.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.mini-stats > div { border: 1px solid var(--border); border-radius: 12px; padding: 12px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { color: var(--red); background: var(--red-soft); }
.icon-btn.copied { color: var(--primary); }
.link-danger { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 0 4px; }
.link-danger:hover { color: var(--red); }

/* ---------- Badges / chips / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-published { background: var(--primary-soft); color: var(--primary); }
.badge-draft { background: var(--amber-soft); color: var(--amber); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); }
.chip-muted { background: var(--bg); color: var(--muted); }
.chip-accent { background: var(--purple-soft); color: var(--purple); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); font-size: 12px; font-weight: 500; background: #fff; }
.pill:hover { text-decoration: none; background: var(--bg); }
.pill.active { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.pill-count { font-size: 10px; padding: 0 6px; border-radius: 999px; background: var(--bg); }
.pill.active .pill-count { background: var(--primary); color: #fff; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; font-size: 13px; border: 1px solid transparent; }
.alert-success { background: var(--primary-soft); color: var(--primary); }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-info { background: var(--blue-soft); color: var(--blue); }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--purple-soft); color: #4a3a8c; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.label { font-weight: 600; font-size: 13px; }
.optional { font-weight: 400; color: var(--faint); font-size: 11px; margin-left: 4px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.hint.split { display: flex; justify-content: space-between; gap: 10px; }
.field-error { color: var(--red); font-size: 12px; margin: 0; }
.input { width: 100%; min-height: 40px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font: inherit; color: var(--text); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input:disabled { background: var(--bg); color: var(--faint); }
.input.has-error, .input-prefix.has-error { border-color: var(--red); }
.input-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; width: auto; max-width: 240px; }
textarea.input { resize: vertical; min-height: 96px; }
.input-prefix { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; background: #fff; overflow: hidden; }
.input-prefix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-prefix > span { padding: 0 2px 0 12px; color: var(--muted); white-space: nowrap; }
.input-prefix input { flex: 1; min-width: 0; height: 40px; border: 0; outline: 0; font: 12px var(--mono); padding: 0 12px 0 0; background: transparent; }
.input-prefix.locked { background: var(--bg); justify-content: space-between; height: 40px; padding-right: 12px; color: var(--faint); }

.number-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.number-option { position: relative; display: block; cursor: pointer; }
.number-option input { position: absolute; opacity: 0; }
.number-option .box { display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-height: 72px; }
.number-option .box strong { font-family: var(--mono); font-size: 13px; }
.number-option input:checked + .box { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.number-option input:focus-visible + .box { box-shadow: 0 0 0 3px var(--primary-soft); }
.number-option.disabled { cursor: not-allowed; opacity: .55; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.segment { cursor: pointer; position: relative; }
.segment input { position: absolute; opacity: 0; }
.segment span { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border: 1px solid var(--border); border-radius: 12px; font-size: 12px; font-weight: 500; text-align: center; }
.segment input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.segment input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }
.mode-panel { display: none; margin-top: 6px; }
.mode-panel.active { display: block; }
.mode-panel .note { margin-top: 14px; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Table ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search-field { position: relative; flex: 1; max-width: 320px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px 20px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover { background: #faf9f6; }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 2px; }
.cell-sub.mono { font-size: 11px; color: var(--text); }
.w-num { width: 48px; }
.w-chev { width: 32px; color: var(--faint); }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); }
.pagination { display: flex; align-items: center; gap: 4px; }
.pagination a, .pagination span { min-width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; font-size: 12px; color: var(--text); }
.pagination a:hover { background: var(--bg); text-decoration: none; }
.pagination .current { background: var(--primary); color: #fff; font-weight: 600; }
.pagination .disabled { color: var(--border-strong); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-inline { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

/* ---------- Chart ---------- */
.chart { display: flex; gap: 10px; height: 220px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; font-size: 10px; color: var(--faint); padding-bottom: 22px; text-align: right; min-width: 24px; }
.chart-y span { line-height: 0; }
.chart-plot { position: relative; flex: 1; min-width: 0; }
.chart-grid { position: absolute; inset: 0 0 22px; display: flex; flex-direction: column; justify-content: space-between; }
.chart-grid span { border-top: 1px dashed var(--border); }
.chart-bars { position: absolute; inset: 0; display: flex; gap: 3px; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; min-width: 0; padding-bottom: 22px; position: relative; }
.chart-bar { background: var(--primary); border-radius: 3px 3px 0 0; transition: opacity .15s; }
.chart-col:hover .chart-bar { opacity: .75; }
.chart-x { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--faint); white-space: nowrap; }

/* ---------- Breakdown ---------- */
.breakdown { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.breakdown-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 5px; }
.breakdown-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown-value { font-weight: 600; white-space: nowrap; }
.breakdown-value small { color: var(--faint); font-weight: 400; margin-left: 4px; }
.breakdown-track { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.breakdown-track div { height: 100%; background: var(--primary); border-radius: 3px; }

/* ---------- Dashboard create list ---------- */
.create-list { display: flex; flex-direction: column; gap: 10px; }
.create-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); }
.create-item:hover { text-decoration: none; border-color: var(--primary); }
.create-item > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.create-item small { color: var(--muted); font-size: 12px; }
.create-item > .icon:last-child { color: var(--faint); }

/* ---------- Link page side ---------- */
.share-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg); border-radius: 10px; padding: 6px 6px 6px 12px; margin-top: 12px; }
.qr { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 18px 0; }
.qr img { border: 1px solid var(--border); border-radius: 12px; padding: 8px; background: #fff; }
.preview { margin-top: 12px; background: #efeae2; border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.preview-to { display: flex; align-items: center; gap: 10px; background: #fff; padding: 8px 10px; border-radius: 10px; }
.preview-to > span:last-child { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.bubble { align-self: flex-end; max-width: 90%; background: #d9fdd3; border-radius: 10px 10px 2px 10px; padding: 8px 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); }

/* ---------- Messages page ---------- */
.message-list { list-style: none; margin: 0; padding: 0; }
.message-item { display: flex; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.message-item:last-child { border-bottom: 0; }
.message-item.is-editing { background: var(--primary-soft); }
.message-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.message-body { white-space: normal; word-break: break-word; }
.message-actions { display: flex; gap: 2px; align-items: flex-start; }
.message-actions form { margin: 0; }

/* ---------- Accounts page ---------- */
.narrow { max-width: 420px; }
.account-actions { display: flex; justify-content: flex-end; align-items: flex-start; gap: 6px; }
.account-actions form { margin: 0; }
.inline-panel summary { list-style: none; }
.inline-panel summary::-webkit-details-marker { display: none; }
.inline-panel-body { margin-top: 8px; width: 240px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.inline-panel-body .field { margin-top: 6px; width: 100%; }
.inline-panel-body .btn { margin-top: 10px; }
.menu-item:hover { text-decoration: none; }

/* ---------- Analytics filters ---------- */
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Auth ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; display: flex; flex-direction: column; gap: 6px; }
.auth-brand { margin-bottom: 16px; }
.auth-card h1 { font-size: 22px; }
.auth-card p { margin: 0 0 12px; }
.auth-card .field { margin-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
    .grid-main-side { grid-template-columns: 1fr; }
    .stat-grid, .grid-3, .summary-strip { grid-template-columns: repeat(2, 1fr); }
    .summary-strip > div:nth-child(2) { border-right: 0; }
    .span-2 { grid-column: auto; }
}
@media (max-width: 600px) {
    .topbar-search { display: none; }
    .topbar-inner { justify-content: space-between; }
    .stat-grid, .grid-3, .field-row, .number-options { grid-template-columns: 1fr; }
    .segmented { grid-template-columns: repeat(2, 1fr); }
    .footer { flex-direction: column; gap: 6px; }
}
