:root {
  color: #17233b;
  background: #f4f6f9;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --ink: #17233b;
  --muted: #69758a;
  --line: #e2e7ef;
  --paper: #ffffff;
  --blue: #2864dc;
  --blue-dark: #174cad;
  --navy: #101b31;
  --danger: #c73645;
  --green: #127a57;
  --shadow: 0 16px 44px rgba(25, 42, 71, .08);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #f4f6f9; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    radial-gradient(circle at 15% 15%, rgba(63, 119, 230, .22), transparent 30%),
    radial-gradient(circle at 85% 80%, rgba(30, 162, 124, .12), transparent 28%),
    var(--navy);
}

.auth-card {
  width: min(460px, 100%);
  padding: 38px;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .28);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; margin-bottom: 42px; }
.brand-lockup.compact { margin-bottom: 40px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; color: white; background: linear-gradient(145deg, #3975e8, #173f9e);
  font-weight: 800; font-size: 22px;
}
.brand-lockup strong, .brand-lockup small { display: block; }
.brand-lockup strong { letter-spacing: .09em; }
.brand-lockup small { color: var(--muted); margin-top: 2px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(25px, 4vw, 34px); letter-spacing: -.035em; }
h2 { margin-bottom: 8px; font-size: 20px; letter-spacing: -.02em; }
.eyebrow {
  margin-bottom: 8px; color: var(--blue); font-size: 12px; font-weight: 750;
  letter-spacing: .12em; text-transform: uppercase;
}
.muted { color: var(--muted); line-height: 1.65; }

button {
  min-height: 42px; padding: 10px 16px; border: 0; border-radius: 10px;
  font-weight: 650; transition: .16s ease;
}
button:disabled { opacity: .55; cursor: wait; }
.primary { color: white; background: var(--blue); }
.primary:hover { background: var(--blue-dark); transform: translateY(-1px); }
.secondary { color: var(--ink); background: white; border: 1px solid var(--line); }
.secondary:hover { border-color: #bdc7d6; }
.danger { color: var(--danger); background: #fff0f2; }
.text-button { padding: 6px 0; color: var(--blue); background: transparent; }
.wide { width: 100%; margin-top: 16px; }
.icon-button { min-width: 36px; padding: 4px; font-size: 23px; background: #eef1f6; }

label { display: grid; gap: 7px; color: #37445a; font-size: 13px; font-weight: 650; }
input, select, textarea {
  width: 100%; padding: 11px 12px; color: var(--ink); background: white;
  border: 1px solid #ccd4e0; border-radius: 9px; outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(40, 100, 220, .12);
}
textarea { resize: vertical; line-height: 1.5; }
.check { grid-template-columns: auto 1fr; align-items: center; font-weight: 500; }
.check input { width: 17px; height: 17px; }

.qr { width: 220px; height: 220px; margin: 10px auto; display: block; border-radius: 12px; }
.secret { overflow-wrap: anywhere; color: var(--muted); font-size: 13px; }
.secret code { color: var(--ink); }

.portal { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; padding: 28px 22px;
  display: flex; flex-direction: column; color: white; background: var(--navy);
}
.sidebar .brand-lockup small { color: #9daac1; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { padding: 11px 14px; text-align: left; color: #b8c3d6; background: transparent; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255, 255, 255, .1); }
.sidebar-user { margin-top: auto; display: grid; gap: 5px; padding: 16px 10px 2px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-user span { color: #9daac1; font-size: 12px; overflow-wrap: anywhere; }
.sidebar-user .text-button { justify-self: start; color: #b9ceff; }

.workspace { grid-column: 2; min-width: 0; padding: 38px clamp(24px, 4vw, 58px) 70px; }
.workspace-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.workspace-header h1 { margin: 0; }
.view { display: grid; gap: 20px; }
.card {
  padding: 24px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--paper); box-shadow: var(--shadow);
}
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.card-heading h2 { margin-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
  min-height: 126px; padding: 22px; display: flex; flex-direction: column;
  justify-content: space-between; border: 1px solid var(--line); border-radius: 16px;
  background: white; box-shadow: var(--shadow);
}
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { font-size: 34px; }
.start-card { display: flex; justify-content: space-between; align-items: center; gap: 30px; }
.start-card p { margin-bottom: 0; }
.safety-card ul { margin: 14px 0 0; padding-left: 20px; color: var(--muted); line-height: 1.9; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.search { max-width: 240px; }

.table-card { padding: 0; overflow: hidden; }
.table-card .card-heading { padding: 24px 24px 0; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 16px; text-align: left; border-top: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); background: #fafbfd; font-size: 12px; font-weight: 700; white-space: nowrap; }
td { color: #334057; }
td.actions { display: flex; gap: 7px; white-space: nowrap; }
td.actions button { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.empty { padding: 38px 20px; text-align: center; color: var(--muted); }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.active, .badge.sent, .badge.paid { color: #116246; background: #e7f7f1; }
.badge.revoked, .badge.failed, .badge.expired { color: #a52d3a; background: #fdecee; }
.badge.open, .badge.new { color: #8d5b08; background: #fff3d8; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-list { display: grid; gap: 10px; }
.detail-row { padding: 13px; border: 1px solid var(--line); border-radius: 10px; }
.detail-row p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.inline-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-actions input { width: 100px; }

.toast {
  position: fixed; z-index: 20; top: 18px; right: 18px; max-width: 390px;
  padding: 13px 16px; color: white; background: var(--ink); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.2); opacity: 0; transform: translateY(-12px);
  pointer-events: none; transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #9b2533; }

dialog { width: min(680px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 30px 90px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(11, 20, 37, .62); backdrop-filter: blur(4px); }
.dialog-card { padding: 26px; }
.codes { max-height: 360px; overflow: auto; display: grid; gap: 10px; }
.code-item { padding: 13px; border: 1px solid var(--line); border-radius: 10px; }
.code-item strong, .code-item code { display: block; }
.code-item code { margin-top: 6px; overflow-wrap: anywhere; color: var(--blue-dark); }

@media (max-width: 980px) {
  .portal { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { width: 76px; padding: 24px 11px; }
  .sidebar .brand-lockup div, .sidebar-user, .nav-item { font-size: 0; }
  .sidebar .brand-lockup { justify-content: center; }
  .nav-item { text-align: center; }
  .nav-item::first-letter { font-size: 16px; }
  .workspace { grid-column: 2; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .portal { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px 16px; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar .brand-lockup { margin: 0 12px 0 0; }
  .sidebar nav { display: flex; gap: 4px; }
  .nav-item { white-space: nowrap; }
  .workspace { padding: 24px 15px 50px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { min-height: 105px; padding: 17px; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .start-card { align-items: flex-start; flex-direction: column; }
  .workspace-header { align-items: flex-end; }
  .auth-shell { padding: 16px; }
  .auth-card { padding: 28px 22px; }
}
