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

:root {
  --bg: #0d0d14;
  --bg2: #13131f;
  --bg3: #1a1a2e;
  --surface: #1e1e30;
  --surface2: #252540;
  --border: #2a2a45;
  --primary: #8b5cf6;
  --primary-light: #a78bfa;
  --primary-dark: #6d28d9;
  --accent: #ec4899;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #f1f0f7;
  --text2: #9d9cb8;
  --text3: #5c5b7a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --nav-h: 64px;
  --bottom-nav-h: 68px;
}

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

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

.sidebar {
  width: 240px; min-height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-bottom: 10px;
}
.sidebar-logo h1 { font-size: 15px; font-weight: 700; color: var(--text); line-height: 1.2; }
.sidebar-logo span { font-size: 11px; color: var(--text2); }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--text2);
  text-decoration: none; font-size: 14px; font-weight: 500;
  border-radius: 0; transition: all 0.2s;
  margin: 1px 8px; border-radius: var(--radius-sm);
}
.sidebar-nav a:hover { background: var(--surface); color: var(--text); }
.sidebar-nav a.active { background: rgba(139,92,246,0.15); color: var(--primary-light); }
.sidebar-nav a .nav-icon { font-size: 18px; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm);
  background: var(--surface);
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 11px; color: var(--text2); }
.logout-btn {
  color: var(--text3); text-decoration: none; font-size: 18px;
  transition: color 0.2s;
}
.logout-btn:hover { color: var(--danger); }

.main-content {
  margin-left: 240px;
  flex: 1; min-height: 100vh;
  display: flex; flex-direction: column;
}

.top-bar {
  height: var(--nav-h); background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 50;
}
.top-bar h2 { font-size: 18px; font-weight: 600; }
.top-bar .actions { display: flex; gap: 10px; align-items: center; }

.page-body { padding: 28px; flex: 1; }

/* ── Mobile Bottom Nav ── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 200;
  justify-content: space-around;
  align-items: center;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  flex: 1; text-decoration: none; color: var(--text3);
  font-size: 10px; font-weight: 500; padding: 8px 4px;
  border-radius: var(--radius-sm); transition: all 0.2s;
  min-width: 0;
}
.bottom-nav a .bn-icon { font-size: 22px; line-height: 1; }
.bottom-nav a.active { color: var(--primary-light); }
.bottom-nav a.active .bn-icon { filter: drop-shadow(0 0 8px var(--primary)); }

.mobile-header {
  display: none; height: 56px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  align-items: center; padding: 0 20px;
  position: sticky; top: 0; z-index: 50; gap: 12px;
}
.mobile-logo { font-size: 16px; font-weight: 700; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }

/* ── KPI Cards ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative; overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.kpi-card.active::before { background: var(--success); }
.kpi-card.expiring::before { background: var(--warning); }
.kpi-card.expired::before { background: var(--danger); }
.kpi-card.mrr::before { background: linear-gradient(90deg, var(--primary), var(--accent)); }
.kpi-icon { font-size: 28px; margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.kpi-label { font-size: 12px; color: var(--text2); font-weight: 500; }
.kpi-card.active .kpi-value { color: var(--success); }
.kpi-card.expiring .kpi-value { color: var(--warning); }
.kpi-card.expired .kpi-value { color: var(--danger); }
.kpi-card.mrr .kpi-value { background: linear-gradient(135deg, var(--primary-light), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
}
.badge-active { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-expiring { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-expired { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-cancelled { background: rgba(156,163,175,0.15); color: #9ca3af; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; cursor: pointer;
  border: none; text-decoration: none; transition: all 0.2s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.btn-success:hover { background: rgba(16,185,129,0.25); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-warning { background: rgba(245,158,11,0.15); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.btn-warning:hover { background: rgba(245,158,11,0.25); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 14px; font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139,92,246,0.15); }
.form-control::placeholder { color: var(--text3); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.input-group { position: relative; }
.input-prefix {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text2); font-size: 14px; pointer-events: none;
}
.input-group .form-control { padding-left: 28px; }

/* ── Table ── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg3); color: var(--text2);
  font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 12px 14px; font-size: 14px; vertical-align: middle; }
tbody tr:last-child { border-bottom: none; }

/* ── Filters bar ── */
.filters-bar {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; margin-bottom: 20px;
}
.filter-tabs { display: flex; gap: 4px; background: var(--bg3); padding: 4px; border-radius: var(--radius-sm); }
.filter-tab {
  padding: 5px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
  color: var(--text2); cursor: pointer; border: none; background: none;
  transition: all 0.2s; text-decoration: none;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--surface2); color: var(--text); }
.search-box { position: relative; flex: 1; min-width: 200px; }
.search-box input { padding-left: 36px; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text3); font-size: 15px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 500; display: none; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Alerts ── */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; margin-bottom: 16px;
  border-left: 3px solid;
}
.alert-success { background: rgba(16,185,129,0.1); color: var(--success); border-color: var(--success); }
.alert-error { background: rgba(239,68,68,0.1); color: var(--danger); border-color: var(--danger); }
.alert-info { background: rgba(139,92,246,0.1); color: var(--primary-light); border-color: var(--primary); }

/* ── Instagram profile ── */
.ig-profile {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--primary-light); font-weight: 500;
}

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-state p { font-size: 14px; color: var(--text2); margin-bottom: 20px; }

/* ── History timeline ── */
.timeline { list-style: none; position: relative; }
.timeline::before {
  content: ''; position: absolute; left: 16px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline li { padding: 0 0 20px 44px; position: relative; }
.timeline-dot {
  position: absolute; left: 8px; top: 4px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--bg2);
}
.timeline-date { font-size: 12px; color: var(--text2); margin-bottom: 2px; }
.timeline-text { font-size: 14px; font-weight: 500; }

/* ── PWA install banner ── */
#install-banner {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 12px); left: 12px; right: 12px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  border-radius: var(--radius); padding: 14px 16px;
  display: none; align-items: center; gap: 12px;
  box-shadow: var(--shadow); z-index: 300;
  animation: slideUp 0.3s ease;
}
#install-banner.show { display: flex; }
#install-banner p { flex: 1; font-size: 13px; font-weight: 500; }
#install-banner .btn { background: rgba(255,255,255,0.2); color: #fff; border: 1px solid rgba(255,255,255,0.3); padding: 7px 14px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,0.5); }
  .main-content { margin-left: 0; }
  .bottom-nav { display: flex; }
  .mobile-header { display: flex; }
  .top-bar { display: none; }
  .page-body { padding: 16px; padding-bottom: calc(var(--bottom-nav-h) + 16px); }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .form-row { grid-template-columns: 1fr; }
  .filters-bar { gap: 8px; }
  table { min-width: 600px; }
  .modal { padding: 20px; }
  .btn-text-hide { display: none; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Overlay for sidebar on mobile ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 99;
}
.sidebar-overlay.show { display: block; }

/* ── Subscription card (mobile) ── */
.sub-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  display: none;
}
@media (max-width: 768px) {
  .sub-card { display: block; }
  .table-cards-mode table { display: none; }
  .table-cards-mode .sub-card { display: block; }
}
.sub-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.sub-card-name { font-size: 15px; font-weight: 600; }
.sub-card-profile { font-size: 13px; color: var(--primary-light); }
.sub-card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.sub-card-meta-item label { font-size: 11px; color: var(--text2); display: block; margin-bottom: 2px; }
.sub-card-meta-item span { font-size: 13px; font-weight: 500; }
.sub-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Notification dot ── */
.notif-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warning); display: inline-block; margin-left: 6px;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Login page ── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(139,92,246,0.12) 0%, transparent 60%),
                    radial-gradient(ellipse at 80% 20%, rgba(236,72,153,0.08) 0%, transparent 50%);
}
.login-box {
  width: 100%; max-width: 380px; padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center; margin-bottom: 28px;
}
.login-logo .logo-circle {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 12px;
}
.login-logo h1 { font-size: 20px; font-weight: 700; }
.login-logo p { font-size: 13px; color: var(--text2); }

/* ── Notes textarea ── */
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Section header ── */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.section-title { font-size: 20px; font-weight: 700; }

/* ── Days remaining indicator ── */
.days-chip {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.days-ok { background: rgba(16,185,129,0.1); color: var(--success); }
.days-warn { background: rgba(245,158,11,0.1); color: var(--warning); }
.days-over { background: rgba(239,68,68,0.1); color: var(--danger); }
