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

:root {
  --bg: #070912;
  --bg-2: #0d111f;
  --panel: #13192b;
  --panel-2: #1b233a;
  --border: #1f2942;
  --text: #f4f6fb;
  --muted: #8b95ad;
  --cyan: #00e5ff;
  --cyan-2: #00b8d4;
  --purple: #8b5cf6;
  --green: #00d084;
  --red: #ff4d6d;
  --amber: #ffcc00;
  --shadow: 0 8px 32px rgba(0,0,0,0.45);
  --radius: 16px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas:
    "header header"
    "nav main";
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* Top bar */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: rgba(7,9,18,0.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.app-header .header-left,
.app-header .header-right { display: flex; align-items: center; gap: 14px; }
.brand-mini { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); text-decoration: none; font-size: 1rem; }
.brand-mini img { height: 26px; width: auto; }
.icon-btn { background: transparent; border: none; color: var(--text); cursor: pointer; padding: 8px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 22px; height: 22px; }

.top-bar-left { display: flex; align-items: center; gap: 16px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.15rem; letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.badge {
  padding: 4px 12px; border-radius: 999px; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  background: rgba(0,229,255,0.12); color: var(--cyan); border: 1px solid rgba(0,229,255,0.2);
}
.badge-paid { background: rgba(0,208,132,0.12); color: var(--green); border-color: rgba(0,208,132,0.25); }
.badge-pending { background: rgba(255,204,0,0.12); color: var(--amber); border-color: rgba(255,204,0,0.25); }
.badge-active { background: rgba(139,149,173,0.12); color: var(--muted); border-color: rgba(139,149,173,0.2); }
.badge-danger { background: rgba(255,77,109,0.12); color: var(--red); border-color: rgba(255,77,109,0.2); }

.top-bar-right { display: flex; align-items: center; gap: 12px; }
.user-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
  font-size: 0.82rem;
}
.user-pill .sep { color: var(--border); }
.user-name { color: var(--text); font-weight: 600; }
.user-role { color: var(--muted); text-transform: capitalize; font-size: 0.75rem; }

/* Side nav */
.side-nav {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  color: var(--muted); font-weight: 500; font-size: 0.92rem;
  cursor: pointer; transition: 0.18s; border: none; background: transparent;
  width: 100%; text-align: left;
  text-decoration: none;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, rgba(0,229,255,0.12), rgba(139,92,246,0.12)); color: var(--cyan); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--red); color: #fff;
  font-size: 0.65rem; font-weight: 800;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

/* Main */
.main { padding: 24px; overflow-y: auto; background: var(--bg); }
.page-title {
  font-size: 1.45rem; font-weight: 700; margin: 0 0 20px 0;
  letter-spacing: -0.5px;
}
.page-sub {
  color: var(--muted); font-size: 0.92rem; margin-top: -14px; margin-bottom: 24px;
}
.page-title-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-title-row .page-title { margin: 0; }

/* Hero summary */
.hero-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 28px;
}
.hero-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.hero-card::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at top right, rgba(0,229,255,0.08), transparent 60%);
}
.hero-label { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.hero-value { font-size: 1.8rem; font-weight: 800; margin: 0; letter-spacing: -1px; }
.hero-sub { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }

/* Progress ring */
.ring-wrap {
  display: flex; align-items: center; gap: 16px;
}
.ring {
  width: 64px; height: 64px; border-radius: 50%;
  background: conic-gradient(var(--cyan) var(--pct), var(--panel-2) var(--pct));
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ring::after {
  content: ''; width: 50px; height: 50px; border-radius: 50%;
  background: var(--panel); position: absolute;
}
.ring-text {
  position: relative; z-index: 1;
  font-size: 0.8rem; font-weight: 700; color: var(--cyan);
}

/* Cards grid */
.grid-5, .grid-4, .grid-3, .grid-2 {
  display: grid; gap: 16px; margin-bottom: 24px;
}
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-1 { display: grid; gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.card:hover { transform: translateY(-2px); }
.card-title { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin: 0 0 10px; }
.card-value { font-size: 1.45rem; font-weight: 800; margin: 0; letter-spacing: -0.5px; }
.card-value.small { font-size: 1.15rem; }
.card-sub { font-size: 0.78rem; color: var(--muted); margin: 8px 0 0; }
.card-primary { border-color: rgba(0,229,255,0.3); }
.card-success { border-color: rgba(0,208,132,0.3); }
.card-danger { border-color: rgba(255,77,109,0.3); }
.card-amber { border-color: rgba(255,204,0,0.3); }

/* Sections */
.detail-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.detail-section h3 { margin: 0 0 18px; font-size: 1.05rem; font-weight: 700; }
.detail-section h4 { margin: 0 0 12px; font-size: 0.95rem; font-weight: 700; color: var(--text); }
.section-sub { color: var(--muted); font-size: 0.85rem; margin: -12px 0 18px; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 680px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0,229,255,0.03); }
.money-positive { color: var(--green); font-weight: 700; }
.money-negative { color: var(--red); font-weight: 700; }

/* Buttons */
.btn {
  padding: 10px 16px; border-radius: 10px; border: none; cursor: pointer;
  font-weight: 600; font-size: 0.82rem; transition: 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: linear-gradient(135deg, var(--cyan), var(--cyan-2)); color: #000; }
.btn-success { background: linear-gradient(135deg, var(--green), #00b86b); color: #000; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 7px 12px; font-size: 0.75rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Form */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
input, select, textarea {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; color: var(--text); font-size: 0.92rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cyan); }
textarea { min-height: 80px; resize: vertical; }

/* Modal */
.modal {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  align-items: center; justify-content: center;
}
.modal:not(.hidden) { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.75);
}
.modal-card {
  position: relative; z-index: 1;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: min(800px, 94vw); max-height: 92vh; overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
}
.modal-card.modal-sm { width: min(440px, 94vw); }
.modal-card.modal-lg { width: min(960px, 96vw); }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin: -28px -28px 24px; padding: 22px 28px;
  background: linear-gradient(135deg, rgba(0,229,255,0.08), rgba(139,92,246,0.08));
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.modal-header h3 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.modal-header .modal-close {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 1.1rem;
}
.modal-header .modal-close:hover { color: var(--text); border-color: var(--cyan); }
.modal-body { display: flex; flex-direction: column; gap: 18px; }
.modal-section-title {
  font-size: 0.72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px;
  margin: 6px 0 -8px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; padding-top: 18px; border-top: 1px solid var(--border); }
.toggle-row { display: flex; align-items: center; gap: 14px; }
.toggle-row label { margin: 0; }
.switch {
  position: relative; display: inline-block; width: 44px; height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: var(--panel-2); border-radius: 999px;
  transition: .2s; border: 1px solid var(--border);
}
.slider::before {
  position: absolute; content: ''; height: 18px; width: 18px; left: 2px; bottom: 2px;
  background: var(--muted); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: rgba(0,229,255,0.2); border-color: var(--cyan); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--cyan); }
.form-hint { font-size: 0.75rem; color: var(--muted); margin-top: -4px; }
.input-premium {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; color: var(--text); font-size: 0.95rem; transition: 0.15s;
}
.input-premium:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(0,229,255,0.08); }
.btn-glow {
  box-shadow: 0 4px 18px rgba(0,229,255,0.25);
}
.btn-glow:hover {
  box-shadow: 0 6px 24px rgba(0,229,255,0.4);
  transform: translateY(-1px);
}
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover { border-color: var(--cyan); color: var(--cyan); }

.client-detail .detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.client-detail .detail-header h2 { margin: 0; }
.client-detail .detail-header p { margin: 4px 0 0; color: var(--muted); }
.client-detail .detail-notes { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 18px; color: var(--text); }
.client-detail .month-block { margin: 14px 0 8px; color: var(--muted); font-size: 0.9rem; }
.client-detail table { font-size: 0.82rem; }

/* Login */
.login-screen {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 0%, rgba(0,229,255,0.12), transparent 55%), var(--bg);
}
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 0%, rgba(0,229,255,0.1), transparent 50%);
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 36px; width: min(400px, 92vw); box-shadow: var(--shadow);
}
.login-card h2 { margin-top: 0; font-size: 1.5rem; }
.login-card .brand { font-size: 1.4rem; margin-bottom: 8px; }
.error-text { color: var(--red); font-size: 0.88rem; }
.empty { color: var(--muted); font-style: italic; padding: 20px 0; }
.empty-guide { background: var(--panel-2); border-radius: 10px; padding: 14px; margin-top: 8px; color: var(--muted); font-size: 0.82rem; }

/* Status chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.chip-active { background: rgba(0,208,132,0.12); color: var(--green); }
.chip-active::before { background: var(--green); box-shadow: 0 0 8px var(--green); }
.chip-pending { background: rgba(255,204,0,0.12); color: var(--amber); }
.chip-pending::before { background: var(--amber); }
.chip-expired { background: rgba(255,77,109,0.12); color: var(--red); }
.chip-expired::before { background: var(--red); }
.chip-other { background: rgba(139,149,173,0.12); color: var(--muted); }

/* Timeline / activity */
.timeline { display: flex; flex-direction: column; gap: 14px; }
.timeline-item {
  display: grid; grid-template-columns: 80px 1fr auto;
  gap: 16px; align-items: center;
  padding: 12px 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--border);
}
.timeline-item .date { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.timeline-item .body { display: flex; flex-direction: column; gap: 2px; }
.timeline-item .title { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.timeline-item .meta { font-size: 0.75rem; color: var(--muted); }
.timeline-item .amount { font-weight: 800; font-size: 0.95rem; text-align: right; }

/* Alerts dashboard */
.alert-banner {
  background: rgba(255,77,109,0.08); border: 1px solid rgba(255,77,109,0.2);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 20px;
  display: flex; align-items: center; gap: 12px;
}
.alert-banner.amber { background: rgba(255,204,0,0.08); border-color: rgba(255,204,0,0.2); }
.alert-banner svg { width: 20px; height: 20px; color: var(--red); flex-shrink: 0; }
.alert-banner.amber svg { color: var(--amber); }

/* Utilities */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-muted { color: var(--muted); }

/* Mobile */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 64px 1fr; grid-template-areas: "header" "main"; }
  .side-nav { display: none; position: fixed; inset: 64px 0 0 0; z-index: 90; width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .side-nav.open { display: flex; }
  .hero-row { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .timeline-item { grid-template-columns: 70px 1fr; }
  .timeline-item .amount { text-align: left; grid-column: 2; }
}
@media (max-width: 560px) {
  .main { padding: 12px; }
  .hero-row { grid-template-columns: 1fr; }
  .grid-5, .grid-4 { grid-template-columns: 1fr; }
  .hero-value { font-size: 1.45rem; }
  .user-pill { display: none; }
  .app-header { padding: 0 14px; }
  .detail-section { padding: 16px; border-radius: 14px; margin-bottom: 16px; }
  .detail-section h3 { font-size: 1rem; }

  /* Stack tables as cards */
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td { display: block; width: 100%; }

  .table-wrap thead tr { display: none; }

  .table-wrap tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    padding: 14px;
    margin-bottom: 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
  }

  .table-wrap td {
    padding: 0;
    border-bottom: none;
    font-size: 0.85rem;
  }

  .table-wrap td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
  }

  /* First cell (client name / main label) full width */
  .table-wrap td:first-child {
    grid-column: 1 / -1;
    font-size: 1rem;
  }

  /* When only one column of data */
  .table-wrap tr:only-child td,
  .table-wrap td:only-child { grid-column: 1 / -1; }

  /* Make buttons bigger for touch */
  .btn { padding: 12px 16px; font-size: 0.9rem; min-height: 40px; }
  .btn-sm { padding: 10px 14px; font-size: 0.85rem; min-height: 38px; }

  /* Modal full screen-ish */
  .modal-card { width: 96vw; padding: 20px; border-radius: 14px; }
  .modal-header { margin: -20px -20px 18px; padding: 16px 20px; }

  /* Header */
  .icon-btn { padding: 10px; }
  .icon-btn svg { width: 24px; height: 24px; }
  .brand-mini span { display: none; }
}
@media (max-width: 380px) {
  .main { padding: 10px; }
  .detail-section { padding: 14px; }
  .table-wrap tr { grid-template-columns: 1fr; }
}
