:root {
  --bg: #0f1419;
  --surface: #1a2129;
  --surface-2: #232c36;
  --border: #2e3a47;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #2f81f7;
  --accent-hover: #1f6feb;
  --green: #2ea043;
  --red: #f85149;
  --amber: #d29922;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #57606a;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --green: #1a7f37;
  --red: #cf222e;
  --amber: #9a6700;
}
[data-theme="light"] .portal-wrap {
  background: radial-gradient(circle at top, #dce8f5, var(--bg));
}
[data-theme="light"] .portal-card { box-shadow: 0 12px 40px rgba(0,0,0,.08); }
[data-theme="light"] .terminal { background: #f0f2f5; }
[data-theme="light"] .pill.online,[data-theme="light"] .pill.done,
[data-theme="light"] .pill.sent,[data-theme="light"] .pill.active
  { background: rgba(26,127,55,.1); color: #1a7f37; }
[data-theme="light"] .pill.offline,[data-theme="light"] .pill.failed,
[data-theme="light"] .pill.critical,[data-theme="light"] .pill.expired
  { background: rgba(207,34,46,.1); color: #cf222e; }
[data-theme="light"] .pill.pending,[data-theme="light"] .pill.issued,
[data-theme="light"] .pill.warning,[data-theme="light"] .pill.in_progress
  { background: rgba(154,103,0,.1); color: #9a6700; }
[data-theme="light"] .flash.success { background: #dafbe1; color: #1a7f37; border-color: #a8e6ae; }
[data-theme="light"] .flash.error { background: #ffebe9; color: #cf222e; border-color: #ffcecb; }

* { box-sizing: border-box; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.5; font-size: 15px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Portal (centered card) ---------- */
.portal-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(circle at top, #1a2530, var(--bg));
}
.portal-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.portal-card h1 { font-size: 22px; margin: 0 0 4px; }
.portal-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 15px; font-family: var(--font);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.btn {
  display: inline-block; padding: 12px 18px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); font-size: 15px; font-weight: 600;
  cursor: pointer; width: 100%; transition: background .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface-2); border: 1px solid var(--border); }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; }
.btn.danger { background: var(--red); }

.pkg-list { display: grid; gap: 10px; margin-bottom: 16px; }
.pkg {
  display: flex; justify-content: space-between; align-items: center; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; background: var(--surface-2);
}
.pkg input { width: auto; }
.pkg.selected { border-color: var(--accent); }
.pkg .price { font-weight: 700; }

.flash { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.flash.success { background: rgba(46,160,67,.15); color: #7ee787; border: 1px solid rgba(46,160,67,.4); }
.flash.error { background: rgba(248,81,73,.12); color: #ff7b72; border: 1px solid rgba(248,81,73,.4); }

.code-display { font-size: 30px; letter-spacing: 4px; font-weight: 700; text-align: center;
  padding: 18px; background: var(--surface-2); border-radius: var(--radius); margin: 16px 0; }

/* ---------- Admin layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 0; flex-shrink: 0;
}
.sidebar .brand { font-weight: 700; font-size: 18px; padding: 0 20px 20px; }
.sidebar nav a {
  display: flex; justify-content: space-between; padding: 10px 20px; color: var(--muted);
}
.sidebar nav a:hover, .sidebar nav a.active { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar .badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.main { flex: 1; padding: 28px 32px; max-width: 100%; overflow-x: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .user { color: var(--muted); font-size: 14px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 28px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: none; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.online, .pill.done, .pill.sent, .pill.active { background: rgba(46,160,67,.18); color: #7ee787; }
.pill.offline, .pill.failed, .pill.critical, .pill.expired { background: rgba(248,81,73,.15); color: #ff7b72; }
.pill.pending, .pill.issued, .pill.warning, .pill.in_progress { background: rgba(210,153,34,.18); color: #e3b341; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 28px 0 14px; }
.section-head h2 { font-size: 17px; margin: 0; }

.terminal {
  background: #0a0e13; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; font-family: ui-monospace, Menlo, monospace; font-size: 13px;
  height: 420px; overflow-y: auto; white-space: pre-wrap;
}
.terminal .cmd { color: #58a6ff; }
.terminal .out { color: #8b98a5; }
.terminal .meta { color: #444c56; font-size: 11px; }

.modal-inline { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, monospace; }
.right { text-align: right; }

/* ---------- Hamburger toggle (hidden on desktop) ---------- */
.nav-toggle {
  display: none; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); padding: 6px 11px;
  font-size: 18px; cursor: pointer; line-height: 1; flex-shrink: 0;
}

/* ---------- Sidebar overlay backdrop ---------- */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 98;
}
.sidebar-overlay.open { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  /* Hamburger visible */
  .nav-toggle { display: block; }

  /* Sidebar: hidden off-screen, slides in */
  .sidebar {
    position: fixed; top: 0; left: -240px; height: 100vh; z-index: 99;
    width: 230px !important; transition: left .25s ease;
    overflow-y: auto; box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .sidebar.open { left: 0; }
  /* Always show brand + labels when open on mobile */
  .sidebar .brand { display: block !important; }
  .sidebar nav a span:first-child { display: inline !important; }

  /* Main area fills full width */
  .main { padding: 14px 12px; }

  /* Topbar: wrap so heading + controls stack if needed */
  .topbar { flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
  .topbar h1 { font-size: 17px; flex: 1; min-width: 0; }
  .topbar .user { font-size: 13px; }
  .topbar .user button { padding: 4px 9px; font-size: 12px; }

  /* Cards */
  .cards { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
  .card .value { font-size: 22px; }

  /* Tables: horizontal scroll */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  td, th { white-space: nowrap; }

  /* section head */
  .section-head { flex-wrap: wrap; gap: 6px; margin: 18px 0 10px; }

  /* Two-col form grids stack */
  .grid-2 { grid-template-columns: 1fr; }

  /* Modal / inline forms */
  .modal-inline { padding: 14px; }

  /* Terminal */
  .terminal { height: 280px; font-size: 12px; }

  /* Portal card */
  .portal-card { padding: 22px 18px; }
  .portal-wrap { padding: 16px; align-items: flex-start; padding-top: 40px; }
  .code-display { font-size: 22px; letter-spacing: 2px; }
}

@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .topbar .user { width: 100%; justify-content: flex-end; }
}
