/* app.css — Calefaltec v2 — Unified Design System */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── DESIGN TOKENS ─────────────────────────────────────── */
:root {
  /* Colors — unified with PWA */
  --primary:    #2563EB;
  --primary-dk: #1D4ED8;
  --primary-lt: #3B82F6;
  --primary-bg: #EFF6FF;
  --primary-mid:#DBEAFE;
  --orange:     #F97316;
  --orange-bg:  #FFF7ED;
  --green:      #16A34A;
  --green-bg:   #F0FDF4;
  --red:        #DC2626;
  --red-bg:     #FEF2F2;
  --yellow:     #CA8A04;
  --yellow-bg:  #FEFCE8;
  --purple:     #7C3AED;
  --purple-bg:  #EDE9FE;

  /* Neutrals */
  --bg:         #F8FAFC;
  --white:      #FFFFFF;
  --border:     #E2E8F0;
  --border-lt:  #F1F5F9;
  --text:       #1E293B;
  --text2:      #475569;
  --text3:      #94A3B8;

  /* Layout */
  --sidebar:    220px;
  --topbar:     56px;

  /* Shape */
  --r:          8px;
  --r-lg:       12px;

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

/* ── RESET ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar);
  background: var(--white); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 50; overflow-y: auto;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.sidebar-logo {
  padding: 14px 14px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.logo-badge {
  background: linear-gradient(135deg, #2563EB, #1D4ED8);
  color: white; font-weight: 800; font-size: 12.5px; padding: 7px 12px;
  border-radius: 7px; display: inline-block; letter-spacing: -.2px;
}
.logo-sub { font-size: 10px; color: var(--text3); margin-top: 3px; padding-left: 2px; }

.nav-group { padding: 10px 8px 2px; }
.nav-group-label {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text3); padding: 0 8px; margin-bottom: 3px; display: block;
}
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--text2); cursor: pointer;
  transition: all .12s; margin-bottom: 1px; text-decoration: none;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }
.nav-item .ni { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item.disabled { opacity: .4; pointer-events: none; }

.sidebar-user {
  margin-top: auto; padding: 10px 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 9px;
}
.user-av {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-dk));
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white;
}
.user-name { font-size: 12px; font-weight: 600; }
.user-role { font-size: 10.5px; color: var(--text3); }
.logout-btn {
  margin-left: auto; padding: 5px 9px; border: 1px solid var(--border);
  border-radius: 6px; background: none; font-size: 12px; color: var(--text3);
  cursor: pointer; transition: all .12s; min-height: 32px;
}
.logout-btn:hover { background: var(--red-bg); color: var(--red); border-color: #FCA5A5; }

/* ── SIDEBAR OVERLAY (mobile) ─────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 49; cursor: pointer;
}
.sidebar-overlay.open { display: block; }

/* ── HAMBURGER ────────────────────────────────────────── */
.hamburger {
  display: none; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border);
  background: none; font-size: 18px; cursor: pointer; color: var(--text2);
  flex-shrink: 0; transition: all .12s;
}
.hamburger:hover { background: var(--bg); }

/* ── LAYOUT ─────────────────────────────────────────────── */
.main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; background: var(--white);
  border-bottom: 1px solid var(--border); padding: 0 22px;
  height: var(--topbar); display: flex; align-items: center; gap: 10px;
}
.topbar-title { font-size: 15px; font-weight: 700; color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.page { flex: 1; padding: 20px 22px; }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: var(--r); border: none; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
  min-height: 38px; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(37,99,235,.25); }
.btn-primary:hover { background: var(--primary-dk); }
.btn-orange { background: var(--orange); color: white; box-shadow: 0 2px 8px rgba(249,115,22,.2); }
.btn-orange:hover { background: #EA6C0A; }
.btn-green { background: var(--green); color: white; box-shadow: 0 2px 8px rgba(22,163,74,.2); }
.btn-green:hover { background: #15803D; }
.btn-out { background: var(--white); color: var(--text2); border: 1px solid var(--border); }
.btn-out:hover { background: var(--bg); border-color: #CBD5E1; }
.btn-ghost { background: none; color: var(--text3); border: none; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12px; min-height: 32px; }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid #FCA5A5; }
.btn-danger:hover { background: var(--red); color: white; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; justify-content: center; }

/* ── FAB (Floating Action Button, mobile only) ───────── */
.fab {
  display: none;
  position: fixed; bottom: 24px; right: 20px; z-index: 80;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: white;
  border: none; font-size: 26px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(37,99,235,.4);
  align-items: center; justify-content: center;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover { background: var(--primary-dk); box-shadow: 0 6px 20px rgba(37,99,235,.5); }
.fab:active { transform: scale(.93); }

/* ── STATUS BADGES ───────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 12px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.b-gray   { background: #F1F5F9; color: #64748B; }
.b-blue   { background: var(--primary-bg); color: var(--primary); }
.b-green  { background: var(--green-bg); color: var(--green); }
.b-red    { background: var(--red-bg); color: var(--red); }
.b-orange { background: var(--orange-bg); color: var(--orange); }
.b-yellow { background: var(--yellow-bg); color: var(--yellow); }
.b-purple { background: var(--purple-bg); color: var(--purple); }

/* ── CARDS ───────────────────────────────────────────── */
.card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh);
}
.card-pad { padding: 16px 18px; }

/* ── STAT PILLS ──────────────────────────────────────── */
.stat-row {
  display: flex; gap: 8px; overflow-x: auto; margin-bottom: 16px;
  padding-bottom: 2px; scrollbar-width: none;
}
.stat-row::-webkit-scrollbar { display: none; }
.stat-pill {
  flex-shrink: 0; background: var(--white); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 10px 16px; cursor: pointer; transition: all .15s;
  min-width: 120px;
}
.stat-pill:hover { border-color: var(--primary-lt); box-shadow: var(--sh); }
.stat-pill.active { border-color: var(--primary); background: var(--primary-bg); }
.stat-pill .sp-label { font-size: 11px; font-weight: 600; color: var(--text3); margin-bottom: 2px; }
.stat-pill .sp-count { font-size: 20px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-pill .sp-amt { font-size: 10.5px; color: var(--text3); margin-top: 2px; }
.stat-pill.active .sp-label,
.stat-pill.active .sp-amt { color: var(--primary); }
.stat-pill.active .sp-count { color: var(--primary); }

/* ── TABLE ───────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 9px 12px; text-align: left; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; color: var(--text3);
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--white);
}
tbody tr { border-bottom: 1px solid var(--border-lt); transition: background .1s; }
tbody tr:hover { background: #FAFBFF; cursor: pointer; }
tbody tr:nth-child(even) { background: #FAFBFC; }
tbody tr:nth-child(even):hover { background: #FAFBFF; }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 10px 12px; font-size: 13px; }
.td-muted { color: var(--text3); font-size: 12px; }

/* ── FILTERS ─────────────────────────────────────────── */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-input {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r);
  font-size: 13px; outline: none; background: var(--white); color: var(--text);
  transition: border-color .15s; min-height: 38px;
}
.filter-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.filter-search { min-width: 200px; }

/* ── KPI GRID ────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 20px; }
.kpi {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--sh);
  transition: box-shadow .15s;
}
.kpi:hover { box-shadow: var(--sh-md); }
.kpi-icon { font-size: 22px; float: right; }
.kpi-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text3); margin-bottom: 6px;
}
.kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -.5px; color: var(--text); }
.kpi-sub { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ── LOADING STATE ───────────────────────────────────── */
.loading-spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: linear-gradient(90deg, var(--border-lt) 25%, #e8edf2 50%, var(--border-lt) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s infinite;
  border-radius: 4px; display: inline-block;
}
@keyframes skeleton { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── MODAL ───────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  overflow-y: auto; /* scroll the overlay when modal taller than viewport */
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white); border-radius: var(--r-lg); width: 100%;
  max-height: 85vh;
  display: flex; flex-direction: column; /* head/body/foot stack, body scrolls */
  box-shadow: var(--sh-lg);
  transform: translateY(8px); transition: transform .18s;
  flex-shrink: 0; /* don't let overlay flex crush the modal */
}
.overlay.open .modal { transform: translateY(0); }
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 1;
  background: var(--white); border-radius: var(--r-lg) var(--r-lg) 0 0;
  flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  background: none; cursor: pointer; font-size: 15px; color: var(--text3);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; background: var(--bg);
  position: sticky; bottom: 0; z-index: 1;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  flex-shrink: 0;
}

/* ── FORM ────────────────────────────────────────────── */
.form-grid   { display: grid; grid-template-columns: 1fr 1fr;      gap: 10px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr;  gap: 10px; }
.form-1      { grid-template-columns: 1fr; }
.fg { display: flex; flex-direction: column; gap: 3px; }
.fg.full  { grid-column: 1/-1; }
.fg.span2 { grid-column: span 2; }
.fg label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text3);
}
.fc {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--r);
  font-size: 13px; color: var(--text); outline: none; background: var(--white);
  transition: border-color .15s; min-height: 34px;
}
.fc:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea.fc { resize: vertical; min-height: 60px; }
select.fc { appearance: none; -webkit-appearance: none; cursor: pointer; }

/* ── TOAST ───────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 999;
  padding: 12px 18px; border-radius: 10px; font-size: 13px;
  font-weight: 600; color: white; box-shadow: var(--sh-md);
  animation: tIn .2s ease; max-width: 320px;
}
@keyframes tIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }

/* ── UTILS ───────────────────────────────────────────── */
.tr { text-align: right; }
.tc { text-align: center; }
.fw7 { font-weight: 700; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-orange { color: var(--orange); }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text3); }
.empty-state { text-align: center; padding: 52px 24px; color: var(--text3); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-title { font-size: 14px; font-weight: 700; color: var(--text2); margin-bottom: 6px; }
.hidden { display: none !important; }

/* ── SCROLLBAR ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── TABLET (≤1024px) ────────────────────────────────── */
@media(max-width:1024px) {
  :root { --sidebar: 200px; }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
}

/* ── MOBILE (≤767px) ─────────────────────────────────── */
@media(max-width:767px) {
  /* Sidebar: slide-in drawer */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    z-index: 50;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }
  .main { margin-left: 0; }
  .hamburger { display: flex; }

  /* Topbar */
  .topbar { padding: 0 14px; gap: 8px; height: 52px; }
  .topbar-title { font-size: 14px; }
  .topbar-right { gap: 5px; }
  /* Hide text labels in topbar buttons, keep icons only via span.btn-label-hide */
  .btn-label-hide { display: none; }

  /* Buttons */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; padding: 6px 12px; }

  /* Inputs */
  .fc, .filter-input { min-height: 44px; font-size: 14px; }

  /* KPI */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 20px; }

  /* Filters */
  .filters { flex-direction: column; gap: 8px; }
  .filter-search { min-width: 0; width: 100%; }
  .filter-input { width: 100%; }

  /* Stat pills smaller */
  .stat-pill { min-width: 100px; padding: 8px 12px; }
  .stat-pill .sp-count { font-size: 17px; }

  /* Form */
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 0; max-height: 95vh; }
  .overlay .modal { border-radius: 16px 16px 0 0; }
  .modal-head { border-radius: 16px 16px 0 0; }
  .modal-foot { border-radius: 0; }

  /* Tables */
  tbody td { padding: 8px 10px; font-size: 12.5px; }
  thead th { padding: 7px 10px; }

  /* Page padding */
  .page { padding: 14px 14px; }

  /* Two-col dashboard */
  .two-col { grid-template-columns: 1fr !important; }

  /* FAB visible */
  .fab { display: flex; }

  /* Toast bottom safe area */
  .toast { bottom: 16px; right: 14px; left: 14px; max-width: none; text-align: center; }
}

/* ── HIGHLIGHT AFTER SAVE ────────────────────────────── */
.highlight-new {
  animation: highlightFade 2s ease-out;
}
@keyframes highlightFade {
  0%   { background-color: #fef9c3; }
  100% { background-color: transparent; }
}
