/* ── Lahuen CRM — Design System ──────────────────────────────────────────── */
/* Green cooperative palette, mobile-first, Apple-inspired */

:root {
  /* Spacing */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 40px; --sp-8: 48px;

  /* Typography */
  --text-xs: 11px; --text-sm: 13px; --text-base: 15px; --text-lg: 17px;
  --text-xl: 20px; --text-2xl: 28px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --weight-normal: 400; --weight-medium: 500; --weight-semi: 600;

  /* Colors — Lahuen green */
  --color-bg: #f5f5f7;
  --color-surface: #ffffff;
  --color-text: #1d1d1f;
  --color-secondary: #6e6e73;
  --color-tertiary: #aeaeb2;
  --color-border: rgba(0,0,0,.08);
  --color-border-hover: rgba(0,0,0,.14);

  --color-accent: #16a34a;
  --color-accent-hover: #15803d;
  --color-accent-muted: rgba(22, 163, 74, 0.08);
  --color-accent-pill: rgba(22, 163, 74, 0.12);
  --color-border-focus: rgba(22, 163, 74, 0.40);

  --color-success: #30d158;
  --color-warning: #ff9500;
  --color-danger: #ff3b30;

  /* Radius */
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-xl: 20px;
  --radius-pill: 100px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.06);
}

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

body {
  font-family: var(--font);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* ── Navbar ──────────────────────────────────────────────────────────────── */

.preview-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-5);
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.preview-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-lg);
  font-weight: var(--weight-semi);
  color: var(--color-accent);
  white-space: nowrap;
}
.nav-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
}
.preview-brand span {
  font-weight: var(--weight-medium);
  color: var(--color-secondary);
  font-size: var(--text-base);
  margin-left: 2px;
}

.tab-group { display: flex; gap: var(--sp-1); background: var(--color-bg); border-radius: var(--radius-pill); padding: 3px; }
.tab-btn {
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-secondary);
  cursor: pointer;
  transition: all .2s;
}
.tab-btn.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.page { max-width: 1100px; margin: 0 auto; padding: var(--sp-5) var(--sp-4); }
.page-narrow { max-width: 600px; margin: 0 auto; padding: var(--sp-5) var(--sp-4); }

/* ── Stat Cards ──────────────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-3);
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.stat-label { font-size: var(--text-xs); color: var(--color-secondary); text-transform: uppercase; letter-spacing: .5px; margin-bottom: var(--sp-1); }
.stat-value { font-size: var(--text-2xl); font-weight: var(--weight-semi); }

.text-accent { color: var(--color-accent) !important; }
.text-success { color: var(--color-success) !important; }
.text-warning { color: var(--color-warning) !important; }
.text-danger { color: var(--color-danger) !important; }
.text-secondary { color: var(--color-secondary); }
.text-tertiary { color: var(--color-tertiary); }
.text-title { font-size: var(--text-xl); font-weight: var(--weight-semi); }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 140px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-tertiary); pointer-events: none; }
.search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--text-sm);
  background: var(--color-surface);
  transition: border-color .2s;
}
.search-input:focus { outline: none; border-color: var(--color-border-focus); }

.filter-select {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--text-sm);
  background: var(--color-surface);
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--color-border-focus); }

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}
.badge-neutral { background: rgba(0,0,0,.06); color: var(--color-secondary); }
.badge-success { background: rgba(48,209,88,.12); color: #248a3d; }
.badge-warning { background: rgba(255,149,0,.12); color: #c93400; }
.badge-danger { background: rgba(255,59,48,.12); color: #d70015; }
.badge-info { background: rgba(59,130,246,.12); color: #2563eb; }
.badge-purple { background: rgba(139,92,246,.12); color: #7c3aed; }
.badge-accent { background: var(--color-accent-pill); color: var(--color-accent); }

/* ── Table ───────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table { width: 100%; border-collapse: collapse; }
thead th {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--color-secondary);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
tbody td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-accent-muted); }

.td-name { font-weight: var(--weight-medium); white-space: nowrap; }

.row-overdue {
  background: rgba(255, 149, 0, 0.06) !important;
  border-left: 3px solid var(--color-warning);
}
.row-overdue:hover { background: rgba(255, 149, 0, 0.10) !important; }

.row-faded { opacity: 0.5; }
.row-faded:hover { opacity: 0.75; }

/* ── Row Actions ─────────────────────────────────────────────────────────── */

.row-actions { display: flex; gap: var(--sp-2); align-items: center; }
.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--color-secondary);
  transition: all .15s;
  display: flex;
  align-items: center;
}
.action-btn:hover { background: var(--color-bg); color: var(--color-text); }
.action-btn.wa { color: #25d366; }
.action-btn.wa:hover { background: rgba(37,211,102,.1); }
.action-btn svg { width: 18px; height: 18px; }

/* ── Card / Form ─────────────────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.form-group { display: flex; flex-direction: column; gap: var(--sp-1); }
.form-label { font-size: var(--text-xs); font-weight: var(--weight-semi); color: var(--color-secondary); text-transform: uppercase; letter-spacing: .5px; }
.form-control {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--text-sm);
  background: var(--color-surface);
  transition: border-color .2s;
  width: 100%;
}
.form-control:focus { outline: none; border-color: var(--color-border-focus); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-4 { gap: var(--sp-4); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}
.btn-primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(22,163,74,.25);
}
.btn-primary:hover { background: var(--color-accent-hover); box-shadow: 0 4px 16px rgba(22,163,74,.35); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
}
.btn-secondary:hover { background: var(--color-border-hover); }

.btn-danger { background: rgba(255,59,48,.1); color: var(--color-danger); }
.btn-danger:hover { background: rgba(255,59,48,.18); }

.w-full { width: 100%; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--sp-4);
}
.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--sp-6);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-title { font-size: var(--text-lg); font-weight: var(--weight-semi); margin-bottom: var(--sp-1); }
.modal-subtitle { font-size: var(--text-sm); color: var(--color-secondary); margin-bottom: var(--sp-5); }
.modal-body { display: flex; flex-direction: column; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.modal-footer { display: flex; gap: var(--sp-3); justify-content: flex-end; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
}
.toast {
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: var(--color-text);
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
}
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-accent); }

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

/* ── Status Message ──────────────────────────────────────────────────────── */

.status-msg {
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  text-align: center;
}
.status-msg.loading { color: var(--color-secondary); }
.status-msg.success { color: var(--color-accent); background: var(--color-accent-muted); }
.status-msg.error { color: var(--color-danger); background: rgba(255,59,48,.08); }

/* ── Empty State ─────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--color-tertiary);
}
.empty-state p { font-size: var(--text-sm); margin-top: var(--sp-2); }

/* ── Login ───────────────────────────────────────────────────────────────── */

.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-4);
}
.login-card {
  text-align: center;
  max-width: 360px;
  width: 100%;
}
.login-logo {
  height: 64px;
  width: auto;
  margin-bottom: var(--sp-4);
}
.login-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semi);
  color: var(--color-accent);
  margin-bottom: var(--sp-1);
}
.login-title span {
  font-weight: var(--weight-normal);
  color: var(--color-secondary);
}
.login-subtitle {
  font-size: var(--text-sm);
  color: var(--color-secondary);
  margin-bottom: var(--sp-5);
}
.login-footnote {
  font-size: var(--text-xs);
  color: var(--color-tertiary);
  margin-top: var(--sp-4);
}

/* ── Nav User ────────────────────────────────────────────────────────────── */

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid .stat-card:last-child { grid-column: span 2; }
  .grid-2 { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; }
  .search-wrap { min-width: 100%; }
  .filter-select { width: 100%; }
  .page { padding: var(--sp-4) var(--sp-3); }
  .preview-nav { padding: var(--sp-3) var(--sp-3); }
  .preview-brand span { display: none; }
  .stat-value { font-size: var(--text-xl); }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .modal-box { padding: var(--sp-5); }
}
