:root {
  --green: #1B6D24;
  --green-700: #155a1d;
  --green-50: #e6f0e3;
  --canvas: #F1F5EB;
  --card: #ffffff;
  --gold: #C9971C;
  --gold-50: #fbf3df;
  --gold-700: #8a6511;
  --ink: #17231a;
  --ink-2: #4b5a4e;
  --muted: #6f7d72;
  --line: #e1e8da;
  --red: #b3261e;
  --red-50: #fbe9e7;
  --blue: #1f5fa8;
  --blue-50: #e6effa;
  --gray-50: #eef1ec;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 35, 26, .06), 0 4px 16px rgba(23, 35, 26, .05);
  --sidebar: 248px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
a { color: var(--green); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; letter-spacing: .02em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2 { flex: 1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-700); }
.btn-gold { background: var(--gold); color: #fff; }
.btn-gold:hover:not(:disabled) { background: var(--gold-700); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-50); }
.btn-danger { background: #fff; color: var(--red); border-color: #efc4bf; }
.btn-danger:hover:not(:disabled) { background: var(--red-50); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; cursor: pointer;
  display: inline-grid; place-items: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--gray-50); }
svg:not([width]) { max-width: 100%; }
.icon-btn svg, .nav svg { width: 20px; height: 20px; fill: currentColor; }
:focus-visible { outline: 3px solid rgba(27, 109, 36, .35); outline-offset: 2px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; color: var(--ink-2); font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  padding: 9px 12px; min-height: 40px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); outline: 3px solid rgba(27, 109, 36, .15); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form-error { color: var(--red); margin: 8px 0 0; min-height: 0; font-size: 13px; }
.form-error:empty { display: none; }
.search {
  position: relative; flex: 1; min-width: 200px; max-width: 420px;
}
.search input { padding-left: 36px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 18px; height: 18px; fill: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; padding: 28px; }
.login-card .brand { margin-bottom: 24px; }
.otp-input { font-size: 22px; letter-spacing: 8px; text-align: center; font-weight: 600; }

/* Brand */
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; background: var(--green); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none;
  box-shadow: inset 0 -3px 0 var(--gold);
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.brand-lg .logo { width: 48px; height: 48px; font-size: 17px; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: #fff; border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 24px;
}
.sidebar .brand { padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--gray-50); }
.nav a.active { background: var(--green-50); color: var(--green); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }
.admin-email { font-size: 12px; color: var(--muted); word-break: break-all; }
.content { padding: 28px 32px 48px; min-width: 0; outline: none; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { flex: 1; }
.page-sub { color: var(--muted); margin-top: 4px; }
.grid { display: grid; gap: 16px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat-foot { font-size: 12px; color: var(--ink-2); display: flex; gap: 10px; flex-wrap: wrap; }
.stat.license { border-top: 4px solid var(--gold); }
.stat.license .stat-value { color: var(--gold-700); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8faf5; }
td .sub { font-size: 12px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--gray-50); color: var(--ink-2);
}
.badge.green { background: var(--green-50); color: var(--green); }
.badge.gold { background: var(--gold-50); color: var(--gold-700); }
.badge.red { background: var(--red-50); color: var(--red); }
.badge.blue { background: var(--blue-50); color: var(--blue); }

/* Empty / loading */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; fill: #c9d4c3; display: block; margin: 0 auto 10px; }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 4px; }
.loading { padding: 28px; text-align: center; color: var(--muted); }
.error-box { background: var(--red-50); color: var(--red); border-radius: var(--radius-sm); padding: 12px 14px; }

/* Codes generator */
.codes-result { border: 1px dashed var(--gold); background: var(--gold-50); border-radius: 12px; padding: 16px; margin-top: 16px; }
.codes-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 16px;
  max-height: 260px; overflow: auto; margin: 12px 0; padding: 12px; background: #fff; border-radius: 10px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select { width: auto; min-width: 150px; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 25, 17, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  background: var(--canvas); z-index: 50; transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(0, 0, 0, .12);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.drawer-head h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.section-title { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.section-title h3 { flex: 1; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.lic {
  border: 1px solid #ecdcb2; border-left: 4px solid var(--gold); background: #fffdf7;
  border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.lic + .lic { margin-top: 10px; }
.lic.inactive { border-color: var(--line); border-left-color: #c8d0c4; background: #fafbf8; }
.lic-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lic-title { font-weight: 700; color: var(--gold-700); }
.lic.inactive .lic-title { color: var(--ink-2); }
.lic-meta { font-size: 12px; color: var(--ink-2); display: flex; gap: 4px 14px; flex-wrap: wrap; }
.item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item > svg { width: 22px; height: 22px; flex: none; fill: var(--primary, #1B6D24); }
.item-main { flex: 1; min-width: 0; }
.item-main .sub { font-size: 12px; color: var(--muted); word-break: break-all; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.timeline .sub { color: var(--muted); font-size: 12px; }

/* Dialog */
.dialog {
  border: 0; border-radius: var(--radius); padding: 0; width: min(440px, calc(100% - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .2); color: var(--ink);
}
.dialog::backdrop { background: rgba(15, 25, 17, .4); }
.dialog form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog p { margin: 0; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toasts */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100% - 32px); max-width: 420px; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; pointer-events: auto; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }

/* Phones: single column */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; height: auto; z-index: 20; flex-direction: column; gap: 10px;
    padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar .brand-sub { display: none; }
  .sidebar .logo { width: 34px; height: 34px; font-size: 13px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; margin: 0 -4px; padding: 0 4px; scrollbar-width: none; }
  .nav a { padding: 8px 12px; flex: none; }
  .nav a svg { width: 18px; height: 18px; }
  .sidebar-foot { position: absolute; top: 12px; right: 12px; flex-direction: row; align-items: center; padding: 0; margin: 0; }
  .admin-email { display: none; }
  .content { padding: 18px 16px 40px; }
  h1 { font-size: 20px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-value { font-size: 22px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 6px; }
  .hide-sm { display: none; }
  .search { max-width: none; }
}
