/* ============================================================
   CWP-2 Portal — Default Theme
   Copy and rename to custom.css to override without losing updates.
   ============================================================ */

/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --color-bg:         #f5f5f5;
  --color-surface:    #ffffff;
  --color-border:     #e0e0e0;
  --color-border-strong: #c0c0c0;

  --color-text:       #1a1a1a;
  --color-text-muted: #6b7280;
  --color-text-light: #9ca3af;

  --color-primary:    #2563eb;
  --color-primary-h:  #1d4ed8;
  --color-primary-fg: #ffffff;

  --color-success:    #16a34a;
  --color-warning:    #d97706;
  --color-danger:     #dc2626;
  --color-info:       #0891b2;

  --color-success-bg: #f0fdf4;
  --color-warning-bg: #fffbeb;
  --color-danger-bg:  #fef2f2;
  --color-info-bg:    #ecfeff;

  --sidebar-w:   220px;
  --radius:      8px;
  --radius-sm:   4px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

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

/* ── Layout ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.main-content {
  min-height: 100vh;
  padding: 24px;
}
.main-content.with-sidebar {
  margin-left: var(--sidebar-w);
  max-width: 960px;
}
.main-content.full-width {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--color-border);
}
.sidebar-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  display: block;
}
.sidebar-logo {
  max-height: 36px;
  max-width: 160px;
}

.sidebar-nav {
  list-style: none;
  padding: 8px 8px;
  flex: 1;
  overflow-y: auto;
}
.sidebar-nav li { margin-bottom: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--color-bg); color: var(--color-text); text-decoration: none; }
.nav-link.active { background: #eff6ff; color: var(--color-primary); font-weight: 500; }
.nav-link .ti { font-size: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--color-border);
}
.user-info {
  padding: 6px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-email { font-size: 12px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; }
.user-balance { font-size: 13px; font-weight: 600; color: var(--color-text); }

.notif-link { position: relative; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-danger);
  color: #fff;
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 20px; font-weight: 600; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 12px;
}
.section-header h3 { font-size: 15px; font-weight: 600; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary  { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-h); }
.btn-outline  { background: transparent; border-color: var(--color-border-strong); color: var(--color-text); }
.btn-outline:hover:not(:disabled) { background: var(--color-bg); }
.btn-ghost    { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--color-text); }
.btn-danger   { background: var(--color-danger); color: #fff; }
.btn-sm       { padding: 4px 10px; font-size: 12.5px; }
.btn-lg       { padding: 10px 20px; font-size: 15px; }
.btn-block    { width: 100%; justify-content: center; }
.btn-icon     { padding: 4px 6px; border: none; background: none; color: var(--color-text-muted); cursor: pointer; border-radius: var(--radius-sm); }
.btn-icon:hover { color: var(--color-text); background: var(--color-bg); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--color-text);
}
.form-control {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: var(--font);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control::placeholder { color: var(--color-text-light); }
.form-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 12px; align-items: center; }
.form-row-between { justify-content: space-between; flex-wrap: wrap; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.alert-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid #bbf7d0; }
.alert-error, .alert-danger { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid #fecaca; }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border: 1px solid #fde68a; }
.alert-info    { background: var(--color-info-bg); color: var(--color-info); border: 1px solid #a5f3fc; }
.alert-close   { margin-left: auto; background: none; border: none; cursor: pointer; color: inherit; opacity: .6; }
.flash-container { margin-bottom: 16px; }

/* ── Auth pages ──────────────────────────────────────────────────────────── */
.auth-wrap {
  width: 100%;
  max-width: 400px;
  padding: 24px 16px;
}
.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}
.auth-logo { max-height: 48px; margin-bottom: 16px; display: block; }
.auth-site-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.auth-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.auth-footer-text { margin-top: 18px; font-size: 13px; color: var(--color-text-muted); text-align: center; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.link-muted { color: var(--color-text-muted); font-size: 13px; }
.link-muted:hover { color: var(--color-text); }

/* ── Calculator ──────────────────────────────────────────────────────────── */
.calc-card { position: relative; }
.calc-selectors { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 4px; }
@media (max-width: 600px) { .calc-selectors { grid-template-columns: 1fr; } }

.calc-fields { margin-top: 4px; }
.calc-online-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 14px;
}
.toggle-caption { font-size: 14px; font-weight: 500; color: var(--color-text); }

/* Segmented Offline | Online control — large, obvious, both options visible */
.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  gap: 3px;
}
.segmented-input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 18px;
  min-width: 84px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.segmented-btn:hover:not(.is-active):not(.is-disabled) {
  color: var(--color-text);
  background: var(--color-surface);
}
.segmented-btn.is-active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.segmented-btn.is-disabled {
  cursor: not-allowed;
  opacity: .6;
}
.segmented-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}


.calc-cost-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  margin-bottom: 14px;
}
.calc-cost-row strong { color: var(--color-text); font-size: 15px; }

.calc-result {
  margin-top: 16px;
  padding: 16px;
  background: var(--color-success-bg);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
}
.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.result-row:last-child { margin-bottom: 0; }
.result-label { font-size: 12px; font-weight: 500; color: var(--color-text-muted); min-width: 40px; }
.result-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  word-break: break-all;
  flex: 1;
}
.result-meta { font-size: 12px; color: var(--color-text-muted); margin-top: 6px; }

.calc-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--color-text-muted);
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.user-balance-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--color-text-muted);
}
.user-balance-badge .ti { color: var(--color-text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin-bottom: 16px; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.table-hover tr:hover td { background: #f9fafb; }
.td-date, .td-nowrap { white-space: nowrap; }
.td-code { font-family: var(--font-mono); }

.result-code-inline {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-default { background: #f3f4f6; color: #374151; }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-danger  { background: var(--color-danger-bg);  color: var(--color-danger); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-info    { background: var(--color-info-bg);    color: var(--color-info); }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-search { flex: 1; min-width: 160px; }
.filter-select { width: auto; min-width: 120px; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  font-size: 13px;
}
.page-link { color: var(--color-primary); }
.page-info { color: var(--color-text-muted); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-box {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 480px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-open { overflow: hidden; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.detail-list dt { font-size: 12px; font-weight: 500; color: var(--color-text-muted); padding-top: 4px; }
.detail-list dd { font-size: 13.5px; padding: 2px 0 6px; border-bottom: 1px solid var(--color-border); }
.detail-list .dd-copy { display: flex; align-items: center; gap: 8px; }

/* ── Notifications ───────────────────────────────────────────────────────── */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.notif-unread { border-left: 3px solid var(--color-primary); }
.notif-success .notif-icon { color: var(--color-success); }
.notif-warning .notif-icon { color: var(--color-warning); }
.notif-danger  .notif-icon { color: var(--color-danger); }
.notif-info    .notif-icon { color: var(--color-info); }
.notif-icon .ti { font-size: 18px; }
.notif-title { font-weight: 600; font-size: 13.5px; }
.notif-msg   { font-size: 13px; color: var(--color-text-muted); }
.notif-time  { font-size: 11.5px; color: var(--color-text-light); margin-top: 3px; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}
.empty-state .ti { font-size: 40px; display: block; margin-bottom: 12px; opacity: .4; }

/* ── Error page ──────────────────────────────────────────────────────────── */
.error-page { text-align: center; padding: 60px 24px; }
.error-page h2 { font-size: 64px; font-weight: 700; color: var(--color-border-strong); }
.error-page p  { color: var(--color-text-muted); margin: 8px 0 20px; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.portal-footer {
  margin-left: var(--sidebar-w);
  padding: 12px 24px;
  font-size: 12px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success{ color: var(--color-success); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: relative;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .sidebar-nav { display: flex; flex-direction: row; flex: none; padding: 4px; }
  .sidebar-footer { display: flex; gap: 8px; align-items: center; padding: 8px; }
  .user-info { display: none; }
  .main-content.with-sidebar { margin-left: 0; }
  .portal-footer { margin-left: 0; }
}

/* ── Top-up ──────────────────────────────────────────────────────────────── */
.topup-card { max-width: 480px; }
.amount-input-wrap { position: relative; }
.amount-prefix {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--color-text-muted); font-size: 14px; pointer-events: none;
}
.amount-input { padding-left: 26px; }
.credits-preview {
  font-size: 13px; color: var(--color-text-muted);
  margin: -8px 0 16px; padding: 8px 10px;
  background: var(--color-bg); border-radius: var(--radius-sm);
}
.payment-buttons { display: flex; flex-direction: column; gap: 12px; }
.payment-section { display: flex; flex-direction: column; gap: 8px; }
.btn-payment { width: 100%; justify-content: center; padding: 11px 20px; font-size: 14px; }

/* ── Admin ───────────────────────────────────────────────────────────────── */
.tab-nav {
  display: flex; gap: 2px; margin-bottom: 20px;
  border-bottom: 2px solid var(--color-border); padding-bottom: 0;
}
.tab-link {
  padding: 8px 16px; font-size: 13.5px; color: var(--color-text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-link:hover { color: var(--color-text); text-decoration: none; }
.tab-link.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 500; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat-card.stat-warn { border-color: var(--color-warning); background: var(--color-warning-bg); }
.stat-card.stat-danger { border-color: var(--color-danger); background: var(--color-danger-bg); }
.stat-alert { margin-top: 8px; font-size: 11.5px; font-weight: 600; color: var(--color-danger); line-height: 1.35; }
.stat-label { font-size: 12px; color: var(--color-text-muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--color-text); }
.stat-sub { font-size: 12px; font-weight: 400; color: var(--color-text-muted); }

.admin-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.hint-text { font-size: 12px; color: var(--color-text-muted); margin: 0; }
.action-row { display: flex; gap: 6px; align-items: center; }

.settings-form { max-width: 720px; }
.settings-section { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--color-border); }
.settings-section:last-of-type { border-bottom: none; }
.settings-heading { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--color-text); }
.settings-subheading { font-size: 13px; font-weight: 600; margin: 0 0 10px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .03em; }

.mb-12 { margin-bottom: 12px; }
.ml-8  { margin-left: 8px; }
code { font-family: var(--font-mono); font-size: 12.5px; background: var(--color-bg); padding: 1px 5px; border-radius: 3px; }
