/* ================================================================
   CLICKZA — Design System
   Apple / iOS-inspired premium SaaS dashboard
   ================================================================ */

:root {
  --blue: #007AFF;
  --blue-dark: #0060DF;
  --green: #34C759;
  --orange: #FF9500;
  --red: #FF3B30;
  --purple: #AF52DE;
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --text-secondary: #6E6E73;
  --border: #E5E5EA;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 6px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.05);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.10);
  --sidebar-w: 264px;
  --header-h: 68px;
  --transition: 180ms cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; }

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; font-weight: 600; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }

/* ---------------------------------------------------------------
   Layout: sidebar + main
   --------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 24px 24px 16px;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.sidebar-logo span { color: var(--blue); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 12px;
}

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding: 16px 12px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(0,0,0,0.04); }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-item .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-item .nav-label { display: flex; align-items: center; gap: 10px; }

.nav-badge {
  background: rgba(0,0,0,0.06);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}
.nav-item.active .nav-badge { background: rgba(255,255,255,0.25); color: #fff; }
.nav-badge.warn { background: rgba(255,149,0,0.15); color: var(--orange); }
.nav-badge.danger { background: rgba(255,59,48,0.15); color: var(--red); }
.nav-badge.info { background: rgba(175,82,222,0.15); color: var(--purple); }

.sidebar-footer {
  padding: 14px 20px 20px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), #5AC8FA);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px; flex-shrink: 0;
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-h);
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(245,245,247,0.85);
  backdrop-filter: saturate(180%) blur(12px);
  position: sticky;
  top: 0;
  z-index: 90;
  border-bottom: 1px solid var(--border);
}

.content {
  padding: 32px 40px 60px;
  max-width: 1400px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-header .eyebrow {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 4px;
}

/* ---------------------------------------------------------------
   Cards
   --------------------------------------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.card-tight { padding: 16px 18px; }

.grid { display: grid; gap: 18px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12.5px; color: var(--text-secondary); }
.kpi-sub.up { color: var(--green); }
.kpi-sub.down { color: var(--red); }

/* ---------------------------------------------------------------
   Buttons
   --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: rgba(0,0,0,0.05); color: var(--text); }
.btn-secondary:hover { background: rgba(0,0,0,0.08); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--blue); padding: 9px 10px; }
.btn-ghost:hover { background: rgba(0,122,255,0.08); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 8px; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------
   Forms
   --------------------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.form-error { font-size: 12.5px; color: var(--red); margin-top: 4px; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #FBFBFD;
  font-size: 14.5px;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(0,122,255,0.12);
  background: #fff;
}
textarea.input { resize: vertical; min-height: 80px; }

.input-group { position: relative; }
.input-group .input { padding-right: 42px; }
.input-group-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 6px; color: var(--text-secondary);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.strength-bar { display: flex; gap: 4px; margin-top: 8px; }
.strength-bar span { height: 4px; flex: 1; border-radius: 4px; background: var(--border); transition: background var(--transition); }
.strength-label { font-size: 12px; margin-top: 6px; color: var(--text-secondary); }

/* ---------------------------------------------------------------
   Badges
   --------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-active { background: rgba(52,199,89,0.12); color: #248A3D; }
.badge-limited { background: rgba(255,149,0,0.12); color: #B36200; }
.badge-suspended { background: rgba(255,59,48,0.12); color: #D70015; }
.badge-review { background: rgba(175,82,222,0.12); color: #8944AB; }
.badge-cancelled { background: rgba(110,110,115,0.12); color: #6E6E73; }
.badge-default { background: rgba(0,0,0,0.06); color: var(--text-secondary); }

/* ---------------------------------------------------------------
   Tables
   --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; min-width: 720px; background: var(--card); }
table.data-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 12px 16px;
  background: #FAFAFC;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: rgba(0,0,0,0.015); }

/* ---------------------------------------------------------------
   Email accordion
   --------------------------------------------------------------- */
.email-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.email-row:hover { box-shadow: var(--shadow-md); }
.email-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  cursor: pointer;
  flex-wrap: wrap;
}
.email-head-left { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.email-title { font-size: 16px; font-weight: 600; }
.email-meta { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.capacity-pill { display: flex; align-items: center; gap: 8px; }
.capacity-bar { width: 70px; height: 5px; border-radius: 4px; background: var(--border); overflow: hidden; }
.capacity-bar-fill { height: 100%; border-radius: 4px; background: var(--blue); transition: width var(--transition); }
.capacity-bar-fill.full { background: var(--red); }

.email-body {
  border-top: 1px solid var(--border);
  padding: 6px 22px 18px;
  display: none;
}
.email-row.open .email-body { display: block; }
.email-row.open .chevron { transform: rotate(180deg); }
.chevron { transition: transform var(--transition); }

.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 6px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.account-card:last-child { border-bottom: none; }
.account-card-main { min-width: 160px; }
.account-card-name { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.account-card-grid { display: flex; gap: 28px; flex-wrap: wrap; }
.account-stat-label { font-size: 11.5px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.account-stat-value { font-size: 14px; font-weight: 600; margin-top: 2px; }
.account-actions { display: flex; gap: 8px; }

/* ---------------------------------------------------------------
   Progress / spending goal
   --------------------------------------------------------------- */
.goal-progress-track {
  height: 14px;
  background: var(--border);
  border-radius: 20px;
  overflow: hidden;
  margin: 14px 0 10px;
}
.goal-progress-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(90deg, var(--blue), #5AC8FA);
  transition: width 500ms cubic-bezier(.4,0,.2,1);
}
.goal-progress-fill.over { background: linear-gradient(90deg, var(--orange), var(--red)); }
.goal-progress-fill.reached { background: linear-gradient(90deg, var(--green), #30D158); }

/* ---------------------------------------------------------------
   Alerts
   --------------------------------------------------------------- */
.alert-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  border: 1px solid var(--border);
  transition: transform var(--transition);
}
.alert-card:hover { transform: translateX(2px); }
.alert-left { display: flex; align-items: center; gap: 12px; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.alert-danger .alert-dot { background: var(--red); }
.alert-warn .alert-dot { background: var(--orange); }
.alert-info .alert-dot { background: var(--purple); }

/* ---------------------------------------------------------------
   Modal
   --------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 180ms cubic-bezier(.4,0,.2,1);
}
.modal.modal-lg { max-width: 680px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 6px; }

/* ---------------------------------------------------------------
   Toasts
   --------------------------------------------------------------- */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: #1D1D1F; color: #fff; padding: 12px 18px;
  border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  animation: toastIn 220ms cubic-bezier(.4,0,.2,1);
  min-width: 220px;
}
.toast.success { background: #1F4E2C; }
.toast.error { background: #4E1F1F; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------
   Empty / loading states
   --------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; }
.empty-state .btn { margin-top: 16px; }

.skeleton {
  background: linear-gradient(90deg, #ECECEF 25%, #F5F5F7 37%, #ECECEF 63%);
  background-size: 400% 100%;
  animation: skeleton 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------------------------------------------------------------
   Auth pages
   --------------------------------------------------------------- */
.auth-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #F5F5F7 0%, #EDEDF2 100%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
}
.auth-logo { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.auth-logo span { color: var(--blue); }
.auth-title { font-size: 22px; margin-bottom: 6px; }
.auth-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 26px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-secondary); }
.auth-error {
  background: rgba(255,59,48,0.08); color: #D70015;
  padding: 10px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 18px;
}
.auth-success {
  background: rgba(52,199,89,0.08); color: #248A3D;
  padding: 10px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 18px;
}

/* ---------------------------------------------------------------
   Utility
   --------------------------------------------------------------- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.3);
  z-index: 99;
}

/* ---------------------------------------------------------------
   Responsive
   --------------------------------------------------------------- */
@media (max-width: 1024px) {
  .content { padding: 24px 20px 50px; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar.open ~ .sidebar-overlay { display: block; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .content { padding: 18px 14px 40px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  table.data-table { min-width: 620px; }
  .account-card { flex-direction: column; align-items: flex-start; }
  .account-actions { width: 100%; }
  .kpi-value { font-size: 24px; }
}

@media (max-width: 400px) {
  .auth-card { padding: 28px 22px; }
}
