/* =====================================================
   CSS RESET & BASE
===================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 16px; }
body { min-height: 100vh; background-color: var(--background); color: var(--foreground); transition: background-color 0.2s, color 0.2s; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* =====================================================
   DESIGN TOKENS — LIGHT (default)
===================================================== */
:root {
  --radius: 0.875rem;
  --background: oklch(0.985 0.005 95);
  --foreground: oklch(0.18 0.02 260);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.18 0.02 260);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.18 0.02 260);
  --primary: oklch(0.7 0.18 55);
  --primary-foreground: oklch(0.15 0.02 60);
  --secondary: oklch(0.95 0.01 95);
  --secondary-foreground: oklch(0.2 0.02 260);
  --muted: oklch(0.95 0.01 95);
  --muted-foreground: oklch(0.5 0.02 260);
  --accent: oklch(0.93 0.05 60);
  --accent-foreground: oklch(0.2 0.02 260);
  --destructive: oklch(0.6 0.22 25);
  --destructive-foreground: oklch(0.98 0 0);
  --border: oklch(0.9 0.01 95);
  --input: oklch(0.92 0.01 95);
  --ring: oklch(0.7 0.18 55);
  --success: oklch(0.65 0.18 145);
  --success-foreground: oklch(0.15 0.02 145);
  --warning: oklch(0.78 0.16 70);
  --warning-foreground: oklch(0.18 0.02 70);
  --danger: oklch(0.62 0.23 25);
  --danger-foreground: oklch(0.98 0 0);
  --gradient-primary: linear-gradient(135deg, oklch(0.72 0.18 55), oklch(0.78 0.16 35));
}

/* =====================================================
   DESIGN TOKENS — DARK
===================================================== */
html.dark {
  --background: oklch(0.16 0.015 260);
  --foreground: oklch(0.96 0.005 95);
  --card: oklch(0.21 0.02 260);
  --card-foreground: oklch(0.96 0.005 95);
  --popover: oklch(0.21 0.02 260);
  --popover-foreground: oklch(0.96 0.005 95);
  --primary: oklch(0.78 0.17 65);
  --primary-foreground: oklch(0.18 0.02 60);
  --secondary: oklch(0.27 0.02 260);
  --secondary-foreground: oklch(0.96 0.005 95);
  --muted: oklch(0.27 0.02 260);
  --muted-foreground: oklch(0.72 0.02 260);
  --accent: oklch(0.32 0.06 60);
  --accent-foreground: oklch(0.96 0.005 95);
  --destructive: oklch(0.68 0.22 25);
  --destructive-foreground: oklch(0.98 0 0);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 12%);
  --ring: oklch(0.78 0.17 65);
  --success: oklch(0.7 0.18 145);
  --success-foreground: oklch(0.14 0.02 145);
  --warning: oklch(0.8 0.17 75);
  --warning-foreground: oklch(0.16 0.02 70);
  --danger: oklch(0.68 0.22 25);
  --danger-foreground: oklch(0.98 0 0);
  --gradient-primary: linear-gradient(135deg, oklch(0.78 0.17 65), oklch(0.7 0.2 35));
}

/* =====================================================
   UTILS
===================================================== */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-primary { color: var(--primary); }
.mt-4 { margin-top: 1rem; }
.w-full { width: 100%; }

/* =====================================================
   CARD
===================================================== */
.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* =====================================================
   BUTTONS
===================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  border: none; border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem; font-weight: 500;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.88; }
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--gradient-primary); color: var(--primary-foreground); }
.btn-outline {
  background: transparent; color: var(--foreground);
  border: 1px solid var(--border);
}
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--muted); opacity: 1; }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-sm { height: 2.25rem; padding: 0 0.75rem; font-size: 0.8125rem; }
.btn-md { height: 2.75rem; padding: 0 1rem; }
.btn-lg { height: 3rem; padding: 0 1.25rem; font-size: 1rem; }
.btn-icon { width: 2.5rem; height: 2.5rem; padding: 0; border-radius: 0.5rem; }

/* =====================================================
   INPUT / SELECT / TEXTAREA
===================================================== */
.input {
  width: 100%;
  height: 2.75rem;
  padding: 0 0.875rem;
  background: var(--input);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px oklch(from var(--ring) l c h / 20%);
}
.select-el { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2.25rem; }
.textarea { height: auto; padding: 0.625rem 0.875rem; resize: vertical; }

/* =====================================================
   ICONS
===================================================== */
.icon-xs { width: 0.75rem; height: 0.75rem; }
.icon-sm { width: 1rem; height: 1rem; }
.icon-md { width: 1.25rem; height: 1.25rem; }
.icon-lg { width: 1.5rem; height: 1.5rem; }
svg { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* =====================================================
   SCREENS
===================================================== */
.screen { min-height: 100vh; }

/* =====================================================
   LOGIN
===================================================== */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; position: relative; overflow: hidden;
}
.login-bg-blob {
  position: absolute; inset: 0; pointer-events: none;
  background: var(--gradient-primary); opacity: 0.25; filter: blur(120px);
}
.login-card {
  width: 100%; max-width: 28rem; position: relative;
  padding: 2rem; box-shadow: 0 25px 60px -20px oklch(0.7 0.18 55 / 0.3);
}
.login-header {
  text-align: center; margin-bottom: 1.5rem; display: flex;
  flex-direction: column; align-items: center; gap: 0.5rem;
}
.logo-badge {
  width: 3.5rem; height: 3.5rem; border-radius: 1rem;
  background: var(--gradient-primary); color: var(--primary-foreground);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700;
}
.login-title { font-size: 1.5rem; font-weight: 700; }
.login-sub { font-size: 0.875rem; color: var(--muted-foreground); }
.login-body { display: flex; flex-direction: column; gap: 0.875rem; }
.login-hint { font-size: 0.75rem; color: var(--muted-foreground); text-align: center; }
.login-hint code { background: var(--muted); padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.75rem; }

/* =====================================================
   HEADER
===================================================== */
.app-header {
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  background: oklch(from var(--background) l c h / 80%);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 90rem; margin: 0 auto; padding: 0.75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.header-brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.logo-badge-sm {
  width: 2.5rem; height: 2.5rem; border-radius: 0.75rem; flex-shrink: 0;
  background: var(--gradient-primary); color: var(--primary-foreground);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.125rem; font-weight: 700;
}
.header-title { font-size: 1.125rem; font-weight: 600; }
.header-sub { font-size: 0.75rem; color: var(--muted-foreground); display: none; }
@media (min-width: 640px) { .header-sub { display: block; } }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }

/* =====================================================
   MAIN
===================================================== */
.main-content {
  max-width: 90rem; margin: 0 auto;
  padding: 1.5rem 1rem 6rem;
  display: flex; flex-direction: column; gap: 1.5rem;
}
@media (min-width: 640px) { .main-content { padding: 1.5rem 1.5rem 6rem; } }

/* =====================================================
   STATS GRID
===================================================== */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
}
@media (min-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; }
}
.stat-card {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.stat-icon-wrap {
  width: 2.75rem; height: 2.75rem; border-radius: 0.75rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon-primary { background: oklch(from var(--primary) l c h / 15%); color: var(--primary); }
.stat-icon-success { background: oklch(from var(--success) l c h / 15%); color: var(--success); }
.stat-icon-warning { background: oklch(from var(--warning) l c h / 15%); color: var(--warning); }
.stat-icon-danger  { background: oklch(from var(--danger) l c h / 15%); color: var(--danger); }
.stat-label { font-size: 0.75rem; color: var(--muted-foreground); }
.stat-value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (min-width: 640px) { .stat-value { font-size: 1.75rem; } }

/* =====================================================
   REMINDERS
===================================================== */
.reminders-grid { display: grid; gap: 1rem; }
@media (min-width: 768px) { .reminders-grid { grid-template-columns: repeat(2, 1fr); } }
.reminder-card { border-left: 4px solid; }
.reminder-card.reminder-danger { border-left-color: var(--danger); }
.reminder-card.reminder-warning { border-left-color: var(--warning); }
.reminder-header { padding: 1rem 1.25rem 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.reminder-header-title { font-size: 0.9375rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.reminder-body { padding: 0 1.25rem 1rem; display: flex; flex-direction: column; gap: 0; }
.reminder-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}
.reminder-row:last-child { border-bottom: none; }
.reminder-name { font-weight: 500; font-size: 0.9375rem; }
.reminder-meta { font-size: 0.75rem; color: var(--muted-foreground); }
.reminder-more { font-size: 0.75rem; color: var(--muted-foreground); padding-top: 0.5rem; }

/* =====================================================
   BADGE (pill)
===================================================== */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.125rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 500;
  background: var(--secondary); color: var(--secondary-foreground);
}
.status-badge { padding: 0.25rem 0.625rem; border-radius: 0.375rem; font-size: 0.75rem; font-weight: 500; }
.status-paid     { background: var(--success); color: var(--success-foreground); }
.status-due-soon { background: var(--warning); color: var(--warning-foreground); }
.status-overdue  { background: var(--danger); color: var(--danger-foreground); }
.status-cancelled{ background: var(--muted); color: var(--muted-foreground); }

/* =====================================================
   TOOLBAR
===================================================== */
.toolbar {
  display: flex; flex-direction: column; gap: 0.75rem;
}
@media (min-width: 640px) {
  .toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
}
.toolbar-left { display: flex; flex-direction: column; gap: 0.75rem; flex: 1; }
@media (min-width: 640px) {
  .toolbar-left { flex-direction: row; max-width: 36rem; }
}
.toolbar-right { display: flex; gap: 0.5rem; }
.search-wrap { position: relative; flex: 1; }
.search-icon {
  position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground); pointer-events: none;
}
.search-input-el { padding-left: 2.25rem; }
.select-wrap { width: 100%; }
@media (min-width: 640px) { .select-wrap { width: 11rem; flex-shrink: 0; } }

/* =====================================================
   MOBILE CARDS
===================================================== */
.mobile-cards { display: flex; flex-direction: column; gap: 0.75rem; }
@media (min-width: 640px) { .mobile-cards { display: none; } }

.cust-card { padding: 1rem; }
.cust-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }
.cust-card-name { font-weight: 600; }
.cust-card-user { font-size: 0.875rem; color: var(--muted-foreground); }
.cust-card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; font-size: 0.875rem; margin-bottom: 0.75rem; }
.cust-meta-label { font-size: 0.6875rem; color: var(--muted-foreground); }
.cust-meta-val { font-weight: 500; font-variant-numeric: tabular-nums; }
.cust-notes { font-size: 0.75rem; color: var(--muted-foreground); background: var(--muted); border-radius: 0.375rem; padding: 0.5rem; margin-bottom: 0.75rem; }
.cust-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

/* =====================================================
   DESKTOP TABLE
===================================================== */
.hidden-mobile { display: none; }
@media (min-width: 640px) { .hidden-mobile { display: block; } }

.desktop-table-wrap { overflow: hidden; }
.table-scroll { overflow-x: auto; }
.cust-table { width: 100%; font-size: 0.875rem; border-collapse: collapse; }
.cust-table thead { background: oklch(from var(--muted) l c h / 50%); color: var(--muted-foreground); }
.cust-table th {
  padding: 0.75rem 1rem; text-align: left;
  font-size: 0.6875rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em;
}
.cust-table td { padding: 0.75rem 1rem; vertical-align: top; }
.cust-table tr { border-top: 1px solid var(--border); }
.cust-table tbody tr { transition: background 0.1s; }
.cust-table tbody tr:hover { background: oklch(from var(--muted) l c h / 30%); }
.cust-name { font-weight: 500; }
.cust-username { font-size: 0.75rem; color: var(--muted-foreground); }
.cust-note-cell { font-size: 0.75rem; color: var(--muted-foreground); margin-top: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.row-actions { display: inline-flex; gap: 0.375rem; }

/* =====================================================
   EMPTY STATE
===================================================== */
.empty-state { padding: 2.5rem; text-align: center; }
.empty-icon-wrap {
  width: 3.5rem; height: 3.5rem; border-radius: 1rem;
  background: oklch(from var(--primary) l c h / 15%); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem;
}
.empty-title { font-size: 1.125rem; font-weight: 600; }
.empty-sub { font-size: 0.875rem; color: var(--muted-foreground); margin-top: 0.25rem; }

/* =====================================================
   FOOTER
===================================================== */
.page-footer { text-align: center; font-size: 0.75rem; color: var(--muted-foreground); padding-top: 2rem; }
.footer-link { color: var(--primary); display: inline-flex; align-items: center; gap: 0.25rem; }

/* =====================================================
   MODAL
===================================================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: oklch(0 0 0 / 50%);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-card {
  width: 100%; max-width: 32rem;
  max-height: 90vh; overflow-y: auto;
  padding: 1.5rem;
}
.modal-header { margin-bottom: 1rem; }
.modal-title { font-size: 1.125rem; font-weight: 600; }
.modal-sub { font-size: 0.875rem; color: var(--muted-foreground); margin-top: 0.25rem; }
.modal-body { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }
.modal-footer { display: flex; gap: 0.5rem; justify-content: flex-end; }

.field-group { display: flex; flex-direction: column; gap: 0.5rem; }
.field-label { font-size: 0.875rem; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* =====================================================
   TOAST
===================================================== */
.toast-container {
  position: fixed; top: 1rem; right: 1rem; z-index: 100;
  display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem; font-weight: 500;
  box-shadow: 0 4px 20px oklch(0 0 0 / 15%);
  animation: toast-in 0.2s ease;
  max-width: 20rem;
}
.toast-success { background: var(--success); color: var(--success-foreground); }
.toast-error { background: var(--danger); color: var(--danger-foreground); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-0.5rem); }
  to   { opacity: 1; transform: translateY(0); }
}
