/* ==========================================================================
   GTC Web — application UI
   Palette, type, shape, elevation and motion are defined in DESIGN.md.
   Loaded by the homepage and the admin dashboard.
   ========================================================================== */

:root {
  --canvas: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #eceae4;

  --ink: #191a17;
  --ink-soft: #5f6259;
  --ink-faint: #8b8d84;

  --line: #e3e4de;
  --line-strong: #d3d5cc;

  --accent: #0f7a63;
  --accent-bg: #0f7a63;
  --accent-bg-hover: #0b5c4a;
  --on-accent: #ffffff;
  --accent-tint: #e7f2ef;
  --accent-line: #cfe4de;

  --ok: #1f7a4d;
  --ok-tint: #e8f3ec;
  --warn: #8a5a00;
  --warn-tint: #f6efe0;
  --bad: #b3261e;
  --bad-tint: #f7e8e6;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;

  --shadow-modal: 0 18px 50px rgba(25, 26, 23, 0.22);
  --focus-ring: 0 0 0 3px rgba(15, 122, 99, 0.28);

  --code-bg: #1c1d1a;
  --code-ink: #e8e9e4;

  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* Dark theme: same identity, surfaces lifted, accent brightened for contrast.
   Applied only when <html data-theme="dark">; the head script sets it from the
   stored choice or the system preference before first paint. */
:root[data-theme="dark"] {
  --canvas: #131416;
  --surface: #1b1d1f;
  --surface-2: #26292c;

  --ink: #f1f2ef;
  --ink-soft: #a9ada6;
  --ink-faint: #7d8279;

  --line: #2c2f32;
  --line-strong: #3a3e42;

  --accent: #56cca9;
  --accent-bg: #4bc4a1;
  --accent-bg-hover: #3fb492;
  --on-accent: #08211b;
  --accent-tint: #16302a;
  --accent-line: #2a4a41;

  --ok: #6fce96;
  --ok-tint: #16301f;
  --warn: #e0b055;
  --warn-tint: #332711;
  --bad: #f0827a;
  --bad-tint: #3a1c1a;

  --shadow-modal: 0 18px 50px rgba(0, 0, 0, 0.55);
  --focus-ring: 0 0 0 3px rgba(86, 204, 169, 0.32);

  --code-bg: #0f1112;
  --code-ink: #e8e9e4;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; }

p { margin: 0; }

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

.muted { color: var(--ink-soft); }
.error { color: var(--bad); }

/* ---- Layout ---- */
.wrap { max-width: 760px; margin: 0 auto; padding: 30px 18px 72px; }
.wrap--wide { max-width: 1060px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
}

.card--flush { padding: 0; overflow: hidden; }

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; flex-direction: column; gap: 3px; }
.brand-mark { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { color: var(--ink-soft); font-size: 13.5px; }

/* ---- Forms ---- */
.form-container { display: flex; flex-direction: column; gap: 22px; }

.form-row { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: start; }

.form-label { font-size: 13.5px; font-weight: 600; padding-top: 11px; }
.req { color: var(--bad); margin-left: 3px; }

.form-control-wrapper { display: flex; flex-direction: column; min-width: 0; }

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea,
.form-input {
  width: 100%;
  padding: 11px 13px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  font: inherit;
  font-size: 15px;
  outline: none;
  min-height: 46px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus,
.form-input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.hint { color: var(--ink-soft); font-size: 13px; line-height: 1.5; margin-top: 7px; }

/* ---- Stock ---- */
.stock-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.stock-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--ink-soft);
}

.stock-badge .stock-num { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }

.stock-refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 40px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.stock-refresh-btn:hover { background: var(--surface-2); }
.stock-refresh-btn.loading { opacity: 0.55; pointer-events: none; }

/* ---- Option (radio) cards ---- */
.option-group { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }

.option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.option:hover { border-color: var(--accent); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.option input[type="radio"] { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.option-title { font-weight: 600; }
.option-desc { color: var(--ink-soft); font-size: 13px; }

/* ---- Informational note ---- */
.paid-info-text {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--accent-tint);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-sm);
  font-size: 13.5px;
  line-height: 1.5;
}
.paid-info-text.show { display: block; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  min-height: 46px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-bg-hover); border-color: var(--accent-bg-hover); }

.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #94201a; border-color: #94201a; }

.btn-ghost-danger { background: transparent; border-color: var(--line-strong); color: var(--bad); }
.btn-ghost-danger:hover:not(:disabled) { background: var(--bad-tint); border-color: var(--bad-tint); }

.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; min-height: 38px; font-size: 13px; border-radius: var(--r-sm); }

.btn:focus-visible,
.stock-refresh-btn:focus-visible,
.tab-btn:focus-visible,
.modal-close:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ---- Result ---- */
.result {
  margin-top: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
}

.result-head {
  font-size: 15px;
  font-weight: 650;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  word-break: break-word;
}

.profile-card { display: flex; gap: 18px; align-items: flex-start; }

.profile-image {
  width: 88px;
  height: 88px;
  border-radius: var(--r);
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}

.profile-info { flex: 1; min-width: 0; font-size: 14px; line-height: 1.7; color: var(--ink-soft); }
.profile-name { font-size: 19px; font-weight: 650; color: var(--ink); margin-bottom: 2px; word-break: break-word; }
.profile-subname { color: var(--ink-faint); font-size: 13.5px; margin-bottom: 10px; }
.profile-field { margin-bottom: 3px; word-break: break-word; }
.profile-field strong { color: var(--ink); font-weight: 600; }
.tag-count-num { font-weight: 650; color: var(--accent); }

/* ---- Tables ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.tags-table, .data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.tags-table th, .data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

.tags-table td, .data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.tags-table tbody tr:last-child td, .data-table tbody tr:last-child td { border-bottom: 0; }
.tags-table tbody tr:hover td, .data-table tbody tr:hover td { background: var(--canvas); }

.data-table td.mono { font-family: var(--mono); font-size: 12.5px; }
.data-table td.highlight { font-weight: 600; }

/* ---- Comments ---- */
.comments-section { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.comments-header { font-weight: 650; margin-bottom: 14px; }
.comments-list { display: flex; flex-direction: column; gap: 14px; }

.comment-item { display: flex; gap: 12px; align-items: flex-start; }
.comment-author-img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.comment-content { flex: 1; min-width: 0; }
.comment-meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.comment-author { font-weight: 600; font-size: 13.5px; }
.comment-date { font-size: 12px; color: var(--ink-faint); }
.comment-body { font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; white-space: pre-wrap; word-break: break-word; }

pre {
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Captcha ---- */
.captcha-container {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: 20px;
}

.captcha-header { margin-bottom: 16px; }
.captcha-title { font-weight: 650; margin-bottom: 3px; }
.captcha-subtitle { color: var(--ink-soft); font-size: 13.5px; }
.captcha-body { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }

.captcha-image { max-width: 200px; border: 1px solid var(--line); border-radius: var(--r-sm); }

.captcha-input-group { display: flex; gap: 8px; width: 100%; max-width: 340px; }
.captcha-input-group input { flex: 1; }
.captcha-input-group .btn { width: auto; }

/* ---- QRIS ---- */
.qris-container { display: flex; flex-direction: column; align-items: center; gap: 18px; }

.qris-title { font-weight: 650; font-size: 16px; }

.qris-qr-wrapper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px;
}
.qris-qr-wrapper img, .qris-qr-wrapper canvas { display: block; max-width: 100%; height: auto; }

.qris-details { display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center; }
.qris-amount { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.qris-order-id { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); word-break: break-all; }

.countdown-timer { font-size: 14px; font-weight: 600; color: var(--warn); }
.countdown-timer.expiring { color: var(--bad); }

.payment-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
}
.payment-status.waiting { background: var(--warn-tint); color: var(--warn); }
.payment-status.success { background: var(--ok-tint); color: var(--ok); }
.payment-status.expired { background: var(--bad-tint); color: var(--bad); }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.qris-actions { display: flex; gap: 10px; width: 100%; }
.qris-actions .btn { flex: 1; }

/* ---- Modals ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(25, 26, 23, 0.5);
  z-index: 1000;
}
.modal-overlay.active { display: flex; }

.modal {
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-title { font-weight: 650; font-size: 15px; }

.modal-close {
  background: none;
  border: 0;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }

.modal-body { padding: 20px; overflow: auto; flex: 1; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

/* ==========================================================================
   Admin
   ========================================================================== */

.dashboard { display: none; }

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.dash-header h1 { font-size: clamp(18px, 4vw, 22px); }
.dash-header .brand-sub { font-weight: 400; }
.dash-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Icon-only theme toggle: square so the icon sits centered. */
.theme-toggle {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
}
.theme-toggle svg { display: block; }

.tab-bar {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
}

.tab-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 9px 14px;
  border-radius: calc(var(--r) - 4px);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(25, 26, 23, 0.08); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Metric strip (real counts, scoped to the active tab) */
.metrics { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }

.metric {
  flex: 1 1 150px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.metric-label { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.metric-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric-value.accent { color: var(--accent); }
.metric-value.ok { color: var(--ok); }
.metric-value.warn { color: var(--warn); }
.metric-value.bad { color: var(--bad); }

.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.table-card-header h2 { font-size: 15px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
}
.status-badge.completed { background: var(--ok-tint); color: var(--ok); }
.status-badge.pending { background: var(--warn-tint); color: var(--warn); }
.status-badge.cancelled, .status-badge.expired, .status-badge.failed { background: var(--bad-tint); color: var(--bad); }

.pool-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.pool-badge.good { background: var(--ok-tint); color: var(--ok); }
.pool-badge.low { background: var(--warn-tint); color: var(--warn); }
.pool-badge.empty { background: var(--bad-tint); color: var(--bad); }

.empty { padding: 40px 20px; text-align: center; }
.empty-title { font-weight: 600; margin-bottom: 4px; }
.empty-hint { color: var(--ink-soft); font-size: 13.5px; }

.add-cred-form {
  display: none;
  margin: 16px 18px;
  padding: 18px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.add-cred-form.visible { display: block; }
.add-cred-form h3 { font-size: 14px; margin-bottom: 14px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }

.login-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 30px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.login-card .theme-toggle { position: absolute; top: 16px; right: 16px; }
.login-card .logo { margin-bottom: 24px; }
.login-card .logo h1 { font-size: 20px; }
.login-card .logo p { color: var(--ink-soft); font-size: 13px; margin-top: 3px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.login-card .btn-block { margin-top: 18px; }
.login-error { display: none; margin-top: 10px; color: var(--bad); font-size: 13px; }

/* ==========================================================================
   Responsive + motion preference
   ========================================================================== */

@media (max-width: 680px) {
  .form-row { grid-template-columns: 1fr; gap: 6px; }
  .form-label { padding-top: 0; }
}

@media (max-width: 560px) {
  .wrap { padding: 22px 14px 60px; }
  .profile-card { flex-direction: column; align-items: flex-start; }
  .qris-actions { flex-direction: column; }
  .metric { flex: 1 1 calc(50% - 5px); }
  .tab-bar { display: flex; width: 100%; }
  .tab-btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
