:root {
  --mtn-yellow: #FFCC00;
  --mtn-dark: #1a1a2e;
  --mtn-navy: #16213e;
  --mtn-blue: #0f3460;
  --mtn-light: #f4f6f9;
  --mtn-text: #333;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --sidebar-width: 250px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; }
body { font-family: 'Segoe UI', sans-serif; background: var(--mtn-light); color: var(--mtn-text); overflow-x: hidden; }

/* LOGIN */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--mtn-dark); }
.login-box { background: white; border-radius: 12px; padding: 2.5rem; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo h1 { color: var(--mtn-dark); font-size: 1.6rem; }
.login-logo span { color: var(--mtn-yellow); }
.login-box h2 { text-align: center; margin-bottom: 1.5rem; color: var(--mtn-blue); font-size: 1.1rem; font-weight: 600; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-size: 0.85rem; font-weight: 600; color: #555; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.65rem 0.9rem; border: 1.5px solid #ddd; border-radius: 6px;
  font-size: 0.95rem; transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--mtn-yellow); }
.btn { display: inline-block; padding: 0.65rem 1.4rem; border: none; border-radius: 6px; cursor: pointer; font-size: 0.9rem; font-weight: 600; text-decoration: none; transition: opacity 0.2s; }
.btn-primary { background: var(--mtn-yellow); color: var(--mtn-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-secondary { background: #6c757d; color: white; }
.btn:hover { opacity: 0.85; }
.btn-block { display: block; width: 100%; text-align: center; }
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-danger { background: #fdecea; color: #c0392b; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* LAYOUT */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); background: var(--mtn-dark); color: white; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; z-index: 100; }
.sidebar-header { padding: 1.2rem 1rem; background: var(--mtn-navy); border-bottom: 3px solid var(--mtn-yellow); }
.sidebar-header h2 { font-size: 1rem; color: var(--mtn-yellow); }
.sidebar-header p { font-size: 0.75rem; color: #aaa; margin-top: 0.2rem; }
.sidebar-nav { flex: 1; padding: 1rem 0; }
.sidebar-nav a { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 1.2rem; color: #ccc; text-decoration: none; font-size: 0.88rem; transition: all 0.2s; border-left: 3px solid transparent; }
.sidebar-nav a:hover, .sidebar-nav a.active { color: var(--mtn-yellow); background: rgba(255,204,0,0.08); border-left-color: var(--mtn-yellow); }
.sidebar-nav .nav-section { padding: 0.5rem 1.2rem; font-size: 0.7rem; text-transform: uppercase; color: #666; margin-top: 0.5rem; }
.sidebar-footer { padding: 1rem; border-top: 1px solid #333; font-size: 0.8rem; color: #888; }
.sidebar-footer a { color: #dc3545; text-decoration: none; font-weight: 600; }

.main-content { margin-left: var(--sidebar-width); flex: 1; padding: 0; min-width: 0; overflow-x: hidden; }
.topbar { background: white; padding: 0.9rem 1.5rem; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.08); position: sticky; top: 0; z-index: 50; }
.topbar h1 { font-size: 1.15rem; color: var(--mtn-blue); }
.topbar .user-info { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: #555; }
.page-body { padding: 1.5rem; overflow-x: hidden; max-width: 100%; }

/* CARDS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: white; border-radius: 10px; padding: 1.2rem 1.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-left: 4px solid var(--mtn-yellow); min-width: 0; overflow: hidden; }
.stat-card h3 { font-size: 0.8rem; color: #888; text-transform: uppercase; margin-bottom: 0.4rem; word-break: break-word; }
.stat-card .value { font-size: 1.8rem; font-weight: 700; color: var(--mtn-dark); word-break: break-word; }
.stat-card .sub { font-size: 0.78rem; color: #aaa; margin-top: 0.2rem; }
.stat-card.yellow { border-left-color: var(--mtn-yellow); }
.stat-card.green { border-left-color: var(--success); }
.stat-card.red { border-left-color: var(--danger); }
.stat-card.blue { border-left-color: var(--info); }

.card { background: white; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); margin-bottom: 1.5rem; min-width: 0; }
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid #eee; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.card-header h3 { font-size: 1rem; color: var(--mtn-blue); flex-shrink: 0; }
.card-body { padding: 1.5rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* TABLE */
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th { background: var(--mtn-light); padding: 0.65rem 1rem; text-align: left; font-size: 0.78rem; text-transform: uppercase; color: #888; border-bottom: 2px solid #eee; }
.table td { padding: 0.7rem 1rem; border-bottom: 1px solid #f0f0f0; }
.table tr:hover td { background: #fafafa; }
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-active, .badge-paid { background: #d4edda; color: #155724; }
.badge-suspended, .badge-overdue { background: #fdecea; color: #c0392b; }
.badge-terminated, .badge-cancelled { background: #e2e3e5; color: #383d41; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-disabled { background: #e2e3e5; color: #383d41; }

/* MODAL */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; align-items: center; justify-content: center; }
.modal-bg.open { display: flex; }
.modal { background: white; border-radius: 10px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-header { padding: 1rem 1.5rem; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { color: var(--mtn-blue); font-size: 1rem; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: #999; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid #eee; text-align: right; display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ── RESPONSIVE LAYOUT ── */

/* Card header toolbars and search bars */
.card-toolbar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.card-toolbar form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.card-toolbar input[type="text"],
.card-toolbar input[type="search"] { min-width: 0; flex: 1 1 140px; }

/* Filter tab row — scrolls horizontally on mobile */
.filter-tabs {
  display: flex; gap: 0.25rem;
  background: #f0f0f0; border-radius: 7px; padding: 0.2rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  flex-shrink: 0; max-width: 100%;
}
.filter-tabs::-webkit-scrollbar { height: 0; }

/* Page action row (back + title + buttons) */
.page-action-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.2rem; }

/* ── Mobile sidebar overlay backdrop ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 299;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* Hamburger in topbar — hidden on desktop */
.topbar-hamburger {
  display: none;
  background: none; border: 1px solid #e5e7eb; cursor: pointer;
  padding: 0.38rem 0.5rem; border-radius: 7px;
  color: var(--mtn-blue); font-size: 1rem; line-height: 1;
  transition: background .18s;
}
.topbar-hamburger:hover { background: #f0f2f5; }

/* Sidebar close button — hidden on desktop */
.sidebar-close {
  display: none;
  position: absolute; top: 0.8rem; right: 0.8rem;
  background: rgba(255,255,255,0.08); border: none;
  width: 28px; height: 28px; border-radius: 6px;
  color: #aaa; cursor: pointer; font-size: 0.9rem;
  align-items: center; justify-content: center;
  transition: background .18s, color .18s;
}
.sidebar-close:hover { background: rgba(220,53,69,0.2); color: #f87171; }

/* Reusable two-column grid that collapses on tablet */
.dash-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* Superadmin packages: form + table grid */
.sa-pkg-grid { min-width: 0; }

/* Tables inside card-body always scroll on small screens */
.card-body.p0 { padding: 0; overflow-x: auto; }

/* Sticky last-column (Actions) in tables */
.table th.col-actions,
.table td.col-actions {
  position: sticky;
  right: 0;
  background: white;
  box-shadow: -3px 0 8px rgba(0,0,0,0.06);
  z-index: 2;
}
.table thead th.col-actions { background: var(--mtn-light); }

/* ── TABLET (≤900px) ── */
@media (max-width: 900px) {
  /* Sidebar slides in as overlay */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1), box-shadow .28s;
    z-index: 300; position: fixed;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 40px rgba(0,0,0,0.55);
  }
  .sidebar-close { display: inline-flex; }

  /* Main content takes full width */
  .main-content { margin-left: 0; }

  /* Show hamburger in topbar */
  .topbar-hamburger { display: inline-flex; }

  /* Stats: 2 per row — minmax(0,1fr) forces columns to shrink below min-content */
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Two-col dashboard panels collapse */
  .dash-two-col { grid-template-columns: 1fr; }

  /* Superadmin packages: stack form above table */
  .sa-pkg-grid { grid-template-columns: 1fr !important; }

  /* Tables: always scroll, never clip */
  .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: max-content; }

  /* Phone manager: stack vertically */
  .pm-body { flex-direction: column; overflow-y: auto; }
  .pm-phone-wrap { padding: 1rem; }
  .pm-panel { border-left: none; border-top: 1px solid #2d3748; }
}

/* ── PHONE TABLE (≤720px) — show only Name / Phone / SIM ── */
@media (max-width: 720px) {
  .col-hide-mob { display: none; }
  .desk-actions { display: none !important; }
  .mob-action-wrap { display: block; }
}

/* ── MOBILE (≤580px) ── */
@media (max-width: 580px) {
  /* Tighter page padding */
  .page-body { padding: 1rem; }
  .topbar { padding: 0.65rem 1rem; gap: 0.6rem; }
  .topbar h1 { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .user-info span:first-of-type { display: none; } /* hide name, keep logout */
  #phonePill { display: none !important; } /* hide phone status pill on mobile */
  .topbar .user-info .fa-user-tie { display: none; } /* hide user icon */
  .topbar .user-info > span:nth-of-type(2),
  .topbar .user-info > span:nth-of-type(3) { display: none; } /* hide name + separator */

  /* Stats: still 2 per row but smaller */
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
  .stat-card { padding: 0.9rem 1rem; }
  .stat-card .value { font-size: 1.4rem; }

  /* Cards */
  .card-header { padding: 0.8rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .card-header > * { flex-shrink: 1; }
  .card-header .card-toolbar { flex-wrap: wrap; gap: 0.5rem; }
  .card-body { padding: 1rem; }

  /* Modals full-width */
  .modal { max-width: calc(100vw - 0.5rem); width: calc(100vw - 0.5rem); margin: 0.25rem; border-radius: 12px; max-height: 94vh; }
  .modal-header { padding: 0.9rem 1rem; }
  .modal-body { padding: 1rem; }
  .modal-footer { padding: 0.8rem 1rem; }

  /* Buttons in actions row */
  .actions { flex-wrap: wrap; }
}

/* ── SMALL MOBILE (≤400px) ── */
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 0.88rem; }
}

.actions { display: flex; gap: 0.4rem; }
.actions .btn { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* Mobile row-action dropdown */
.mob-action-wrap { display: none; position: relative; }
.row-menu {
  display: none; position: absolute;
  right: 0; top: calc(100% + 4px);
  background: white; border: 1px solid #e5e7eb;
  border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  z-index: 200; min-width: 155px; overflow: hidden;
}
.row-menu.open { display: block; }
.row-menu a, .row-menu button {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 1rem; width: 100%; text-decoration: none;
  font-size: 0.84rem; font-weight: 500; background: none;
  border: none; cursor: pointer; color: #333;
  transition: background .15s; text-align: left; white-space: nowrap;
}
.row-menu a:hover, .row-menu button:hover { background: #f8f9fa; }
.rm-divider { height: 1px; background: #f0f0f0; margin: 0.2rem 0; }

/* ══════════════════════════════════════
   TAILNET SPINNER
   ══════════════════════════════════════ */
.tn-spinner {
  width: 46px; height: 46px;
  border: 4px solid #e0e0e0;
  border-top-color: #0f3460;
  border-radius: 50%;
  animation: tn-spin 0.85s linear infinite;
}
@keyframes tn-spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════
   PHONE MANAGER MODAL
   ══════════════════════════════════════ */
#phoneManagerModal.modal-bg { background: rgba(0,0,0,0.85); align-items: stretch; justify-content: stretch; padding: 0; }
#phoneManagerModal.modal-bg.open { display: flex; }

.phone-manager-shell {
  display: flex;
  flex-direction: column;
  width: 100%; height: 100%;
  background: #111827;
  overflow: hidden;
}

/* Header */
.pm-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1.25rem;
  background: #0d1117;
  border-bottom: 2px solid #FFCC00;
  flex-shrink: 0;
}
.pm-indicator {
  width: 10px; height: 10px; border-radius: 50%;
  background: #28a745;
  box-shadow: 0 0 6px #28a745;
  animation: pm-pulse 2s ease-in-out infinite;
}
@keyframes pm-pulse { 0%,100%{opacity:1;} 50%{opacity:0.4;} }

/* Data monitor — row flash animations */
@keyframes dm-flash-warn {
  0%,100% { background:#fff8ec; }
  50%     { background:#fd7e14; color:#fff; }
}
@keyframes dm-flash-crit {
  0%,100% { background:#fff0f0; }
  50%     { background:#dc3545; color:#fff; }
}
.dm-row-warn { animation: dm-flash-warn 1.8s ease-in-out infinite; }
.dm-row-crit { animation: dm-flash-crit 1.2s ease-in-out infinite; }
.dm-row-warn td, .dm-row-crit td { border-color: transparent !important; }

/* Body */
.pm-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* Phone wrap — centres the phone frame */
.pm-phone-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem 1.5rem 2rem;
  background: #111827;
  position: relative;
}

/* The outer phone shell */
.pm-phone-outer {
  width: 300px;
  min-height: 580px;
  background: #1a1a2e;
  border-radius: 36px;
  border: 3px solid #2d3748;
  box-shadow: 0 0 0 6px #0d1117, 0 20px 60px rgba(0,0,0,0.7), inset 0 0 20px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Notch */
.pm-notch {
  height: 28px;
  background: #1a1a2e;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pm-camera {
  width: 10px; height: 10px; border-radius: 50%; background: #0d1117;
  box-shadow: inset 0 0 3px rgba(255,255,255,0.15);
}

/* Screen */
.pm-screen {
  flex: 1;
  background: #000;
  position: relative;
  overflow: hidden;
}

/* Home bar */
.pm-home-bar {
  height: 4px;
  background: #333;
  margin: 6px auto;
  width: 40%;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Android nav row */
.pm-nav-row {
  display: flex; align-items: center; justify-content: space-around;
  padding: 6px 16px 10px;
  background: rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.pm-nav-btn {
  background: none; border: none; color: #aaa; font-size: 1rem; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; transition: background 0.15s;
}
.pm-nav-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.pm-nav-home { font-size: 1.15rem; }

/* Volume strip on side */
.pm-vol-strip {
  position: absolute;
  right: -2px;
  top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.pm-vol-btn {
  width: 32px; height: 36px;
  background: #2d3748; border: none; border-radius: 0 6px 6px 0;
  color: #aaa; font-size: 0.8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.pm-vol-btn:hover { background: #4a5568; color: #fff; }

/* Right panel */
.pm-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: #1a1a2e;
  border-left: 1px solid #2d3748;
  display: flex;
  flex-direction: column;
  transition: width .25s, padding .25s;
}
.pm-panel.collapsed { display: none; }

/* Panel cards */
.pm-card {
  background: #111827;
  border: 1px solid #2d3748;
  border-radius: 10px;
  padding: 1rem 1.25rem;
}
.pm-card-title {
  font-size: 0.85rem; font-weight: 700; color: #e2e8f0;
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid #2d3748; padding-bottom: 0.6rem;
}
.pm-label {
  font-size: 0.75rem; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: .05em;
  display: block; margin-bottom: 0.3rem;
}

/* Quick action buttons */
.pm-action-btn {
  background: #2d3748; border: 1px solid #374151;
  color: #d1d5db; border-radius: 8px;
  padding: 0.6rem 0.5rem; cursor: pointer; font-size: 0.82rem;
  font-weight: 600; transition: background 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
}
.pm-action-btn:hover { background: #374151; color: #fff; }

/* --------------------------------------
   RESPONSIVE LAYOUT HELPERS
   -------------------------------------- */

/* -- Customer View: 5-column stats row -- */
.cv-stats-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.4rem;
}

/* -- Customer View: main two-column layout (sidebar | content) -- */
.cv-two-col {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* -- Customer View: donut chart + stats (chart | legend) -- */
.cv-donut-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.5rem;
  align-items: center;
}

/* -- Reports: revenue breakdown (2:1 ratio) -- */
.report-two-col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

/* -- Large tablet (=1100px) -- */
@media (max-width: 1100px) {
  .cv-stats-5  { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cv-two-col  { grid-template-columns: 280px 1fr; }
}

/* -- Tablet (=900px) -- */
@media (max-width: 900px) {
  .cv-stats-5     { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cv-two-col     { grid-template-columns: 1fr; }
  .report-two-col { grid-template-columns: 1fr; }
  .btn            { min-height: 40px; touch-action: manipulation; }
  input, select, textarea { font-size: 16px !important; }
}

/* -- Mobile (=580px) -- */
@media (max-width: 580px) {
  .cv-stats-5         { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cv-donut-grid      { grid-template-columns: 1fr; text-align: center; }
  .cv-donut-grid > *:first-child { margin: 0 auto; }
  .inv-parties        { grid-template-columns: 1fr !important; }
  .inv-dates          { gap: 0.75rem; }
}

/* -- Small mobile (=400px) -- */
@media (max-width: 400px) {
  .cv-stats-5 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
