/* =====================================================
   ERP Design System
   Palette: slate/teal primary, clean whites, precise
   type scale. Signature: teal accent on a slate sidebar.
   ===================================================== */

/* ---- tokens ---- */
:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-surface2: #f0f4f8;
  --color-border: #e2e8f0;
  --color-text: #1a202c;
  --color-text-muted: #718096;
  --color-primary: #0b6e61;
  --color-primary-h: #0d8a79;
  --color-primary-light: #e6f4f2;
  --color-danger: #dc2626;
  --color-danger-light: #fef2f2;
  --color-success: #059669;
  --color-success-light: #ecfdf5;
  --color-warn: #d97706;
  --color-warn-light: #fffbeb;
  --color-info: #2563eb;
  --sidebar-bg: #1a2433;
  --sidebar-text: #a0aec0;
  --sidebar-active-bg: #0b6e61;
  --sidebar-active-text: #ffffff;
  --sidebar-hover-bg: rgba(255,255,255,.06);
  --sidebar-width: 220px;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Consolas, monospace;
}

[data-theme="dark"] {
  --color-bg: #0f1117;
  --color-surface: #1a1f2e;
  --color-surface2: #232940;
  --color-border: #2d3748;
  --color-text: #e2e8f0;
  --color-text-muted: #718096;
  --sidebar-bg: #111827;
  --color-primary-light: rgba(11,110,97,.2);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; height: 100%; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- layout shell ---- */
#app { display: flex; height: 100%; overflow: hidden; }

/* ---- sidebar ---- */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .2s;
  z-index: 200;
}

#sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
#sidebar-logo {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  letter-spacing: .3px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sidebar-company {
  font-size: 11.5px;
  color: var(--sidebar-text);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar-nav { flex: 1; padding: 8px 0; }
.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #4a5568;
  padding: 10px 16px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  cursor: pointer;
  border-radius: 0;
  transition: background .15s, color .15s;
  font-size: 13.5px;
  white-space: nowrap;
  user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: #fff; }
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}
.nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }

#sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 8px;
}
#sync-indicator {
  font-size: 11px;
  color: var(--sidebar-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: #4a5568;
}
.sync-dot.online { background: var(--color-success); }
.sync-dot.syncing { background: var(--color-warn); animation: pulse .9s infinite; }
.sync-dot.error { background: var(--color-danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

#user-btn {
  background: none; border: none; cursor: pointer;
  color: var(--sidebar-text); font-size: 12px;
  padding: 4px 6px; border-radius: var(--radius-sm);
  transition: background .15s;
}
#user-btn:hover { background: var(--sidebar-hover-bg); color: #fff; }

/* ---- main content ---- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  height: 50px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
#hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--color-text-muted);
  padding: 4px;
}
#breadcrumb { font-size: 13px; color: var(--color-text-muted); flex: 1; }
#topbar-right { display: flex; align-items: center; gap: 12px; }
#topbar-company { font-size: 12px; font-weight: 600; color: var(--color-primary); }
#topbar-user { font-size: 12px; color: var(--color-text-muted); }

#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px 24px;
}

/* ---- page header ---- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.page-head h2 { font-size: 20px; font-weight: 700; color: var(--color-text); }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-desc { font-size: 13px; color: var(--color-text-muted); margin-bottom: 14px; line-height: 1.5; }
.section-title { font-size: 13px; font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .5px; margin: 18px 0 8px; }
.section-title:first-of-type { margin-top: 0; }
.dash-clock {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12.5px; color: var(--color-text-muted);
  background: var(--color-surface2); border-radius: 8px; padding: 6px 12px;
}
.dash-clock-date { font-weight: 600; }
.dash-clock-time { font-variant-numeric: tabular-nums; color: var(--color-primary); font-weight: 700; }

/* ── Sticky Notes ── */
.sticky-notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sticky-note {
  position: relative; border-radius: 6px; padding: 10px 10px 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); min-height: 100px;
}
.sticky-note textarea {
  width: 100%; height: 84px; border: none; background: transparent; resize: none;
  font-family: inherit; font-size: 12.5px; color: #2a2a2a; line-height: 1.5;
}
.sticky-note textarea:focus { outline: none; }
.sticky-note-del {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
  border: none; background: rgba(0,0,0,.08); border-radius: 50%; cursor: pointer;
  font-size: 11px; line-height: 1; color: #444;
}
.sticky-note-del:hover { background: rgba(0,0,0,.18); }

/* ── Calendar ── */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid-head { margin-bottom: 4px; text-align: center; font-size: 11px; font-weight: 700; color: var(--color-text-muted); }
.cal-cell {
  min-height: 62px; border: 1px solid var(--color-border); border-radius: 6px;
  padding: 4px; cursor: pointer; background: var(--color-surface);
}
.cal-cell:hover { background: var(--color-surface2); }
.cal-cell.cal-empty { border: none; cursor: default; background: transparent; }
.cal-cell.cal-empty:hover { background: transparent; }
.cal-cell.cal-today { border-color: var(--color-primary); border-width: 2px; }
.cal-daynum { font-size: 12px; font-weight: 700; margin-bottom: 3px; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; font-size: 11px; }
.cal-more { font-size: 10px; color: var(--color-text-muted); }

/* ---- filters row ---- */
.filters-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.search-box {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 13px;
  background: var(--color-surface);
  color: var(--color-text);
  min-width: 200px;
  outline: none;
  transition: border-color .15s;
}
.search-box:focus { border-color: var(--color-primary); }
.filters-row select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 13px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

/* ---- card ---- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card h3 { font-size: 14px; font-weight: 700; margin-bottom: 12px; color: var(--color-text); }

/* ---- table ---- */
.table-scroll { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  padding: 9px 10px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-surface2);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-surface2); }
.data-table tfoot td {
  border-top: 2px solid var(--color-border);
  font-weight: 600;
  padding-top: 10px;
}
.active-row { background: var(--color-primary-light) !important; }
.row-actions { display: flex; gap: 4px; flex-wrap: nowrap; }

/* ---- icon buttons ---- */
.icon-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-muted);
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
}
.icon-btn:hover { background: var(--color-surface2); color: var(--color-text); }
.icon-btn.danger:hover { background: var(--color-danger-light); color: var(--color-danger); border-color: var(--color-danger); }

/* ---- buttons ---- */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-h); }
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: var(--color-surface2); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }

/* ---- forms ---- */
.erp-form { display: contents; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 16px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row.full { grid-column: 1 / -1; }
.form-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: .2px;
}
.form-row input,
.form-row select,
.form-row textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13.5px;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.form-row input[type="checkbox"] { width: auto; }

/* ---- modal ---- */
.erp-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 9000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 30px 12px;
}
.erp-modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  animation: modalIn .18s ease;
  min-height: 0; /* without this, nested flex children refuse to shrink
                    on mobile WebKit and the body never becomes
                    scrollable — this was the actual "can't finger-
                    scroll, have to rotate" bug */
}
.erp-modal.large { max-width: 820px; }
.erp-modal.small { max-width: 380px; }
@keyframes modalIn { from{opacity:0;transform:translateY(-12px)} to{opacity:1;transform:none} }
.erp-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.erp-modal-head h3 { font-size: 15px; font-weight: 700; }
.erp-modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--color-text-muted);
  line-height: 1; padding: 2px 4px;
}
.erp-modal-body {
  padding: 18px; display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  flex: 1 1 auto;
}
.erp-modal-body .form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; }
.erp-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---- line-items table ---- */
.li-table input { padding: 5px 7px; font-size: 13px; }
.li-table select { padding: 5px 7px; font-size: 13px; }
.li-name { display: block; margin-top: 4px; width: 100%; }
.li-product-cell { position: relative; min-width: 190px; }
.li-product-inputwrap { display: flex; gap: 4px; align-items: stretch; }
.li-product-search { flex: 1; min-width: 0; }
.li-product-browse {
  flex-shrink: 0; width: 26px; border: 1px solid var(--color-border);
  border-radius: 6px; background: var(--color-surface2); cursor: pointer;
  font-size: 11px; color: var(--color-text-muted);
}
.li-product-browse:hover { background: var(--color-border); }
.li-product-dd {
  position: fixed; z-index: 9999;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.18);
  max-height: 240px; overflow-y: auto;
}
.li-product-opt { padding: 7px 10px; font-size: 12.5px; cursor: pointer; }
.li-product-opt:hover, .li-product-opt.active { background: var(--color-surface2); }
.li-product-empty { padding: 8px 10px; font-size: 12px; color: var(--color-text-muted); }

.row-action-menu {
  position: fixed; z-index: 9999; min-width: 190px;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 8px; box-shadow: 0 8px 22px rgba(0,0,0,.18);
  padding: 5px; display: flex; flex-direction: column;
}
.ram-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left; background: none; border: none;
  padding: 8px 10px; font-size: 13px; border-radius: 6px; cursor: pointer;
  color: var(--color-text);
}
.ram-item:hover { background: var(--color-surface2); }
.ram-item.danger { color: var(--color-danger); }
.ram-item.danger:hover { background: var(--color-danger-light); }
.ram-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
.ram-divider { height: 1px; background: var(--color-border); margin: 4px 2px; }
.row-menu-btn {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--color-border);
  background: var(--color-surface); cursor: pointer; font-size: 15px; font-weight: 700;
  color: var(--color-text-muted); line-height: 1;
}
.row-menu-btn:hover { background: var(--color-surface2); color: var(--color-text); }

/* ---- totals box ---- */
.totals-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 12px 16px;
  background: var(--color-surface2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 10px;
}
.totals-box div { display: flex; gap: 24px; justify-content: flex-end; min-width: 240px; }
.totals-box span { color: var(--color-text-muted); }
.totals-box .grand { border-top: 1px solid var(--color-border); padding-top: 6px; font-size: 15px; }

/* ---- badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); }
.badge-warn { background: var(--color-warn-light); color: var(--color-warn); }
.badge-muted { background: var(--color-surface2); color: var(--color-text-muted); }
.role-admin { background: #fce7f3; color: #be185d; }
.role-manager { background: #ede9fe; color: #7c3aed; }
.role-staff { background: #dbeafe; color: #1d4ed8; }

/* ---- KPI grid ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.kpi-icon { font-size: 24px; flex-shrink: 0; }
.kpi-value { font-size: 16px; font-weight: 800; line-height: 1.2; }
.kpi-label { font-size: 11.5px; color: var(--color-text-muted); margin-top: 2px; }
.kpi-blue .kpi-value { color: var(--color-info); }
.kpi-green .kpi-value { color: var(--color-success); }
.kpi-orange .kpi-value { color: var(--color-warn); }
.kpi-teal .kpi-value { color: var(--color-primary); }
.kpi-purple .kpi-value { color: #7c3aed; }
.kpi-muted .kpi-value { color: var(--color-text-muted); }
.kpi-danger .kpi-value { color: var(--color-danger); }

/* ---- dashboard charts layout ---- */
.dash-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.chart-card canvas { display: block; }
.chart-legend { font-size: 11.5px; color: var(--color-text-muted); margin-top: 6px; }

.dash-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ---- activity list ---- */
.activity-list { list-style: none; font-size: 12.5px; }
.activity-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}
.activity-list li:last-child { border-bottom: none; }
.act-module { font-weight: 700; color: var(--color-primary); font-size: 11px; white-space: nowrap; }
.act-detail { flex: 1; color: var(--color-text); }
.act-time { font-size: 11px; color: var(--color-text-muted); white-space: nowrap; }

/* ---- top list ---- */
.top-list { list-style: none; }
.top-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}
.top-list li:last-child { border-bottom: none; }

/* ---- settings ---- */
.settings-section { margin-bottom: 18px; }
.settings-section h3 { margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--color-border); }
.settings-actions { margin-top: 6px; }
.danger-zone { border-color: var(--color-danger) !important; }
.danger-zone h3 { color: var(--color-danger); }

/* ---- tabs ---- */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--color-surface2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tab-btn {
  padding: 7px 14px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background .15s, color .15s;
}
.tab-btn.active { background: var(--color-surface); color: var(--color-primary); box-shadow: var(--shadow); }
.tab-btn:hover:not(.active) { background: rgba(0,0,0,.04); color: var(--color-text); }

/* ---- empty state ---- */
.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13.5px;
}

/* ---- misc ---- */
.text-danger { color: var(--color-danger); }
.muted-text { font-size: 13px; color: var(--color-text-muted); }

/* ---- toast ---- */
.erp-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  box-shadow: var(--shadow-md);
  z-index: 99999;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: 320px;
}
.erp-toast.show { opacity: 1; transform: none; }
.erp-toast.info, .erp-toast.success { background: var(--color-success); }
.erp-toast.warn { background: var(--color-warn); }
.erp-toast.error { background: var(--color-danger); }

/* ---- login screen ---- */
#login-screen,
#setup-wizard-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a2433 0%, #0b3d35 100%);
  padding: 20px;
}
.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.login-logo-icon {
  width: 40px; height: 40px;
  background: var(--color-primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  object-fit: cover;
  flex-shrink: 0;
}
.login-logo-text { font-size: 15.5px; font-weight: 800; color: #1a202c; line-height: 1.25; }
.login-logo-sub { font-size: 11px; color: #718096; }
.login-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: #718096; margin-bottom: 20px; }
.login-error { background: #fef2f2; color: #dc2626; padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; display: none; }
.login-error.show { display: block; }
#login-form .form-row { margin-bottom: 14px; }
#login-form label { font-size: 13px; font-weight: 600; color: #4a5568; margin-bottom: 5px; display: block; }
#login-form input {
  width: 100%;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  padding: 10px 12px;
  font-size: 14px;
  transition: border-color .15s;
  outline: none;
}
#login-form input:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(11,110,97,.12); }
#login-submit { width: 100%; padding: 11px; font-size: 14.5px; margin-top: 4px; }
.login-hint { font-size: 11.5px; color: #a0aec0; text-align: center; margin-top: 14px; }

/* ---- mobile sidebar overlay ---- */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 190;
}

/* ---- responsive ---- */
@media (max-width: 900px) {
  .dash-charts,
  .dash-bottom { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  :root { --sidebar-width: 240px; }
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .22s;
    z-index: 200;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay.show { display: block; }
  #hamburger { display: block; }
  #content { padding: 14px 12px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .erp-modal-backdrop { align-items: flex-end; padding: 0; }
  .erp-modal {
    max-width: 100% !important; border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92vh; max-height: 92dvh;
  }
  .login-box { padding: 28px 20px; }
  .filters-row { flex-direction: column; align-items: stretch; }
}

@media (max-width: 480px) {
  .page-head { flex-direction: column; align-items: flex-start; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 6px; }

  /* Line-items table (invoice/quotation editor) becomes a stack of
     cards instead of a wide table — this is what used to force
     rotating the phone to landscape just to reach the Qty/Unit/
     Price/Tax columns. Each row is now its own card with labelled
     fields, fully usable in portrait. */
  .li-table thead { display: none; }
  .li-table, .li-table tbody, .li-table tr { display: block; width: 100%; }
  .li-table tr {
    border: 1px solid var(--color-border); border-radius: 8px;
    padding: 8px 10px; margin-bottom: 10px; background: var(--color-surface);
  }
  .li-table td {
    display: flex; align-items: center; justify-content: space-between;
    border: none; padding: 5px 0; text-align: left !important;
  }
  .li-table td[data-label]:not([data-label=""])::before {
    content: attr(data-label); font-weight: 600; font-size: 11px;
    color: var(--color-text-muted); margin-right: 10px; flex-shrink: 0;
  }
  .li-table td input, .li-table td select { flex: 1; max-width: 62%; width: auto !important; }
  .li-table .li-product-cell { display: block; }
  .li-table .li-product-cell::before { display: block; margin-bottom: 4px; }
  .li-table .li-product-inputwrap { width: 100%; }
  .li-table td[data-label=""] { justify-content: flex-end; gap: 6px; }
}

/* ---- print ---- */
@media print {
  #sidebar, #topbar, .page-head-actions, .row-actions, .filters-row { display: none !important; }
  #content { padding: 0; }
  body { overflow: visible; }
  .card { box-shadow: none; border: none; }
}

/* ── PWA safe area padding (notch phones) ── */
#sidebar { padding-bottom: env(safe-area-inset-bottom, 0); }
#content  { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0)); }

/* ── Template picker cards ── */
.tpl-card { transition: border-color .15s, box-shadow .15s; }
.tpl-card:hover { box-shadow: var(--shadow-md); }
.tpl-card.selected { box-shadow: 0 0 0 3px var(--color-primary-light); }

/* ── Fire safety status colours ── */
.fs-overdue { color: var(--color-danger); font-weight: 700; }
.fs-soon    { color: var(--color-warn);   font-weight: 700; }
.fs-ok      { color: var(--color-success);}

/* ── Project cards ── */
.card[data-id]:hover { box-shadow: var(--shadow-md); }

/* ══════════════════════════════════════
   AI ASSISTANT — floating chat widget
   ══════════════════════════════════════ */
#ai-widget-root { position: fixed; right: 20px; bottom: 20px; z-index: 8000; }
#ai-fab {
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--color-primary); color: #fff; font-size: 24px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer;
}
#ai-fab:hover { transform: scale(1.06); }
#ai-panel {
  position: absolute; right: 0; bottom: 68px;
  width: 360px; max-width: calc(100vw - 32px);
  height: 520px; max-height: calc(100vh - 120px);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.28);
  display: flex; flex-direction: column; overflow: hidden;
}
#ai-panel-head {
  background: var(--color-primary); color: #fff;
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
#ai-panel-actions { display: flex; gap: 6px; }
#ai-panel-actions button {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
#ai-panel-actions button:hover { background: rgba(255,255,255,.28); }
#ai-messages {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
  min-height: 0;
}
.ai-msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.ai-msg-user { align-self: flex-end; background: var(--color-primary); color: #fff; border-bottom-right-radius: 3px; }
.ai-msg-bot  { align-self: flex-start; background: var(--color-surface2); color: var(--color-text); border-bottom-left-radius: 3px; }
#ai-typing { padding: 0 14px 6px; font-size: 11.5px; color: var(--color-text-muted); font-style: italic; flex-shrink: 0; }
#ai-input-row { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--color-border); flex-shrink: 0; }
#ai-input-row input {
  flex: 1; border: 1px solid var(--color-border); border-radius: 20px;
  padding: 9px 14px; font-size: 13px; background: var(--color-surface2); color: var(--color-text);
}
#ai-input-row input:focus { outline: none; border-color: var(--color-primary); }
#ai-send-btn, #ai-mic-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--color-primary); color: #fff; cursor: pointer; font-size: 15px; flex-shrink: 0;
}
#ai-mic-btn { background: var(--color-surface2); color: var(--color-text-muted); }
#ai-send-btn:hover, #ai-mic-btn:hover { opacity: .85; }
#ai-mic-btn.ai-mic-active { background: var(--color-danger); color: #fff; animation: aiMicPulse 1s infinite; }
@keyframes aiMicPulse { 0%,100%{opacity:1} 50%{opacity:.55} }

@media (max-width: 480px) {
  #ai-widget-root { right: 12px; bottom: 12px; }
  #ai-panel { width: calc(100vw - 24px); height: calc(100vh - 100px); bottom: 66px; right: -8px; }
}
