@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@300;400;500;600;700&family=Fira+Code:wght@400;500;600&display=swap');

:root {
  --accent: #1e40af;
  --accent-dark: #1d4ed8;
  --accent-deep: #1e3a8a;
  --accent-soft: #3b82f6;
  --amber: #d97706;
  --amber-dark: #b45309;
  --bg: #f8fafc;
  --bg2: #ffffff;
  --card: #ffffff;
  --card-border: #dbeafe;
  --text: #1e293b;
  --muted: #475569;
  --danger: #dc2626;
  --sidebar: #ffffff;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.05);
  --radius: 12px;
}

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

body {
  font-family: 'Fira Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a, button, [role="button"], input[type="checkbox"], label, select { cursor: pointer; }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], textarea { cursor: text; }

.icon { width: 18px; height: 18px; flex-shrink: 0; }
.stat-icon svg { width: 22px; height: 22px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #eef3fb 0%, #dbe6f7 50%, #eef3fb 100%);
}

.auth-page::before,
.auth-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: float 8s ease-in-out infinite;
}

.auth-page::before {
  width: 400px; height: 400px;
  background: var(--accent);
  top: -100px; left: -100px;
}

.auth-page::after {
  width: 300px; height: 300px;
  background: var(--accent-dark);
  bottom: -80px; right: -80px;
  animation-delay: -4s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, 20px) scale(1.05); }
}

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

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(30, 64, 175, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(30, 64, 175, 0); }
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 40px 36px;
  animation: fadeUp 0.6s ease;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  animation: pulse 2s infinite;
}

.auth-logo svg { width: 32px; height: 32px; color: #fff; }

.auth-card h1 {
  text-align: center;
  font-size: 1.6rem;
  margin-bottom: 6px;
  color: var(--text);
}

.auth-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input, .field textarea, .field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--text);
  font: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.label-optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}

.file-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px dashed var(--card-border);
  border-radius: 10px;
  background: #f8fafc;
}

.file-picker input[type="file"] {
  width: auto;
  max-width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.9rem;
}

.file-name {
  flex: 1;
  font-size: 0.9rem;
  color: var(--muted);
  min-width: 120px;
}

.btn-clear-file {
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  margin-top: 8px;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 8px 24px rgba(30, 64, 175, 0.35);
}

.btn-amber {
  width: 100%;
  background: linear-gradient(135deg, var(--amber-dark), var(--amber));
  color: #fff;
  margin-top: 8px;
}

.btn-amber:hover:not(:disabled) {
  box-shadow: 0 8px 24px rgba(217, 119, 6, 0.35);
}

.btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--card-border);
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  padding: 8px 0;
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-footer a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-error {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

/* App layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--sidebar);
  border-right: 1px solid var(--card-border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-bottom: 32px;
}

.sidebar-brand .icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}

.sidebar-brand .icon svg { width: 22px; height: 22px; color: #fff; }

.sidebar-brand span { font-weight: 700; font-size: 1rem; color: var(--text); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  margin-bottom: 4px;
  transition: background 0.2s, color 0.2s;
}

.nav-link:hover { background: #f1f5f9; color: var(--text); }
.nav-link.active { background: rgba(30, 64, 175, 0.1); color: var(--accent); font-weight: 600; }
.nav-link svg { width: 18px; height: 18px; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--card-border); }

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 0.8rem;
}

.main {
  flex: 1;
  margin-left: 240px;
  padding: 32px;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 28px;
  animation: fadeUp 0.5s ease;
}

.page-header h1 { font-size: 1.75rem; margin-bottom: 4px; color: var(--text); }
.page-header p { color: var(--muted); font-size: 0.95rem; }

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.5s ease backwards;
  transition: transform 0.2s, border-color 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(30, 64, 175, 0.3);
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #0f172a, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-icon { font-size: 1.5rem; margin-bottom: 12px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.5s ease;
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

/* QR */
.qr-section { text-align: center; padding: 20px 0; }

#qrImg {
  width: 260px; height: 260px;
  border-radius: 16px;
  border: 3px solid var(--accent);
  padding: 8px;
  background: #fff;
  animation: fadeUp 0.6s ease, pulse 3s infinite;
}

.qr-hint { color: var(--muted); margin-top: 16px; font-size: 0.9rem; }

.connected-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(30, 64, 175, 0.1);
  color: var(--accent);
  padding: 10px 18px;
  border-radius: 99px;
  font-weight: 600;
  font-size: 0.9rem;
}

.dot-live {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

/* API settings */
.api-block {
  background: #f8fafc;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.api-block h3 {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.method-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-right: 8px;
}

.method-get { background: #1d4ed8; color: #fff; }
.method-post { background: #b45309; color: #fff; }

.url-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.url-input {
  flex: 1;
  font-family: 'Fira Code', ui-monospace, monospace;
  font-size: 0.75rem;
  padding: 10px 12px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  word-break: break-all;
  cursor: pointer;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.8rem;
  background: rgba(30, 64, 175, 0.1);
  color: var(--accent);
  border: 1px solid rgba(30, 64, 175, 0.3);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-sm:hover { background: rgba(30, 64, 175, 0.18); }

.btn-sm svg { width: 16px; height: 16px; }

.btn-sm.btn-amber {
  background: var(--amber-dark);
  color: #fff;
  border: 1px solid var(--amber-dark);
  width: auto;
  margin: 0;
}

.btn-sm.btn-amber:hover { background: var(--amber); border-color: var(--amber); }

.hint { font-size: 0.82rem; color: var(--muted); margin-bottom: 12px; }

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  text-decoration: none;
  font-weight: 600;
}

.btn-google:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.google-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.google-toolbar input[type="search"] {
  flex: 1;
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--text);
  font: inherit;
}

.contact-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: #f8fafc;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--card-border);
  cursor: pointer;
  transition: background 0.15s;
}

.contact-item:last-child { border-bottom: none; }
.contact-item:hover { background: rgba(30, 64, 175, 0.05); }
.contact-item.selected { background: rgba(30, 64, 175, 0.1); }

.contact-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.contact-meta { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; font-size: 0.95rem; }
.contact-phone { font-size: 0.82rem; color: var(--muted); }
.contact-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.google-flash { margin-top: 12px; color: var(--accent); }

.hidden { display: none !important; }

/* Super admin */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.card-head h2 { margin-bottom: 0; }

.stat-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: #f8fafc;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 720px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.data-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(15, 23, 42, 0.03); }

.cell-strong { font-weight: 600; }
.cell-muted { color: var(--muted); font-size: 0.8rem; }

.expiry-note {
  margin-top: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--amber, #d97706);
  background: rgba(217, 119, 6, 0.1);
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
}
.expiry-note-done { color: #b91c1c; background: rgba(220, 38, 38, 0.1); }
#subscriptionNote { margin-top: 8px; display: block; width: fit-content; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-active { background: rgba(22, 163, 74, 0.12); color: #15803d; }
.badge-disabled { background: rgba(220, 38, 38, 0.1); color: #b91c1c; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-ghost-sm {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--card-border);
}

.btn-ghost-sm:hover { background: rgba(15, 23, 42, 0.04); }

.btn-danger-sm {
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  border: 1px solid rgba(220, 38, 38, 0.25);
}

.btn-danger-sm:hover { background: rgba(220, 38, 38, 0.14); }

.btn-amber-sm {
  background: rgba(217, 119, 6, 0.1);
  color: var(--amber, #d97706);
  border: 1px solid rgba(217, 119, 6, 0.35);
}

.btn-amber-sm:hover { background: rgba(217, 119, 6, 0.18); }

.analysis-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chart-label {
  flex: 0 0 180px;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-track {
  flex: 1;
  height: 14px;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 99px;
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  border-radius: 99px;
  min-width: 3px;
  transition: width 0.5s ease;
}

.chart-value {
  flex: 0 0 48px;
  text-align: right;
  font-weight: 700;
  font-size: 0.9rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.3s ease;
}

.modal h2 { font-size: 1.2rem; margin-bottom: 18px; color: var(--text); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modal-actions .btn-primary { margin-top: 0; flex: 1; }
.modal-actions .btn-secondary { flex: 1; }

@media (max-width: 1024px) {
  .main { padding: 24px; }
  .chart-label { flex-basis: 140px; }
}

@media (max-width: 768px) {
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .main { margin-left: 0; padding: 16px; }
  .app-layout { flex-direction: column; }
  .sidebar-footer { display: none; }
  .chart-label { flex-basis: 120px; }
}
