/* =========================================
   MarkBase Billing — Global Styles
   ========================================= */

:root {
  --bg-base:       #060d1f;
  --bg-card:       #0d1a2e;
  --bg-card2:      #111e33;
  --bg-hover:      #162040;
  --bg-input:      #0b1528;
  --border:        #1e2d4a;
  --border-active: #3b82f6;
  --text-primary:  #e2e8f0;
  --text-muted:    #7b8eab;
  --text-faint:    #3d5275;
  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --accent-soft:   rgba(59,130,246,.18);
  --green:         #10b981;
  --green-soft:    rgba(16,185,129,.15);
  --blue:          #3b82f6;
  --blue-soft:     rgba(59,130,246,.15);
  --gold:          #f59e0b;
  --gold-soft:     rgba(245,158,11,.15);
  --purple:        #8b5cf6;
  --purple-soft:   rgba(139,92,246,.15);
  --red:           #ef4444;
  --red-soft:      rgba(239,68,68,.15);

  --header-h:      56px;
  --sidebar-w:     240px;
  --sidebar-coll:  60px;
  --radius:        10px;
  --radius-lg:     14px;
  --transition:    .17s ease;
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ======= AUTH SCREEN ======= */
#auth-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #041838 0%, #060d1f 70%);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 380px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,.5);
}

.auth-logo {
  width: 60px; height: 60px; border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 0 32px rgba(59,130,246,.4);
}

.auth-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.auth-card p  { color: var(--text-muted); font-size: 13px; margin-bottom: 28px; line-height: 1.5; }

.btn-auth {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff; text-decoration: none;
  padding: 12px 24px; border-radius: 8px;
  font-weight: 600; font-size: 14px;
  box-shadow: 0 4px 16px rgba(59,130,246,.4);
  transition: var(--transition);
}
.btn-auth:hover { background: linear-gradient(135deg, #2563eb, #1e40af); }

/* ======= ADMIN BANNER ======= */
#admin-banner {
  display: none;
  background: linear-gradient(90deg, #1d4ed8, #1e40af);
  text-align: center; font-size: 11px; font-weight: 600;
  letter-spacing: .06em; color: rgba(255,255,255,.85); padding: 5px 0;
}

/* ======= HEADER ======= */
#app-header {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: rgba(6,13,31,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 24px;
}

.header-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; font-size: 16px; font-weight: 700; color: var(--text-primary); letter-spacing: -.02em;
}

.header-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  box-shadow: 0 0 10px rgba(59,130,246,.6);
}

.header-nav { display: flex; gap: 4px; flex: 1; }
.header-nav a { color: var(--text-muted); text-decoration: none; padding: 5px 12px; border-radius: 6px; font-size: 13px; transition: var(--transition); }
.header-nav a:hover { color: var(--text-primary); background: var(--bg-hover); }

.header-account { position: relative; }

.account-trigger {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card2); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; color: var(--text-primary); transition: var(--transition);
}
.account-trigger:hover { border-color: var(--border-active); background: var(--bg-hover); }

.trigger-avatar, .avatar-lg {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.avatar-lg { width: 38px; height: 38px; font-size: 14px; }

.trigger-info { text-align: left; min-width: 0; }
.trigger-name  { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.trigger-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }

.account-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 280px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 16px 48px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transform: translateY(-6px);
  transition: var(--transition); z-index: 400;
}
.account-dropdown.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.dropdown-section { padding: 8px; border-bottom: 1px solid var(--border); }
.dropdown-section:last-child { border-bottom: none; }

.dropdown-user { display: flex; align-items: center; gap: 12px; padding: 6px; }
.dropdown-user-info { min-width: 0; }
.dropdown-user-info .name  { font-size: 13px; font-weight: 600; }
.dropdown-user-info .email { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.dropdown-menu { list-style: none; }
.dropdown-menu li a,
.dropdown-menu li button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; border-radius: 6px;
  text-decoration: none; color: var(--text-primary); font-size: 13px;
  background: none; border: none; cursor: pointer; transition: var(--transition);
}
.dropdown-menu li a:hover,
.dropdown-menu li button:hover { background: var(--bg-hover); }
.dropdown-menu li button.danger { color: var(--red); }

.badge-external { margin-left: auto; font-size: 10px; color: var(--text-faint); background: var(--border); padding: 1px 5px; border-radius: 4px; }

/* ======= APP LAYOUT ======= */
#app-layout { display: flex; height: calc(100vh - var(--header-h)); }
.layout-inner { display: flex; width: 100%; overflow: hidden; }

/* ======= SIDEBAR ======= */
#app-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-card); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 16px 8px;
}
#app-sidebar::-webkit-scrollbar { width: 4px; }
#app-sidebar::-webkit-scrollbar-track { background: transparent; }
#app-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-section { margin-bottom: 8px; }
.sidebar-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-faint); padding: 12px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; border: none; background: none;
  color: var(--text-muted); border-radius: 7px; font-size: 13px; font-weight: 500;
  cursor: pointer; text-align: left; transition: var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item svg { flex-shrink: 0; }

/* ======= MAIN ======= */
#app-main { flex: 1; overflow-y: auto; padding: 32px 32px 64px; }
#app-main::-webkit-scrollbar { width: 6px; }
#app-main::-webkit-scrollbar-track { background: transparent; }
#app-main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

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

.page-title { font-size: 22px; font-weight: 700; color: var(--text-primary); letter-spacing: -.02em; margin-bottom: 6px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }

/* ======= BALANCE HERO ======= */
.balance-hero {
  background: linear-gradient(135deg, #0e2d5a 0%, #0a1e3d 50%, #060d1f 100%);
  border: 1px solid #1e3a6a;
  border-radius: var(--radius-lg);
  padding: 28px 28px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.balance-hero-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: rgba(147,197,253,.6); margin-bottom: 8px;
}

.balance-hero-value {
  font-size: 38px; font-weight: 800; letter-spacing: -.03em;
  color: #fff; text-shadow: 0 0 40px rgba(59,130,246,.4); margin-bottom: 6px;
}

.balance-hero-meta { font-size: 13px; color: rgba(255,255,255,.5); }

.balance-hero-right { display: flex; gap: 10px; flex-shrink: 0; }

/* ======= STATS GRID ======= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: var(--transition); }
.stat-card:hover { border-color: var(--text-faint); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 4px; }
.stat-value.blue   { color: var(--blue); }
.stat-value.green  { color: var(--green); }
.stat-value.gold   { color: var(--gold); }
.stat-value.purple { color: var(--purple); }
.stat-hint { font-size: 11px; color: var(--text-faint); }

/* ======= TWO COLUMN ======= */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ======= CARD ======= */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* ======= TARIFF PLAN CARDS ======= */
.tariff-plans {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.tariff-plan {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  transition: var(--transition);
  cursor: pointer;
}
.tariff-plan:hover { border-color: var(--accent); }
.tariff-plan.current { border-color: var(--accent); background: var(--accent-soft); }

.tp-name { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.tp-price { font-size: 22px; font-weight: 800; color: var(--blue); margin-bottom: 12px; }
.tp-price span { font-size: 13px; font-weight: 400; color: var(--text-muted); }
.tp-limits { font-size: 12px; color: var(--text-muted); line-height: 1.8; }

/* ======= RESOURCE BARS ======= */
#resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.resource-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.resource-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 8px; }
.resource-values { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.resource-used { font-size: 22px; font-weight: 800; color: var(--text-primary); }
.resource-limit { font-size: 13px; color: var(--text-muted); }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--blue); transition: width .5s ease; }
.progress-fill.warn { background: var(--gold); }
.progress-fill.danger { background: var(--red); }
.progress-fill.unlimited { background: var(--green); width: 20% !important; }

/* ======= TABLE ======= */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; font-size: 13px; color: var(--text-primary); border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
.empty-row td { text-align: center; color: var(--text-muted); padding: 32px; }

/* ======= FORM ======= */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.form-input, .form-select {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 12px; color: var(--text-primary); font-size: 13px;
  outline: none; transition: var(--transition); -webkit-appearance: none;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-input::placeholder { color: var(--text-faint); }

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237b8eab' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; cursor: pointer;
}
.form-select option { background: #0d1a2e; }

.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-primary); cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ======= BUTTONS ======= */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; border: none; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-primary { background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; box-shadow: 0 2px 12px rgba(59,130,246,.3); }
.btn-primary:hover { background: linear-gradient(135deg, #2563eb, #1e40af); }
.btn-secondary { background: var(--bg-card2); border: 1px solid var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-faint); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-danger { background: var(--red-soft); border: 1px solid var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* ======= BADGES ======= */
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-active   { background: var(--green-soft); color: var(--green); }
.badge-inactive { background: var(--bg-hover); color: var(--text-muted); }
.badge-blue     { background: var(--blue-soft); color: var(--blue); }
.badge-gold     { background: var(--gold-soft); color: var(--gold); }

/* ======= COST BREAKDOWN ======= */
.breakdown-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.breakdown-item { background: var(--bg-card2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.breakdown-name { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; text-transform: capitalize; }
.breakdown-amount { font-size: 20px; font-weight: 800; color: var(--text-primary); }
.breakdown-sub { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* ======= SUBSCRIPTION INFO ======= */
.sub-info { display: flex; flex-direction: column; gap: 12px; }
.sub-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg-card2); border-radius: 8px; }
.sub-row-label { font-size: 12px; color: var(--text-muted); }
.sub-row-value { font-size: 14px; font-weight: 700; color: var(--text-primary); }

/* ======= LOADING ======= */
.loading-overlay {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 40px; color: var(--text-muted); font-size: 13px;
}
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ======= TOAST ======= */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; padding: 14px 18px; color: var(--text-primary); font-size: 13px; box-shadow: 0 8px 32px rgba(0,0,0,.4); pointer-events: auto; opacity: 0; transform: translateY(10px); animation: toast-in .2s ease forwards; max-width: 320px; }
.toast.success { border-left-color: var(--green); }
.toast.error   { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--gold); }
.toast.hide    { animation: toast-out .2s ease forwards; }
@keyframes toast-in  { to { opacity:1; transform:translateY(0); } }
@keyframes toast-out { to { opacity:0; transform:translateY(6px); } }

/* ======= SCROLLBAR ======= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ======= RESPONSIVE ======= */
@media (max-width: 768px) {
  #app-sidebar { width: var(--sidebar-coll); }
  .sidebar-label, .nav-item span { display: none; }
  .nav-item { justify-content: center; }
  .trigger-info { display: none; }
  #app-main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .balance-hero { flex-direction: column; align-items: flex-start; }
}
