/* ═══════════════════════════════════════════════════════════
   Bigo Live Agent — Design System (Phoenix Edition)
═══════════════════════════════════════════════════════════ */

:root {
  /* Brand */
  --primary:        #f97316;
  --primary-hover:  #ea580c;
  --primary-soft:   #fff1e6;
  --primary-glow:   rgba(249, 115, 22, .18);
  --accent:         #2563eb;
  --accent-hover:   #1d4ed8;

  /* Surfaces */
  --bg:             #fff7ed;
  --surface:        #ffffff;
  --surface-2:      #fffaf5;
  --surface-3:      #fff4ea;
  --sidebar-bg:     #ffffff;

  /* Borders */
  --border:         #fed7aa;
  --border-soft:    #ede9e4;
  --border-focus:   #f97316;

  /* Text */
  --text:           #111827;
  --text-muted:     #6b7280;
  --text-light:     #9ca3af;
  --sidebar-text:   #374151;

  /* Status */
  --danger:         #dc2626;
  --danger-soft:    rgba(220, 38, 38, .10);
  --success:        #16a34a;
  --success-soft:   rgba(22, 163, 74, .10);
  --warning:        #d97706;
  --warning-soft:   rgba(217, 119, 6, .10);

  /* Radius */
  --radius-xs:  6px;
  --radius-sm:  10px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --radius-xl:  26px;

  /* Shadows */
  --shadow-xs:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm:  0 2px 8px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.10), 0 4px 12px rgba(0,0,0,.06);
  --shadow-orange: 0 4px 14px rgba(249,115,22,.30), 0 1px 4px rgba(249,115,22,.15);

  /* Layout */
  --sidebar-width: 256px;
  --topbar-height: 60px;
}

[data-theme='dark'] {
  --bg:           #13100c;
  --surface:      #1c1813;
  --surface-2:    #231e17;
  --surface-3:    #2a2218;
  --sidebar-bg:   #181410;
  --border:       #3a2c1d;
  --border-soft:  #2e2519;
  --text:         #f0ebe3;
  --text-muted:   #a89880;
  --text-light:   #7a6a58;
  --sidebar-text: #c8bfb0;
  --primary-soft: #2c1d10;
  --primary-glow: rgba(249,115,22,.12);
  --shadow-xs:    0 1px 3px rgba(0,0,0,.3);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);
  --shadow-md:    0 4px 16px rgba(0,0,0,.35);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.40);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

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

/* ═══════════════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════════════ */

.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 16px 12px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--border-soft);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Custom scrollbar inside sidebar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 99px; }

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 12px;
}

.sidebar-brand .logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
  box-shadow: var(--shadow-orange);
  letter-spacing: -1px;
}

.sidebar-brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -.3px;
}

/* Bigo account card */
.sidebar-bigo-panel {
  padding: 0 2px 14px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar-bigo-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-light);
  font-weight: 700;
  padding: 0 6px 8px;
}

.sidebar-bigo-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 10px 11px;
  margin-bottom: 8px;
  transition: border-color .2s, box-shadow .2s;
}

.sidebar-bigo-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.sidebar-bigo-card img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-soft);
  flex-shrink: 0;
}

.sidebar-bigo-info { min-width: 0; flex: 1; }
.sidebar-bigo-name {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-bigo-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.sidebar-bigo-type {
  font-size: 11px;
  color: var(--success);
  font-weight: 600;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.sidebar-bigo-type::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.sidebar-bigo-type-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}
.sidebar-bigo-type-chip {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.sidebar-bigo-type-chip:hover { border-color: var(--success); }
.sidebar-bigo-type-chip.active {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

/* Nav groups */
.nav-group { margin-top: 4px; }
.nav-group + .nav-group { margin-top: 14px; }

.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-light);
  padding: 0 10px 5px;
  font-weight: 700;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 1px;
  transition: background .15s, color .15s;
  position: relative;
}

.nav-link:hover {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.nav-link.active {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-orange);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .5);
  backdrop-filter: blur(2px);
  z-index: 55;
}

/* ── Main area ─────────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── Topbar ────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 24px;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 1px 0 var(--border-soft), 0 2px 8px rgba(0,0,0,.04);
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 17px;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  transition: border-color .15s;
}
.menu-toggle:hover { border-color: var(--primary); color: var(--primary); }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.topbar-user {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 5px 12px;
}

/* ── Content area ──────────────────────────────────────── */
.content {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}

.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-header h2 { margin: 0; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-orange);
  transition: transform .15s, box-shadow .15s, opacity .15s;
  letter-spacing: .01em;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(249,115,22,.40);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-xs);
}
.btn.secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(249,115,22,.12);
  transform: none;
}

.btn.accent {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 4px 14px rgba(37,99,235,.30);
}
.btn.accent:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(37,99,235,.40);
}

.btn.danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 12px rgba(220,38,38,.25);
}
.btn.danger:hover:not(:disabled) {
  box-shadow: 0 6px 18px rgba(220,38,38,.35);
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.btn.secondary .spinner { border-color: var(--border-soft); border-top-color: var(--text-muted); }

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

/* ── Icon buttons ──────────────────────────────────────── */
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: border-color .15s, color .15s, background .15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary-hover); background: var(--primary-soft); }

/* Row icon buttons (edit/copy/delete inline) */
.row-icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 5px 7px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.row-icon-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.row-icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--surface-3);
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
}

.badge.active   { background: var(--success-soft); color: var(--success); border-color: rgba(22,163,74,.2); }
.badge.disabled,
.badge.blocked,
.badge.failed   { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(220,38,38,.2); }
.badge.pending  { background: var(--warning-soft); color: var(--warning); border-color: rgba(217,119,6,.2); }
.badge.info     { background: rgba(37,99,235,.08); color: var(--accent);  border-color: rgba(37,99,235,.2); }
.badge.purple   { background: rgba(124,58,237,.08); color: #7c3aed; border-color: rgba(124,58,237,.2); }

/* ── Table ─────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 480px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-light);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

thead th:first-child { border-radius: var(--radius-xs) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius-xs) 0 0; }

td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  color: var(--text);
}

/* Legacy th (non-thead) */
th {
  text-align: left;
  padding: 10px 12px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-light);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }

/* ── Forms ─────────────────────────────────────────────── */
.form-row { margin-bottom: 16px; }

.form-row label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 7px;
  color: var(--text-muted);
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-soft);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}

.form-row input::placeholder,
.form-row textarea::placeholder { color: var(--text-light); }

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-row textarea { resize: vertical; min-height: 90px; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ── Permission grid ───────────────────────────────────── */
.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-2);
}
.permission-grid label { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 80;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 440px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border-soft);
  box-shadow:
    0 2px 4px rgba(0,0,0,.04),
    0 8px 24px rgba(0,0,0,.12),
    0 32px 64px rgba(0,0,0,.10);
}

.modal h3 {
  margin: 0 0 20px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
}

/* ── Page loading overlay ──────────────────────────────── */
.page-loading-overlay {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .55);
  backdrop-filter: blur(4px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.page-loading-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}
.page-loading-card p { margin: 0; font-size: 14px; font-weight: 600; }

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 340px;
  min-width: 220px;
  background: var(--text);
  color: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  border: none;
  animation: toastIn .3s cubic-bezier(.34,1.56,.64,1);
}
.toast.error   { background: var(--danger); }
.toast.success { background: var(--success); }
.toast.warning { background: var(--warning); }

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

/* ── Utility ───────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.text-small { font-size: 12px; }

.diamond-icon {
  height: 12px; width: 12px;
  vertical-align: middle;
  margin-right: 3px;
  object-fit: contain;
}

/* ── Login page (kept for backward compat) ─────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════ */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .topbar-user { display: none; }
  .content { padding: 16px; }
  .card { padding: 16px; border-radius: var(--radius-md); }
  .permission-grid { grid-template-columns: 1fr; }
  .modal { width: 100%; padding: 20px; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .toast { right: 16px; bottom: 16px; left: 16px; max-width: none; }
}

@media (max-width: 480px) {
  .topbar-title { font-size: 15px; }
  .card-header { flex-direction: column; align-items: stretch; }
  .card-header .btn { width: 100%; }
  .modal h3 { font-size: 15px; }
}
