@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f1f4f9;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #f0642f;
  --brand-dark: #d4521f;
  --ok: #059669;
  --bad: #dc2626;
  --navy: #182334;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', 'Microsoft JhengHei', 'Noto Sans TC', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 32px;
  height: 54px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}

.brand {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  letter-spacing: -0.01em;
}

nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

nav a, .link-button {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

nav a:hover, .link-button:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}

nav a.active {
  color: #fff;
  font-weight: 600;
  background: rgba(255,255,255,0.13);
}

/* ── Shell ── */
.shell {
  width: min(1600px, calc(100% - 40px));
  margin: 28px auto;
}

/* ── Panel ── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
}

h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 20px 0 10px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ── Forms ── */
.admin-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}

.form-grid { display: grid; gap: 14px; }

label {
  display: grid;
  gap: 5px;
  color: #3d5068;
  font-weight: 600;
  font-size: 13px;
}

small { color: var(--muted); font-weight: 400; }

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(240,100,47,0.12);
}

/* ── Buttons ── */
button, .button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 13px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

button:hover, .button:hover {
  background: #f8fafc;
  border-color: #c8d5e8;
}

.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

.primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.danger { color: var(--bad); border-color: #fecaca; }
.danger:hover { background: #fff0f0; border-color: #f87171; }

.btn-extend { color: #2563eb; border-color: #bfdbfe; }
.btn-extend:hover { background: #eff6ff; border-color: #93c5fd; }

/* ── Messages ── */
.messages { display: grid; gap: 8px; margin-bottom: 18px; }

.message {
  border-radius: 8px;
  padding: 12px 16px;
  background: #eef4ff;
  border: 1px solid #cfddf8;
  font-size: 14px;
}

.message.error { color: #7f1d1d; background: #fef2f2; border-color: #fecaca; }
.message.success { color: #065f46; background: #ecfdf5; border-color: #a7f3d0; }

/* ── Section head ── */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

/* ── Admin tools ── */
.admin-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: 260px;
}

.search-form input { flex: 1; }

.backup-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.backup-form input[type="file"] {
  padding: 7px 10px;
  font-size: 13px;
}

.backup-note {
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.license-table { min-width: 1160px; }
.seller-total-table { min-width: 560px; }

th, td {
  border-bottom: 1px solid #f0f4fa;
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: #f8fafd;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfe; }

/* License-table column widths */
.license-table th:nth-child(1), .license-table td:nth-child(1) { width: 120px; }
.license-table th:nth-child(2), .license-table td:nth-child(2) { width: 240px; }
.license-table th:nth-child(3), .license-table td:nth-child(3) { } /* email – auto */
.license-table th:nth-child(4), .license-table td:nth-child(4) { width: 72px; text-align: center; }
.license-table th:nth-child(5), .license-table td:nth-child(5) { width: 105px; }
.license-table th:nth-child(6), .license-table td:nth-child(6) { width: 105px; }
.license-table th:nth-child(7), .license-table td:nth-child(7) { width: 145px; }
.license-table th:nth-child(8), .license-table td:nth-child(8) { width: 230px; }

code {
  white-space: nowrap;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 12.5px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  color: #1e3a5f;
}

.license-key {
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 12.5px;
  white-space: nowrap;
  color: #1e3a5f;
  letter-spacing: 0.02em;
}

.sort-link {
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sort-link:hover { color: var(--brand); }

/* ── Mini form (email update) ── */
.mini-form {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.mini-form input {
  min-width: 0;
  flex: 1;
  font-size: 13px;
  padding: 6px 10px;
}

/* ── Action cell ── */
.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.actions form, .inline { display: inline; }

/* ── Pill badges ── */
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
}

.pill.active  { color: #065f46; background: #d1fae5; }
.pill.disabled { color: #7f1d1d; background: #fee2e2; }
.pill.bound   { color: #1e40af; background: #dbeafe; }
.pill.unbound { color: var(--muted); background: #f1f5f9; }

/* ── Stats ── */
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
}

.stats div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  background: #fbfcff;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats strong {
  display: block;
  font-size: 22px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
}

.stats .total { border-color: #ffd2bf; background: #fff6f1; }

.expiry {
  margin-top: 12px;
  border-top: 1px solid #ffd2bf;
  padding-top: 10px;
  color: #7c3b1f;
}

.expiry b, .expiry em { display: block; }

.expiry em {
  margin-top: 4px;
  color: #b42318;
  font-style: normal;
  font-weight: 800;
}

.expiry.urgent {
  border: 1px solid #ffb4a8;
  border-radius: 8px;
  background: #fff0ee;
  padding: 10px;
}

.money { color: #9a3412; font-weight: 700; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 36px !important;
  font-size: 14px;
}

.narrow {
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .topbar, .section-head { flex-direction: column; align-items: stretch; }
  .admin-form, .stats { grid-template-columns: 1fr; }
  .admin-tools { flex-direction: column; align-items: stretch; }
}

/* ═══════════════════════════════════════════
   Dark Frontend Theme (.dark-page)
   ═══════════════════════════════════════════ */

.dark-page {
  background: #060b14;
  background-image:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(59,130,246,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(240,100,47,0.05) 0%, transparent 60%),
    linear-gradient(rgba(20,36,60,0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20,36,60,0.25) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px;
  min-height: 100vh;
  color: #c8d8f0;
}

/* Topbar dark override */
.dark-page .topbar {
  background: rgba(6,11,20,0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(59,130,246,0.15);
}

/* Messages stay inside .front-card, hide shell messages on dark page */
.dark-page > .shell > .messages { display: none; }

/* ── Hero centering shell ── */
.front-hero {
  min-height: calc(100vh - 54px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

/* ── Login card ── */
.front-card {
  width: 100%;
  max-width: 480px;
  background: rgba(12,20,36,0.85);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 18px;
  padding: 36px 40px 40px;
  backdrop-filter: blur(24px);
  box-shadow:
    0 0 0 1px rgba(59,130,246,0.06),
    0 8px 40px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.04);
  animation: cardIn 0.4s cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Brand row ── */
.front-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  color: #6b9fd4;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Title ── */
.front-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
  background: linear-gradient(135deg, #e8f0ff 0%, #7eb6ff 60%, #93c5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.front-desc {
  font-size: 13px;
  color: #4d6b90;
  margin: 0 0 24px;
  line-height: 1.65;
}

/* ── Flash messages inside card ── */
.front-msg {
  border-radius: 8px;
  padding: 11px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.22);
  color: #93b8f5;
}
.front-msg.error {
  background: rgba(220,38,38,0.08);
  border-color: rgba(220,38,38,0.28);
  color: #fca5a5;
}
.front-msg.success {
  background: rgba(5,150,105,0.08);
  border-color: rgba(5,150,105,0.28);
  color: #6ee7b7;
}

/* ── Form ── */
.front-form { display: grid; gap: 16px; }

.front-field { display: grid; gap: 7px; }

.front-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #6b9fd4;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.front-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(59,130,246,0.15);
  color: #60a5fa;
  text-transform: none;
  letter-spacing: 0.02em;
}

.front-field input {
  background: rgba(4,8,18,0.8);
  border: 1px solid rgba(59,130,246,0.18);
  border-radius: 9px;
  color: #d0e4ff;
  padding: 11px 14px;
  font: inherit;
  font-size: 14px;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.front-field input::placeholder { color: #2a4060; }

.front-field input:focus {
  outline: none;
  border-color: #3b82f6;
  background: rgba(4,8,22,0.95);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.14), 0 0 16px rgba(59,130,246,0.07);
}

.front-file-wrap input[type="file"] {
  background: rgba(4,8,18,0.8);
  border: 1px dashed rgba(59,130,246,0.25);
  border-radius: 9px;
  color: #4d6b90;
  padding: 10px 14px;
  width: 100%;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.front-file-wrap input[type="file"]:focus {
  outline: 2px solid rgba(59,130,246,0.4);
}

/* ── Submit button ── */
.front-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
  padding: 13px 20px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #f0642f 0%, #e34d15 100%);
  box-shadow: 0 4px 20px rgba(240,100,47,0.35), 0 0 0 1px rgba(240,100,47,0.3);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.front-submit svg { transform: rotate(180deg); }

.front-submit:hover {
  background: linear-gradient(135deg, #ff6d35 0%, #f0642f 100%);
  box-shadow: 0 6px 28px rgba(240,100,47,0.5), 0 0 0 1px rgba(240,100,47,0.4);
  transform: translateY(-1px);
}

.front-submit:active { transform: translateY(0); }

/* ══ Result Page ══ */
.front-result {
  max-width: 900px;
  margin: 36px auto;
  padding: 0 16px;
  animation: cardIn 0.4s cubic-bezier(0.16,1,0.3,1) both;
}

.result-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.result-back-btn {
  display: inline-flex;
  align-items: center;
  padding: 9px 16px;
  border: 1px solid rgba(59,130,246,0.25);
  border-radius: 8px;
  background: rgba(59,130,246,0.06);
  color: #60a5fa;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.result-back-btn:hover {
  background: rgba(59,130,246,0.12);
  border-color: rgba(59,130,246,0.4);
}

/* ── Result stat cards ── */
.result-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.rstat {
  background: rgba(12,20,36,0.8);
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: 14px;
  padding: 18px 16px;
  backdrop-filter: blur(12px);
}

.rstat span {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #4d6b90;
  margin-bottom: 10px;
}

.rstat strong {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: #d0e4ff;
  letter-spacing: -0.02em;
}

.rstat--total {
  border-color: rgba(240,100,47,0.3);
  background: rgba(240,100,47,0.06);
}

.rstat--total strong { color: #fb923c; font-size: 22px; }

.rstat-expiry {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(240,100,47,0.2);
  font-size: 12px;
  color: #a06040;
}

.rstat-expiry b { display: block; margin-bottom: 4px; font-weight: 500; }

.rstat-expiry em {
  display: block;
  font-style: normal;
  font-weight: 700;
  color: #f87171;
  margin-top: 4px;
}

.rstat-expiry.urgent {
  border-radius: 8px;
  background: rgba(240,100,47,0.08);
  border: 1px solid rgba(240,100,47,0.25);
  padding: 10px;
  margin-top: 10px;
}

/* ── Result detail table ── */
.result-panel {
  background: rgba(12,20,36,0.75);
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: 14px;
  padding: 24px 28px;
  backdrop-filter: blur(12px);
}

.result-h2 {
  font-size: 14px;
  font-weight: 600;
  color: #4d6b90;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 16px;
}

.result-table { table-layout: auto; }

.result-panel .table-wrap {
  border: 1px solid rgba(59,130,246,0.12);
  border-radius: 10px;
  overflow: hidden;
}

.result-panel th {
  background: rgba(4,8,18,0.6);
  color: #3a5578;
  border-bottom: 1px solid rgba(59,130,246,0.12);
}

.result-panel td {
  color: #8bb4d8;
  border-bottom: 1px solid rgba(59,130,246,0.07);
}

.result-panel tbody tr:last-child td { border-bottom: none; }

.result-panel tbody tr:hover td {
  background: rgba(59,130,246,0.04);
  color: #aed0f0;
}

/* Responsive dark */
@media (max-width: 760px) {
  .front-card { padding: 28px 24px; }
  .result-stats { grid-template-columns: repeat(2, 1fr); }
  .rstat--total { grid-column: 1 / -1; }
  .result-header { flex-direction: column; }
}

@media (max-width: 480px) {
  .result-stats { grid-template-columns: 1fr; }
}

