:root {
  --bg: #0b0d12;
  --panel: #12151d;
  --panel-2: #181c26;
  --panel-3: #1f2430;
  --border: #242a37;
  --border-strong: #303748;
  --text: #e7eaf0;
  --muted: #8a92a6;
  --faint: #5d6579;
  --accent: #8b6cff;
  --accent-2: #4fd1ff;
  --accent-soft: rgba(139, 108, 255, 0.14);
  --success: #3ecf8e;
  --danger: #ff5f6d;
  --warning: #ffb547;
  --info: #4fa8ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-3); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
[hidden] { display: none !important; }

/* ── layout ── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: none; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 20px 20px 18px; border-bottom: 1px solid var(--border); }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
#nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); padding: 14px 12px 6px; }
#nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; text-decoration: none; transition: background 0.15s, color 0.15s;
}
#nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: 0.85; }
#nav a:hover { background: var(--panel-2); color: var(--text); }
#nav a.active { background: var(--accent-soft); color: #fff; }
#nav a.active svg { color: var(--accent); opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.18); }
.dot.off { background: var(--danger); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 64px; display: flex; align-items: center; gap: 14px; padding: 0 32px; border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
#menu { display: none; }
.content { padding: 28px 32px 60px; max-width: 1400px; width: 100%; }
.page { display: flex; flex-direction: column; gap: 20px; }

/* ── components ── */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card > header h2 { font-size: 15px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat span { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.stat strong { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; }
.stat.accent { background: linear-gradient(135deg, rgba(139, 108, 255, 0.18), rgba(79, 209, 255, 0.08)); border-color: rgba(139, 108, 255, 0.35); }
.stat small { display: block; color: var(--faint); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; transition: background 0.15s, border-color 0.15s, opacity 0.15s; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #7a58ff; }
.btn.danger { background: rgba(255, 95, 109, 0.12); border-color: rgba(255, 95, 109, 0.4); color: #ff8f99; }
.btn.danger:hover { background: rgba(255, 95, 109, 0.22); }
.btn.success { background: rgba(62, 207, 142, 0.12); border-color: rgba(62, 207, 142, 0.4); color: #6fe3ae; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

input[type="text"], input[type="search"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 11px; font: inherit; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { cursor: pointer; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar input[type="search"] { max-width: 260px; }
.toolbar select { max-width: 220px; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 550; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel-3); color: #fff; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.card .table-wrap { border: 0; border-radius: 0; background: transparent; margin: 0 -20px -20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; background: var(--panel); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--panel-2); }
td.wrap { white-space: normal; min-width: 220px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-3); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.open, .badge.paid { background: rgba(62, 207, 142, 0.12); color: var(--success); }
.badge.closed, .badge.closing, .badge.cancelled { background: rgba(138, 146, 166, 0.14); color: #b4bbcc; }
.badge.archived, .badge.pending { background: rgba(255, 181, 71, 0.12); color: var(--warning); }
.badge.deleted, .badge.deleting, .badge.failed { background: rgba(255, 95, 109, 0.12); color: var(--danger); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--panel-3); color: var(--muted); font-size: 12px; }

.user { display: inline-flex; align-items: center; gap: 8px; }
.user img, .avatar-fallback { width: 24px; height: 24px; border-radius: 50%; flex: none; }
.avatar-fallback { display: inline-flex; align-items: center; justify-content: center; background: var(--panel-3); color: var(--muted); font-size: 11px; font-weight: 700; }

.activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.activity li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity time { margin-left: auto; color: var(--faint); font-size: 12.5px; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 48px 0; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { border-radius: var(--radius-sm); padding: 12px 14px; border: 1px solid; font-size: 13.5px; }
.alert.error { background: rgba(255, 95, 109, 0.08); border-color: rgba(255, 95, 109, 0.35); color: #ffb3ba; }
.alert.info { background: rgba(79, 168, 255, 0.08); border-color: rgba(79, 168, 255, 0.3); color: #b8dbff; }
.alert.warn { background: rgba(255, 181, 71, 0.08); border-color: rgba(255, 181, 71, 0.3); color: #ffd79a; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px 0; color: var(--muted); }

/* ── forms ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label { font-size: 13px; font-weight: 550; color: #c9cedb; display: flex; align-items: center; gap: 8px; }
.field small { color: var(--faint); font-size: 12px; }
.color-input { display: flex; gap: 8px; }
.color-input input[type="color"] { width: 42px; height: 37px; flex: none; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--panel-2); cursor: pointer; }
.checklist { max-height: 190px; overflow-y: auto; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--panel-2); padding: 6px; display: flex; flex-direction: column; gap: 1px; }
.checklist label { display: flex; align-items: center; gap: 9px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.checklist label:hover { background: var(--panel-3); }
.checklist .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.checklist .none { color: var(--faint); padding: 6px 8px; font-size: 13px; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--panel-3); border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #9aa1b3; border-radius: 50%; transition: transform 0.15s, background 0.15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-error { color: #ff8f99; font-size: 13px; margin: 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 22px 0 12px; }
.question { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; background: var(--panel-2); margin-bottom: 10px; }
.question header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--muted); font-weight: 600; font-size: 13px; }
.inline-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c9cedb; padding-top: 26px; }

.msg-item { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.msg-item:last-child { border-bottom: 0; }
.msg-item code { background: none; padding: 0; color: var(--muted); word-break: break-all; }
.msg-item textarea { min-height: 42px; }
.msg-item.dirty textarea { border-color: var(--warning); }
.sticky-bar { position: sticky; bottom: 16px; display: flex; justify-content: flex-end; pointer-events: none; }
.sticky-bar .btn { pointer-events: auto; box-shadow: var(--shadow); }

.panel-card { display: flex; flex-direction: column; gap: 12px; }
.panel-card .meta { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.panel-card .meta b { color: var(--text); font-weight: 550; }
.panel-card h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.bar { height: 6px; border-radius: 999px; background: var(--panel-3); overflow: hidden; min-width: 120px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: inherit; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.answers { display: flex; flex-direction: column; gap: 10px; }
.answers div { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.answers b { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.answers p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--faint); margin-left: auto; white-space: nowrap; }

/* ── modal & toasts ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(5, 6, 10, 0.68); backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; overflow-y: auto; animation: fade 0.15s ease; }
.modal { width: 100%; max-width: 560px; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow); animation: rise 0.18s ease; }
.modal.wide { max-width: 920px; }
.modal > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal > header h2 { font-size: 16px; }
.modal .body { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.modal > footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { min-width: 260px; max-width: 420px; background: var(--panel-2); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow); animation: rise 0.18s ease; font-size: 13.5px; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

/* ── login & payment pages ── */
.login-page, .paypage { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(139, 108, 255, 0.16), transparent), radial-gradient(900px 500px at 110% 110%, rgba(79, 209, 255, 0.1), transparent), var(--bg); }
.login-card, .paycard { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand strong { display: block; font-size: 16px; }
.login-brand span { color: var(--muted); font-size: 12.5px; }
.login-card h1 { font-size: 20px; margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 8px; }
.login-card label { font-size: 13px; font-weight: 550; color: #c9cedb; margin-top: 6px; }
.login-card .btn { margin-top: 14px; height: 40px; }
.login-foot { color: var(--faint); font-size: 12.5px; margin: 20px 0 0; }
.paycard { text-align: center; }
.paycard h1 { font-size: 20px; margin: 14px 0 8px; }
.paycard p { color: var(--muted); margin: 0; }

/* ── responsive ── */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 25; }
  #menu { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 48px; }
  .grid.two { grid-template-columns: 1fr; }
  .msg-item { grid-template-columns: 1fr; gap: 8px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .toolbar input[type="search"], .toolbar select { max-width: none; flex: 1 1 160px; }
}
