/* public/css/app.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f5f5f2;
  --surface:  #ffffff;
  --border:   rgba(0,0,0,.10);
  --border2:  rgba(0,0,0,.17);
  --text:     #1a1a18;
  --muted:    #6b6b67;
  --hint:     #9b9b96;
  --accent:   #1D9E75;
  --accent-dk:#0F6E56;
  --danger:   #A32D2D;
  --warn:     #854F0B;
  --info:     #185FA5;
  --radius:   8px;
  --tbl-head-bg:    #EFF6FF;
  --tbl-row-odd:    #FFFFFF;
  --tbl-row-even:   #F0F7FF;
  --tbl-row-hover:  #DBEAFE;
  --tbl-row-border: rgba(59,130,246,.12);
  --radius-lg:12px;
  --nav-w:    220px;
  --hdr-h:    52px;
  --font: -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#1c1c1a; --surface:#252523; --border:rgba(255,255,255,.10);
    --border2:rgba(255,255,255,.18); --text:#f0f0ec; --muted:#a0a09a;
    --hint:#6a6a65;
    --tbl-head-bg:#1e2a3a; --tbl-row-odd:#1a2332; --tbl-row-even:#1e2a3a;
    --tbl-row-hover:#1e3a5f; --tbl-row-border:rgba(59,130,246,.15);
  }
}
/* Manual dark mode override */
:root[data-theme="dark"] {
  --bg:#1c1c1a; --surface:#252523; --border:rgba(255,255,255,.10);
  --border2:rgba(255,255,255,.18); --text:#f0f0ec; --muted:#a0a09a;
  --hint:#6a6a65;
  --tbl-head-bg:#1e2a3a; --tbl-row-odd:#1a2332; --tbl-row-even:#1e2a3a;
  --tbl-row-hover:#1e3a5f; --tbl-row-border:rgba(59,130,246,.15);
}
/* Manual light mode override (forces light even if OS is dark) */
:root[data-theme="light"] {
  --bg:#f5f5f2; --surface:#ffffff; --border:rgba(0,0,0,.10);
  --border2:rgba(0,0,0,.17); --text:#1a1a18; --muted:#6b6b67;
  --hint:#9b9b96;
  --tbl-head-bg:#EFF6FF; --tbl-row-odd:#FFFFFF; --tbl-row-even:#F0F7FF;
  --tbl-row-hover:#DBEAFE; --tbl-row-border:rgba(59,130,246,.12);
}

body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ── */
#app    { display: flex; height: 100vh; overflow: hidden; }
#main   { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
#content{ flex: 1; overflow-y: auto; padding: 20px; }

/* ── Sidebar ── */
#sidebar {
  width: var(--nav-w); background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.brand { padding: 14px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 32px; height: 32px; background: var(--accent); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.brand-name { font-size: 13px; font-weight: 600; }
.brand-sub  { font-size: 11px; color: var(--muted); }
nav { flex: 1; overflow-y: auto; padding: 6px 0; }
.nav-group { padding: 10px 14px 2px; font-size: 10px; font-weight: 600; color: var(--hint); letter-spacing: .07em; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; cursor: pointer; font-size: 13px;
  color: var(--muted); border-left: 2px solid transparent;
  text-decoration: none; transition: background .1s;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: .7; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); border-left-color: var(--accent); }
.nav-item.active svg { opacity: 1; }
.sidebar-footer { padding: 12px 14px; border-top: 0.5px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 12px; font-weight: 500; }
.user-sub  { font-size: 11px; color: var(--muted); }

/* ── Topbar ── */
#topbar {
  height: var(--hdr-h); background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 10px; flex-shrink: 0;
}
#page-title { font-size: 14px; font-weight: 500; flex: 1; }
.search-wrap { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 5px 10px; width: 210px; }
.search-wrap svg { width: 13px; height: 13px; color: var(--muted); flex-shrink: 0; }
.search-wrap input { background: none; border: none; outline: none; font-size: 13px; color: var(--text); width: 100%; font-family: var(--font); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 14px; border-radius: var(--radius); border: 0.5px solid var(--border2); background: transparent; cursor: pointer; font-size: 13px; color: var(--text); font-family: var(--font); white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.back-btn { padding: 5px 10px; font-size: 12px; }

/* ── Avatar ── */
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #E1F5EE; color: #0F6E56; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

/* ── Cards ── */
.card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 0; }
.card-hdr { padding: 12px 16px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; gap: 8px; }
.card-title { font-size: 13px; font-weight: 500; flex: 1; }
.count-badge { font-size: 11px; color: var(--muted); background: var(--bg); padding: 1px 8px; border-radius: 20px; border: 0.5px solid var(--border); }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--bg); border-radius: var(--radius); padding: 13px; border: 0.5px solid var(--border); }
.stat-label { font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.stat-val   { font-size: 22px; font-weight: 500; }
.stat-sub   { font-size: 11px; color: var(--hint); margin-top: 2px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 9px 14px; text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--tbl-head-bg); letter-spacing: .02em; text-transform: uppercase; }
td { padding: 9px 14px; border-bottom: 0.5px solid var(--tbl-row-border); color: var(--text); font-size: 13px; }
tbody tr:nth-child(odd)  { background: var(--tbl-row-odd); }
tbody tr:nth-child(even) { background: var(--tbl-row-even); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--tbl-row-hover) !important; cursor: pointer; }
.loading { color: var(--muted); font-style: italic; text-align: center; padding: 16px; }
.error-row { color: var(--danger); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.inline-select { font-size: 12px; padding: 2px 4px; border: 0.5px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; max-width: 130px; }
.badge-green  { background: #E1F5EE; color: #0F6E56; }
.badge-amber  { background: #FAEEDA; color: #854F0B; }
.badge-blue   { background: #E6F1FB; color: #185FA5; }
.badge-gray   { background: #F1EFE8; color: #5F5E5A; }
.badge-red    { background: #FCEBEB; color: #A32D2D; }

/* ── Layout helpers ── */
.two-col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 14px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-input { padding: 6px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 13px; font-family: var(--font); width: 200px; }
select { padding: 6px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 13px; font-family: var(--font); }
.check-label { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

/* ── Client Detail ── */
.detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.detail-name   { font-size: 17px; font-weight: 500; }
.detail-meta   { font-size: 13px; color: var(--muted); margin-top: 2px; }
.detail-actions{ margin-left: auto; display: flex; gap: 8px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 0.5px solid var(--border); margin-bottom: 14px; }
.tab { padding: 8px 16px; font-size: 13px; cursor: pointer; color: var(--muted); border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: var(--font); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }
.tab:hover:not(.active) { color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Forms ── */
.form-body   { padding: 16px; }
.form-row    { display: grid; gap: 12px; margin-bottom: 12px; }
.form-row.two   { grid-template-columns: 1fr 1fr; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.fg          { display: flex; flex-direction: column; gap: 4px; }
.fg select   { width: 100%; }
label        { font-size: 12px; color: var(--muted); }
input[type=text], input[type=date], input[type=number], input[type=email], textarea {
  padding: 7px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 13px; font-family: var(--font);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
/* ── Searchable combobox ── */
.combobox { position: relative; }
.combobox-input { width: 100%; }
.combobox-list { position: fixed; z-index: 9999; background: var(--surface); border: 0.5px solid var(--accent); border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0,0,0,0.18); max-height: 220px; overflow-y: auto; }
.combobox-list.hidden { display: none; }
.combobox-list div { padding: 6px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combobox-list div:hover, .combobox-list div.cb-active { background: var(--accent); color: #fff; }
.profile-grid { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 12px; padding: 16px; }
/* Width classes — use on any .fg inside .profile-grid
   w1 = 1/6  w2 = 2/6 (third)  w3 = 3/6 (half, default)
   w4 = 4/6 (two-thirds)  w5 = 5/6  full = full width      */
.profile-grid .fg       { grid-column: span 3; }   /* half by default */
.profile-grid .fg.w1    { grid-column: span 1; }
.profile-grid .fg.w2    { grid-column: span 2; }
.profile-grid .fg.w3    { grid-column: span 3; }   /* same as default */
.profile-grid .fg.w4    { grid-column: span 4; }
.profile-grid .fg.w5    { grid-column: span 5; }
.profile-grid .fg.full  { grid-column: 1 / -1; }  /* full width */
.form-save-row { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 0.5px solid var(--border); }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--surface); border-radius: var(--radius-lg); border: 0.5px solid var(--border); width: 520px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
.modal-wide { width: 900px; }
.modal-hdr { padding: 14px 18px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; }
#modal-title { font-size: 14px; font-weight: 500; flex: 1; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--muted); padding: 0 4px; }
#modal-body  { padding: 16px 18px; }
.modal-footer { padding: 12px 18px; border-top: 0.5px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Login screen ── */
#login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 300;
}
#login-screen.hidden { display: none; }
#app.hidden { display: none !important; }
.login-card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 40px; width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-logo .brand-icon { width: 38px; height: 38px; font-size: 15px; }
.login-logo .brand-name { font-size: 16px; font-weight: 600; }
.login-logo .brand-sub  { font-size: 12px; color: var(--muted); }
.login-card .fg { margin-bottom: 14px; }
.login-card label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.login-error { color: var(--danger); font-size: 12px; margin-bottom: 12px; min-height: 16px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 9px; font-size: 14px; margin-top: 4px; }

/* ── Toast ── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: var(--radius); font-size: 13px; z-index: 200; box-shadow: 0 2px 12px rgba(0,0,0,.2); }
.toast.hidden { display: none; }
.toast.error  { background: var(--danger); }

@media (max-width: 900px) {
  :root { --nav-w: 0px; }
  #sidebar { display: none; }
  .two-col { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-grid .full { grid-column: 1; }
}
