:root {
  --ink: #1c1915;
  --muted: #6d645b;
  --line: #e4ddd2;
  --paper: #f6f3ee;
  --card: #fffcf8;
  --accent: #9a4d24;
  --accent-ink: #fff8f3;
  --sidebar: #231e1a;
  --sidebar-text: #f3ece4;
  --ok: #1f7a4d;
  --ok-bg: #e5f5ec;
  --bad: #9d2c2c;
  --bad-bg: #fdecec;
  --wait: #8a5a12;
  --wait-bg: #fff4df;
  --info: #1d4f73;
  --info-bg: #e7f1f8;
  --shadow: 0 12px 30px rgba(48, 32, 16, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}
a { color: inherit; }
button, input, select { font: inherit; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, #f3e2d2, transparent 36%),
    var(--paper);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.login-card h1 { margin: 16px 0 6px; font-size: 28px; }
.login-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.45; }
label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 6px; }
input[type="email"], input[type="password"], input[type="search"], select {
  width: 100%;
  border: 1px solid #d9d0c5;
  background: white;
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 14px;
}
button, .btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.secondary, button.secondary { background: #efe8df; color: var(--ink); }
.btn.ghost, button.ghost { background: transparent; color: var(--bad); border: 1px solid #efc8c8; }
.login-card button { width: 100%; margin-top: 4px; }
.error {
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { display: flex; gap: 10px; align-items: center; margin-bottom: 28px; }
.sidebar .brand strong { display: block; }
.sidebar .brand span { color: #c8b8a8; font-size: 12px; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar a {
  text-decoration: none;
  color: #f6efe8;
  padding: 10px 12px;
  border-radius: 10px;
}
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,0.08); }
.sidebar .who { margin-top: 28px; color: #c8b8a8; font-size: 13px; }
.sidebar .who form { margin-top: 10px; }
.sidebar .who button { background: transparent; color: #f6efe8; border: 1px solid rgba(255,255,255,0.16); width: 100%; }

.main { padding: 28px 32px 48px; }
.top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 22px; }
.top h1 { margin: 0; font-size: 30px; letter-spacing: -0.03em; }
.top p { margin: 6px 0 0; color: var(--muted); }
.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.warn { background: var(--wait-bg); color: var(--wait); }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.card { padding: 16px 18px; }
.card span { color: var(--muted); font-size: 13px; }
.card strong { display: block; margin-top: 8px; font-size: 26px; letter-spacing: -0.03em; }
.card em { font-style: normal; color: var(--muted); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 14px; }
.panel { padding: 16px 18px 8px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
th { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
a.rowlink { color: var(--accent); text-decoration: none; font-weight: 650; }

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #eee7de;
  color: #4d453d;
}
.badge.success, .badge.approved { background: var(--ok-bg); color: var(--ok); }
.badge.rejected, .badge.failed { background: var(--bad-bg); color: var(--bad); }
.badge.awaiting_customer, .badge.processing, .badge.sms_required, .badge.pending { background: var(--wait-bg); color: var(--wait); }
.badge.expired, .badge.created { background: var(--info-bg); color: var(--info); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; margin: 0; min-width: 180px; }
.pager { display: flex; justify-content: space-between; align-items: center; color: var(--muted); margin-top: 12px; }
.pager a { color: var(--accent); text-decoration: none; font-weight: 700; }

.detail { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 14px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 12px; }
.kv span { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.note { color: var(--muted); font-size: 13px; line-height: 1.45; }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 8px; align-items: center; font-size: 13px; }
.track { height: 8px; background: #efe8df; border-radius: 99px; overflow: hidden; }
.track i { display: block; height: 100%; background: var(--accent); }

.sidebar { display: flex; flex-direction: column; overflow: auto; }
.sidebar nav { flex: 1; }
.sidebar nav a { font-size: 14px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.panel { overflow-x: auto; }
.editor { margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field { display: block; margin-bottom: 12px; }
.field.wide, .wide { grid-column: 1 / -1; }
.hint { display: block; color: var(--muted); font-weight: 500; font-size: 12px; margin: 2px 0 6px; }
.editor input[type="text"],
.editor input[type="url"],
.editor input[type="number"],
.editor input[type="email"],
.editor input[type="password"],
.editor select,
.editor textarea {
  width: 100%;
  border: 1px solid #d9d0c5;
  background: white;
  border-radius: 10px;
  padding: 11px 12px;
  margin: 6px 0 0;
}
.editor textarea { min-height: 96px; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 4px 0 16px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 650; margin: 0; }
.check input { width: auto; margin: 0; }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #231e1a;
  color: #f6efe8;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
  word-break: break-all;
}
.danger { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.side-search { padding: 0 0 12px; }
.side-search input { width: 100%; margin: 0; background: #2d2723; color: var(--sidebar-text); border-color: #3d352f; }
.filters a.btn { align-self: center; text-decoration: none; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }
.filters input[type="date"] { width: auto; margin: 0; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .sidebar nav { grid-template-columns: repeat(2, 1fr); }
  .cards, .grid-2, .detail, .form-grid { grid-template-columns: 1fr; }
  .main { padding: 18px; }
}
