:root {
  --navy: #00578C;
  --blue: #0899CC;
  --light-blue: #66ADE0;
  --ink: #1E1E1E;
  --ink-muted: #5C6672;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E1E6EC;
  --success: #1E9E5A;
  --error: #D6353D;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;

  --adm-sidebar: #0A2540;
  --adm-sidebar2: #0E3157;
  --adm-sidebar-line: #193E63;
  --adm-text-dim: #9FB3C8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth (login) ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--adm-sidebar) 0%, var(--navy) 100%);
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 60px -20px rgba(0, 30, 60, 0.45);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}
.auth-card__logo { display: block; height: 32px; margin: 0 auto 28px; }
.auth-card h1 { font-size: 20px; font-weight: 700; text-align: center; margin: 0 0 4px; }
.auth-card__subtitle { text-align: center; color: var(--ink-muted); font-size: 14px; margin: 0 0 28px; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 14px; font-size: 15px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--ink); font-family: inherit;
}
.field input:focus {
  outline: none; border-color: var(--blue); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(8, 153, 204, 0.15);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 8px; font-size: 14.5px; font-weight: 600;
  padding: 11px 20px; cursor: pointer; font-family: inherit;
}
.btn--primary { background: var(--navy); color: #fff; }
.btn--primary:hover { background: #004472; }
.btn--primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; color: var(--navy); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--bg); }
.btn--danger { background: transparent; color: var(--error); }
.btn--danger:hover { background: rgba(214, 53, 61, 0.08); }
.btn--sm { padding: 7px 13px; font-size: 12.5px; }

.form-error {
  background: rgba(214, 53, 61, 0.08); color: var(--error); border: 1px solid rgba(214, 53, 61, 0.25);
  border-radius: 8px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 18px; display: none;
}
.form-error.visible { display: block; }
.form-ok {
  background: rgba(30, 158, 90, 0.08); color: var(--success); border: 1px solid rgba(30, 158, 90, 0.25);
  border-radius: 8px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 18px; display: none;
}
.form-ok.visible { display: block; }

/* ---------- Admin shell (sidebar) ---------- */
.admwrap { display: flex; min-height: 100vh; }
.adm-side {
  width: 220px; flex: none; background: var(--adm-sidebar); color: var(--adm-text-dim);
  padding: 18px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.adm-brand {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px 18px;
  border-bottom: 1px solid var(--adm-sidebar-line); margin-bottom: 14px;
}
.adm-brand img { height: 22px; }
.adm-brand__text { line-height: 1.25; }
.adm-brand__text b { display: block; color: #fff; font-size: 13px; font-weight: 800; letter-spacing: -0.01em; }
.adm-brand__text span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--blue); font-weight: 700; }

.adm-nav { display: flex; flex-direction: column; gap: 2px; }
.adm-navbtn {
  appearance: none; text-align: left; background: transparent; border: none; color: var(--adm-text-dim);
  font-family: var(--font); font-size: 13px; font-weight: 600; padding: 9px 12px; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; gap: 10px; text-decoration: none;
}
.adm-navbtn .ico { width: 16px; text-align: center; opacity: 0.85; }
.adm-navbtn:hover { background: var(--adm-sidebar2); color: #fff; }
.adm-navbtn.active { background: var(--blue); color: #fff; }
.adm-side__foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--adm-sidebar-line); font-size: 11.5px; color: var(--adm-text-dim); }
.adm-side__foot b { color: #fff; }
.adm-side__signout { color: var(--adm-text-dim); font-size: 11.5px; cursor: pointer; background: none; border: none; font-family: inherit; padding: 0; margin-top: 6px; text-decoration: underline; }

.adm-main { flex: 1; padding: 28px 32px 60px; min-width: 0; }
.adm-h1 { font-size: 20px; font-weight: 800; margin: 0 0 3px; color: var(--ink); }
.adm-sub { font-size: 13.5px; color: var(--ink-muted); margin: 0 0 22px; }

.admsub { display: none; }
.admsub.active { display: block; }

/* ---------- Stat cards / charts ---------- */
.stat4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.statcard { background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 16px 18px; }
.statcard__label { font-size: 11px; color: var(--ink-muted); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 8px; }
.statcard__val { font-size: 23px; font-weight: 800; font-variant-numeric: tabular-nums; }
.statcard__delta { font-size: 11.5px; color: var(--success); font-weight: 700; margin-top: 4px; }
.statcard__delta.down { color: var(--error); }

.chartcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; margin-bottom: 22px; }
.chartcard__title { font-size: 13.5px; font-weight: 800; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: baseline; }
.chartcard__title span { font-size: 12px; font-weight: 600; color: var(--ink-muted); }
.bars { display: flex; align-items: flex-end; gap: 12px; height: 120px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--blue), var(--navy)); border-radius: 5px 5px 0 0; position: relative; min-height: 2px; }
.bars .bar span { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: 10.5px; color: var(--ink-muted); }
.bars .bar.hi { background: linear-gradient(180deg, var(--light-blue), var(--blue)); }

.sectiontitle { font-size: 15px; font-weight: 800; margin: 30px 0 14px; }

/* ---------- Tables ---------- */
.tablewrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tablewrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tablewrap th {
  text-align: left; font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-muted);
  padding: 11px 18px; border-bottom: 1px solid var(--border); font-weight: 700;
}
.tablewrap td { padding: 12px 18px; border-bottom: 1px solid var(--border); color: var(--ink); }
.tablewrap tr:last-child td { border-bottom: none; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.pill.active, .pill.paid { color: var(--success); background: rgba(30, 158, 90, 0.1); }
.pill.past_due, .pill.failed { color: #B7791F; background: rgba(183, 121, 31, 0.12); }
.pill.cancelled, .pill.refunded { color: var(--ink-muted); background: var(--border); }

.admbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.searchbox {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px;
  font-size: 13px; color: var(--ink); width: 240px; font-family: inherit;
}
select.inlineselect {
  font-family: inherit; font-size: 12.5px; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; background: var(--surface); color: var(--ink);
}

/* ---------- Package cards ---------- */
.pkggrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.pkgcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.pkgcard__top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.pkgcard__name { font-size: 14.5px; font-weight: 800; }
.pkgcard__subs { font-size: 11px; color: var(--ink-muted); background: var(--bg); border: 1px solid var(--border); padding: 2px 8px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.pkgcard__price { font-size: 22px; font-weight: 800; margin: 6px 0; }
.pkgcard__price span { font-size: 12px; color: var(--ink-muted); font-weight: 600; }
.pkgcard__row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 6px 0; border-top: 1px solid var(--border); color: var(--ink-muted); }
.pkgcard__row b { color: var(--ink); font-weight: 700; }
.pkgcard .btn { width: 100%; margin-top: 12px; }
.pkgcard.inactive { opacity: 0.55; }
.pkgcard.new { display: flex; align-items: center; justify-content: center; flex-direction: column; border-style: dashed; color: var(--ink-muted); gap: 8px; cursor: pointer; background: transparent; }
.pkgcard.new .plus { width: 34px; height: 34px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 18px; color: var(--blue); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 35, 0.5); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.visible { display: flex; }
.modal {
  background: var(--surface); border-radius: 14px; padding: 26px 28px; width: 100%; max-width: 420px;
  box-shadow: 0 30px 70px -20px rgba(0,0,0,0.4);
}
.modal h3 { margin: 0 0 18px; font-size: 16px; font-weight: 800; }
.modal .field input, .modal .field select {
  width: 100%; padding: 10px 13px; font-size: 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--ink); font-family: inherit;
}
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease; z-index: 200;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

@media (max-width: 980px) {
  .stat4 { grid-template-columns: repeat(2, 1fr); }
  .pkggrid { grid-template-columns: 1fr; }
}
