/* Cashier POS licence admin - rebuilt mobile-first.
   The panel is used far more from a phone than a desktop, so phone layout is
   the base and wider screens are the enhancement. Notably there are no
   horizontally scrolling tables: subscriber records render as cards, which is
   what made the old table unusable on a narrow screen. */

:root {
  --navy: #102a43;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --ink: #14213d;
  --muted: #64748b;
  --line: #e4e9f0;
  --bg: #f5f7fa;
  --card: #fff;
  --danger: #c8323f;
  --danger-bg: #fdeaec;
  --ok: #12805c;
  --ok-bg: #e6f6ef;
  --warn: #9a5b12;
  --warn-bg: #fdf2e3;
  --radius: 14px;
  --shadow: 0 1px 2px #102a430d, 0 8px 24px #102a430a;
  --tap: 44px; /* minimum comfortable touch target */
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }

/* ---------- login ---------- */
.login-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #e8f0ff, var(--bg));
}
.login-card {
  width: min(100%, 380px);
  padding: 28px 24px;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { margin: 14px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-inline: auto;
  border-radius: 13px;
  color: #fff;
  background: var(--navy);
  font-size: 22px;
  font-weight: 800;
}

/* ---------- form controls ---------- */
label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  font-weight: 400;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
  border-color: var(--blue);
}
.field-hint { margin: -8px 0 14px; color: var(--muted); font-size: 12px; font-weight: 400; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.button:active { transform: translateY(1px); }
.button.primary { border-color: var(--blue); background: var(--blue); color: #fff; }
.button.primary:hover { background: var(--blue-dark); }
.button.danger { border-color: #f0c7cc; color: var(--danger); }
.button.block { width: 100%; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.link-button {
  border: 0;
  padding: 6px 2px;
  background: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.error { min-height: 20px; margin-top: 10px; color: var(--danger); font-size: 13px; }

/* ---------- app shell ---------- */
.app-shell { min-height: 100svh; padding-bottom: calc(66px + env(safe-area-inset-bottom)); }

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #fff;
  background: var(--navy);
}
.appbar .brand-mark { width: 34px; height: 34px; margin: 0; font-size: 17px; background: #ffffff1f; }
.appbar h1 { flex: 1; font-size: 17px; font-weight: 700; }
.appbar .icon-button {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 11px;
  background: #ffffff1f;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

main { padding: 16px 16px 24px; }

/* bottom tab bar: nav lives under the thumb on a phone */
.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: #fff;
}
.tabbar button {
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 9px 2px 10px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.tabbar button span { font-size: 18px; line-height: 1; }
.tabbar button.active { color: var(--blue); }

/* ---------- metrics ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.metrics article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics strong { display: block; margin-top: 6px; font-size: 21px; }
.metrics article.wide { grid-column: 1 / -1; }

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
}
.section-heading h2 { flex: 1; font-size: 15px; }

.toolbar { display: grid; gap: 9px; margin-bottom: 14px; }
.toolbar label { margin: 0; }

/* ---------- subscriber cards ---------- */
.card-list { display: grid; gap: 11px; }
.sub-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.sub-card__top { display: flex; align-items: flex-start; gap: 10px; }
.sub-card__id { flex: 1; min-width: 0; }
.sub-card__id strong { display: block; font-size: 15px; }
.sub-card__id small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.sub-card__meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 12px 0 13px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.sub-card__meta div { min-width: 0; }
.sub-card__meta span { display: block; color: var(--muted); font-size: 11px; }
.sub-card__meta b { font-size: 13px; font-weight: 600; }
.sub-card__actions { display: flex; flex-wrap: wrap; gap: 7px; }
.sub-card__actions .button { flex: 1 1 auto; min-width: 104px; padding: 9px 12px; font-size: 13px; }

.badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.active, .badge.lifetime { color: var(--ok); background: var(--ok-bg); }
.badge.expired, .badge.suspended { color: var(--danger); background: var(--danger-bg); }
.badge.trial, .badge.none { color: var(--warn); background: var(--warn-bg); }

.empty-state {
  padding: 40px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
.muted { color: var(--muted); font-size: 13px; }

.skeleton { display: grid; gap: 11px; }
.skeleton div {
  height: 118px;
  border-radius: var(--radius);
  background: linear-gradient(100deg, #eef1f6 30%, #f7f9fc 50%, #eef1f6 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { background-position: 180% 0; } to { background-position: -40% 0; } }

.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.panel h2 { margin-bottom: 6px; font-size: 16px; }

.log-list { display: grid; gap: 8px; }
.log-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  font-size: 13px;
}
.log-row time { margin-inline-start: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------- dialogs: full-height sheets on a phone ---------- */
dialog {
  width: 100%;
  max-width: 100%;
  max-height: 92svh;
  margin: 0 0 0 auto;
  margin-block-start: auto;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--ink);
  overflow: hidden;
}
dialog::backdrop { background: #0f172a80; }
dialog form, dialog .sheet { display: flex; flex-direction: column; max-height: 92svh; }
dialog header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 13px;
  border-bottom: 1px solid var(--line);
}
dialog header h2 { flex: 1; font-size: 16px; }
dialog header button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--bg);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.dialog-body { flex: 1; min-height: 0; padding: 16px 18px; overflow-y: auto; }
.dialog-body > p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
dialog footer {
  display: flex;
  gap: 9px;
  padding: 13px 18px calc(15px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}
dialog footer .button { flex: 1; }

.code-display {
  display: block;
  margin: 4px 0 14px;
  padding: 18px 12px;
  border-radius: 13px;
  background: #eaf1ff;
  color: var(--navy);
  text-align: center;
  direction: ltr;
  font-size: clamp(20px, 6.5vw, 30px);
  font-weight: 800;
  letter-spacing: 2px;
  word-break: break-all;
}

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 60;
  padding: 13px 16px;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 12px 30px #102a4340;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .22s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

/* ---------- wider screens ---------- */
@media (min-width: 900px) {
  .app-shell {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    padding-bottom: 0;
  }
  .appbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    gap: 22px;
    padding: 20px 14px;
    grid-row: 1 / -1;
  }
  .appbar__title { display: flex; align-items: center; gap: 10px; }
  .appbar__title h1 { font-size: 16px; }
  .appbar .icon-button { display: none; }
  .tabbar {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
  }
  .tabbar button {
    grid-template-columns: 22px 1fr;
    justify-items: start;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 10px;
    color: #ffffffb5;
    font-size: 14px;
    text-align: start;
  }
  .tabbar button.active { color: var(--navy); background: #fff; }
  main { padding: 26px 30px 40px; }
  .page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
  .page-head h2 { flex: 1; font-size: 23px; }
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metrics article.wide { grid-column: auto; }
  .toolbar { grid-template-columns: minmax(0, 1fr) 210px; align-items: end; }
  .card-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  dialog {
    width: min(100% - 40px, 540px);
    max-height: 86svh;
    margin: auto;
    border-radius: 18px;
  }
  dialog form, dialog .sheet { max-height: 86svh; }
  dialog footer { padding-bottom: 15px; }
  .toast { inset-inline: auto; inset-inline-start: 26px; bottom: 26px; max-width: 360px; }
}

@media (max-width: 899px) {
  .page-head { display: none; }
}
