:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #126a3a;
  --primary-hover: #0e5730;
  --danger: #b42318;
  --warning: #b54708;
  --success-bg: #ecfdf3;
  --success-text: #027a48;
  --danger-bg: #fef3f2;
  --danger-text: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 20px; font-size: 13px; }

/* ---------- login ---------- */

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; }

/* ---------- layout ---------- */

.app {
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 { margin: 0 0 4px; font-size: 24px; }
.topbar p { margin: 0; }
.topbar-actions { display: flex; gap: 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 4px; }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.toolbar input {
  flex: 1 1 260px;
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
  background: #fff;
  outline: none;
}

.toolbar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18, 106, 58, 0.12); }

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f8f9fb; }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.danger:hover { background: #fee4e2; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- table ---------- */

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
}

.table-wrap.inner { max-height: 280px; margin: 10px 0 14px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8f9fb;
  text-align: left;
  font-weight: 600;
  color: #475467;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid #f2f4f7;
  vertical-align: middle;
}

tr:last-child td { border-bottom: 0; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); }

.org { font-weight: 600; }
.key-cell { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.active { background: var(--success-bg); color: var(--success-text); }
.badge.expired { background: #fffaeb; color: var(--warning); }
.badge.revoked { background: var(--danger-bg); color: var(--danger-text); }

/* ---------- modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--card);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card.wide { width: min(860px, 100%); }
.modal-card h2 { margin: 0; font-size: 19px; }
.modal-card h3 { margin: 4px 0 0; font-size: 15px; }
.modal-card p { margin: 0; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: #344054; }
label span { font-weight: 600; }

input, select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
  outline: none;
}

input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18, 106, 58, 0.12); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

legend { padding: 0 4px; font-size: 12.5px; font-weight: 600; color: #344054; }

label.check {
  flex-direction: row;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text);
}
label.check input { width: auto; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.key-box {
  background: #f8f9fb;
  border: 1px dashed #98a2b3;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}

.key-box code { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }

.payment-form {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 36px));
  background: #1f2328;
  color: #fff;
  border-radius: 9px;
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.3);
}

.toast.error { background: var(--danger); }
.toast.ok { background: var(--primary); }

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .topbar { flex-direction: column; }
  .row { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
  th:nth-child(6), td:nth-child(6) { display: none; }
}
