:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #0f6e63;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok-bg: #e7f6ef;
  --ok-text: #0b5c3b;
  --err-bg: #fdecea;
  --err-text: #8a1c12;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2b333e;
    --accent: #3cb8a6;
    --accent-text: #0b1b18;
    --danger: #f2766b;
    --ok-bg: #12332a;
    --ok-text: #8fe0bd;
    --err-bg: #3a1714;
    --err-text: #f8b4ad;
    --warn-bg: #3a2c10;
    --warn-text: #f5cf87;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { font-weight: 700; font-size: 18px; padding: 0 10px 16px; display: block; color: var(--text); text-decoration: none; }
.sidebar nav a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--accent); color: var(--accent-text); }
.sidebar .group { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 10px 4px; }
.sidebar .me { margin-top: 24px; padding: 0 10px; font-size: 13px; color: var(--muted); }

main { padding: 24px 32px; width: 100%; min-width: 0; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; justify-content: space-between; margin-bottom: 16px; }
.toolbar form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .name { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.field .error { font-size: 13px; color: var(--danger); margin-top: 4px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
input[type="file"] { padding: 6px; cursor: pointer; }
input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
details > summary { cursor: pointer; margin: 6px 0; }
.image-field .thumb { display: block; margin-bottom: 8px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; }

button, .btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn.secondary, button.secondary { background: transparent; color: var(--accent); }
.btn.danger, button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); border: 1px solid var(--border); white-space: nowrap; }
.badge.paid, .badge.active, .badge.published, .badge.confirmed, .badge.delivered, .badge.approved { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge.pending_payment, .badge.processing, .badge.pending, .badge.draft, .badge.low { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge.cancelled, .badge.refunded, .badge.archived, .badge.unsubscribed, .badge.bounced, .badge.rejected, .badge.inactive { background: var(--err-bg); color: var(--err-text); border-color: transparent; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); }
.thumb.lg { width: 96px; height: 96px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 14px; }

.login { max-width: 380px; margin: 12vh auto; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar .group { display: none; }
  main { padding: 16px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

.htmx-request.loading-row { opacity: .6; }
