/* ============================================================
   NetTrack IMS — Main Stylesheet (Mobile-First + WebView)
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --navy:   #0D1B2A;
  --steel:  #1B3A5C;
  --sky:    #2E86C1;
  --ice:    #D6EAF8;
  --signal: #00C896;
  --warn:   #F39C12;
  --danger: #E74C3C;
  --light:  #F4F7FB;
  --mid:    #8FA6C1;
  --border: #D0DCE8;
  --white:  #FFFFFF;
  --text:   #1A2B3C;
  --muted:  #6B83A0;
  --mono:   'JetBrains Mono', monospace;
  --sans:   'Inter', sans-serif;
  --sidebar-w: 240px;
  --topbar-h:  60px;
  --bottom-nav-h: 64px;
}

body { font-family: var(--sans); background: var(--light); color: var(--text); min-height: 100vh; }
a    { text-decoration: none; color: inherit; }

/* ══════════════════════════════════════════════════════════
   DESKTOP LAYOUT (≥ 769px)
══════════════════════════════════════════════════════════ */
/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--navy); display: flex; flex-direction: column;
  z-index: 200; overflow-y: auto; overflow-x: hidden;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
}
.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}
.logo-mark  { display: flex; align-items: center; gap: 10px; }
.logo-icon  {
  width: 36px; height: 36px; background: var(--sky);
  border-radius: 8px; display: flex; align-items: center;
  justify-content: center; font-size: 18px; flex-shrink: 0;
}
.logo-text  { color: var(--white); font-size: 15px; font-weight: 700; letter-spacing: -.3px; }
.logo-sub   { color: var(--mid); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; margin-top: 1px; }

.user-badge {
  margin: 16px 14px; padding: 10px 12px;
  background: rgba(255,255,255,0.05); border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.07);
}
.user-role  { font-size: 9px; letter-spacing: 1.8px; text-transform: uppercase; color: var(--signal); font-weight: 600; }
.user-name  { color: var(--white); font-size: 13px; font-weight: 500; margin-top: 2px; }

.nav-section { padding: 4px 0; }
.nav-label   {
  font-size: 9px; letter-spacing: 1.8px; text-transform: uppercase;
  color: var(--mid); padding: 10px 20px 4px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; cursor: pointer; transition: all .15s;
  color: rgba(255,255,255,.6); font-size: 13px; font-weight: 400;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--white); background: rgba(255,255,255,.05); }
.nav-item.active {
  color: var(--white); background: rgba(46,134,193,.18);
  border-left-color: var(--sky); font-weight: 500;
}
.nav-item .icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: var(--signal); color: var(--navy);
  font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 20px;
}
.nav-badge.warn { background: var(--warn); color: white; }

.sidebar-footer {
  margin-top: auto; padding: 16px 14px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.logout-btn {
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,.4); font-size: 12px; cursor: pointer;
  padding: 8px 6px; border-radius: 6px; transition: all .15s;
}
.logout-btn:hover { color: var(--danger); }

/* ── OVERLAY (mobile sidebar backdrop) ───────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 190; backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* ── TOPBAR ──────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: var(--sidebar-w); right: 0;
  height: var(--topbar-h); background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
  z-index: 90;
}
.topbar-menu-btn { display: none; }
.page-title  { font-size: 17px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb  { font-size: 12px; color: var(--muted); margin-top: 1px; display: none; }
.breadcrumb a { color: var(--sky); }
.topbar-right {
  margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.notif-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; position: relative; background: var(--white); cursor: pointer;
}
.notif-dot {
  position: absolute; top: 6px; right: 6px; width: 7px; height: 7px;
  background: var(--danger); border-radius: 50%; border: 1.5px solid white;
}
.topbar-avatar {
  width: 34px; height: 34px; border-radius: 8px; background: var(--sky);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 12px; font-weight: 700; cursor: pointer; flex-shrink: 0;
}

/* ── MAIN ────────────────────────────────────────────────── */
.main      { margin-left: var(--sidebar-w); padding-top: var(--topbar-h); min-height: 100vh; }
.page-inner { padding: 24px; }

/* ── BOTTOM NAV (mobile only — hidden on desktop) ─────────── */
.bottom-nav { display: none; }

/* ══════════════════════════════════════════════════════════
   PAGE HEADER
══════════════════════════════════════════════════════════ */
.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header p  { font-size: 13px; color: var(--muted); margin-top: 4px; }
.page-header .hd-row { display:flex; align-items:flex-start; justify-content:space-between; gap: 12px; }

/* ══════════════════════════════════════════════════════════
   KPI GRID
══════════════════════════════════════════════════════════ */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 20px; }
.kpi-grid.col3 { grid-template-columns: repeat(3,1fr); }
.kpi-grid.col2 { grid-template-columns: repeat(2,1fr); }
.kpi-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; position: relative; overflow: hidden;
}
.kpi-card::after {
  content:''; position:absolute; bottom:0; left:0; right:0; height:3px;
}
.kpi-card.blue::after  { background: var(--sky); }
.kpi-card.green::after { background: var(--signal); }
.kpi-card.warn::after  { background: var(--warn); }
.kpi-card.red::after   { background: var(--danger); }
.kpi-icon  { font-size: 20px; margin-bottom: 10px; }
.kpi-val   { font-size: 22px; font-weight: 700; font-family: var(--mono); line-height: 1.2; }
.kpi-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-top: 4px; }
.kpi-delta { font-size: 11px; color: var(--signal); font-weight: 600; margin-top: 6px; }
.kpi-delta.bad { color: var(--danger); }

/* ══════════════════════════════════════════════════════════
   CARD
══════════════════════════════════════════════════════════ */
.card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card-title  { font-size: 13px; font-weight: 600; }
.card-body   { padding: 16px; }
.card + .card { margin-top: 14px; }

/* ══════════════════════════════════════════════════════════
   GRID HELPERS
══════════════════════════════════════════════════════════ */
.grid-2       { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3       { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-aside   { display: grid; grid-template-columns: 1fr 320px; gap: 14px; }
.grid-aside-l { display: grid; grid-template-columns: 320px 1fr; gap: 14px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.gap-8 { gap: 8px; }

/* ══════════════════════════════════════════════════════════
   TABLE
══════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table  { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  background: var(--light); text-align: left; padding: 10px 12px;
  font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFBFC; }
.td-mono  { font-family: var(--mono); font-size: 12px; }
.td-actions { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.text-right { text-align: right; }

/* ══════════════════════════════════════════════════════════
   MOBILE CARD LIST (replaces table rows on small screens)
══════════════════════════════════════════════════════════ */
.m-card-list { display: none; }
.m-card-item {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin-bottom: 10px;
}
.m-card-item:last-child { margin-bottom: 0; }
.m-card-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.m-card-row   { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.m-card-label { font-size: 11px; color: var(--muted); }
.m-card-val   { font-size: 12px; font-weight: 500; }
.m-card-footer{ display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* ══════════════════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 600;
  letter-spacing: .3px; text-transform: uppercase; white-space: nowrap;
}
.badge-green { background: #E8FAF4; color: #00956E; }
.badge-warn  { background: #FEF5E7; color: #D68910; }
.badge-red   { background: #FDEDEC; color: #C0392B; }
.badge-blue  { background: #EBF5FB; color: #1A6FA8; }
.badge-gray  { background: #EEF1F5; color: #5D7896; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ══════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; transition: all .15s; letter-spacing: .2px;
  font-family: var(--sans); white-space: nowrap; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--sky);    color: white; }
.btn-primary:hover  { background: #236FA0; }
.btn-secondary { background: var(--light);  color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success   { background: var(--signal); color: white; }
.btn-success:hover  { background: #00A87E; }
.btn-danger    { background: var(--danger); color: white; }
.btn-danger:hover   { background: #C0392B; }
.btn-warn      { background: var(--warn);   color: white; }
.btn-sm   { padding: 6px 12px; font-size: 12px; }
.btn-xs   { padding: 4px 8px;  font-size: 11px; }
.btn-full { width: 100%; }
/* Mobile: bigger tap targets */
.btn-mobile { min-height: 46px; font-size: 14px; border-radius: 10px; }

/* ══════════════════════════════════════════════════════════
   FORMS
══════════════════════════════════════════════════════════ */
.form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
input, select, textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: var(--sans); color: var(--text);
  background: var(--white); outline: none; transition: border .15s; width: 100%;
  -webkit-appearance: none; appearance: none;
  /* Prevent zoom on focus in iOS */
  font-size: max(16px, 14px);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--sky); box-shadow: 0 0 0 3px rgba(46,134,193,.12);
}
input[readonly] { background: var(--light); color: var(--muted); }
textarea { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.required-star { color: var(--danger); margin-left: 2px; }

/* ══════════════════════════════════════════════════════════
   ALERTS
══════════════════════════════════════════════════════════ */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px;
}
.alert-success { background: #E8FAF4; border: 1px solid #A9DFBF; color: #145A32; }
.alert-danger  { background: #FDEDEC; border: 1px solid #F1948A; color: #922B21; }
.alert-info    { background: #EBF5FB; border: 1px solid #AED6F1; color: #154360; }
.alert-warn    { background: #FEF5E7; border: 1px solid #FAD7A0; color: #784212; }
.alert-icon    { font-size: 15px; margin-top: 1px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════════════
   TABS
══════════════════════════════════════════════════════════ */
.tabs {
  display: flex; gap: 0; border-bottom: 2px solid var(--border);
  margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 16px; font-size: 12px; font-weight: 600; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all .15s; white-space: nowrap; flex-shrink: 0;
}
.tab.active      { color: var(--sky); border-bottom-color: var(--sky); }
.tab:hover:not(.active) { color: var(--text); }

/* ══════════════════════════════════════════════════════════
   SECTION HEAD
══════════════════════════════════════════════════════════ */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 8px;
}
.section-head-left { display: flex; flex-direction: column; }
.section-title { font-size: 14px; font-weight: 600; }
.section-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }
.section-head-right { display: flex; gap: 8px; align-items: center; }

/* ══════════════════════════════════════════════════════════
   WORKFLOW STEPS
══════════════════════════════════════════════════════════ */
.workflow { display: flex; align-items: flex-start; margin-bottom: 16px; overflow-x: auto; }
.wf-step  { flex: 1; min-width: 70px; display: flex; flex-direction: column; align-items: center; position: relative; }
.wf-step:not(:last-child)::after {
  content: ''; position: absolute; top: 16px; left: 50%; right: -50%;
  height: 2px; background: var(--border); z-index: 0;
}
.wf-step.done:not(:last-child)::after   { background: var(--signal); }
.wf-circle {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; background: var(--white); z-index: 1; position: relative; font-weight: 700;
}
.wf-step.done   .wf-circle { border-color: var(--signal); color: var(--signal); background: #E8FAF4; }
.wf-step.active .wf-circle { border-color: var(--sky);    color: var(--sky);    background: #EBF5FB; }
.wf-step.pending .wf-circle { color: var(--mid); }
.wf-label { font-size: 10px; font-weight: 600; color: var(--muted); margin-top: 6px; text-align: center; line-height: 1.4; }
.wf-step.done   .wf-label { color: var(--signal); }
.wf-step.active .wf-label { color: var(--sky); }

/* ══════════════════════════════════════════════════════════
   STOCK BAR
══════════════════════════════════════════════════════════ */
.stock-bar  { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.stock-fill { height: 100%; border-radius: 4px; }
.fill-green { background: var(--signal); }
.fill-warn  { background: var(--warn); }
.fill-red   { background: var(--danger); }

/* ══════════════════════════════════════════════════════════
   INVOICE
══════════════════════════════════════════════════════════ */
.invoice-wrap    { background: white; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.invoice-header  { background: var(--navy); color: white; padding: 24px; display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; }
.invoice-logo    { font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.invoice-logo span { color: var(--sky); }
.invoice-no      { font-family: var(--mono); font-size: 13px; color: var(--ice); }
.invoice-body    { padding: 24px; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.party-label     { font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.party-name      { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.party-detail    { font-size: 12px; color: var(--muted); line-height: 1.6; }
.invoice-totals  { display: flex; justify-content: flex-end; margin-top: 14px; }
.totals-box      { width: 250px; }
.totals-row      { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.totals-row.grand { font-weight: 800; font-size: 16px; color: var(--navy); border-bottom: none; padding-top: 10px; }
.invoice-footer  { background: var(--light); padding: 14px 24px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); text-align: center; }

/* ══════════════════════════════════════════════════════════
   MINI BAR CHART
══════════════════════════════════════════════════════════ */
.mini-bar       { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.mini-bar-label { font-size: 11px; color: var(--muted); width: 100px; flex-shrink: 0; }
.mini-bar-track { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.mini-bar-fill  { height: 100%; border-radius: 4px; }
.mini-bar-val   { font-size: 11px; font-family: var(--mono); width: 70px; text-align: right; }

/* ══════════════════════════════════════════════════════════
   ROLE CARDS
══════════════════════════════════════════════════════════ */
.role-card        { border-radius: 12px; padding: 16px; border: 1px solid var(--border); }
.role-card.field  { background: linear-gradient(135deg,#EBF5FB,#F4F7FB); }
.role-card.office { background: linear-gradient(135deg,#E8FAF4,#F4F7FB); }
.role-card.admin  { background: linear-gradient(135deg,#FEF5E7,#F4F7FB); }
.role-icon        { font-size: 24px; margin-bottom: 10px; }
.role-name        { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.role-perm        { list-style: none; }
.role-perm li     { font-size: 11px; color: var(--muted); padding: 3px 0 3px 16px; position: relative; line-height: 1.5; }
.role-perm li::before { content: '→'; position: absolute; left: 0; color: var(--sky); font-size: 10px; }

/* ══════════════════════════════════════════════════════════
   ITEM LINE ROWS
══════════════════════════════════════════════════════════ */
.item-lines       { margin-bottom: 12px; }
.item-line        {
  background: var(--light); border-radius: 8px; padding: 12px;
  margin-bottom: 8px; display: grid; gap: 8px; align-items: end;
  grid-template-columns: 2.5fr 1fr 1fr 1fr 38px;
}
.item-line .remove-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; padding: 8px; color: var(--muted); font-size: 12px;
  transition: all .15s; height: 38px; width: 38px; display: flex; align-items: center; justify-content: center;
}
.item-line .remove-btn:hover { border-color: var(--danger); color: var(--danger); }

/* ══════════════════════════════════════════════════════════
   GRAND TOTAL BAR
══════════════════════════════════════════════════════════ */
.grand-total-bar {
  background: var(--navy); border-radius: 8px; padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  margin: 12px 0;
}
.grand-total-bar .label { color: rgba(255,255,255,.6); font-size: 12px; }
.grand-total-bar .val   { color: white; font-size: 20px; font-weight: 800; font-family: var(--mono); }

/* ══════════════════════════════════════════════════════════
   FILTER BAR
══════════════════════════════════════════════════════════ */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar input, .filter-bar select { width: auto; min-width: 0; }

/* ══════════════════════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════════════════════ */
.text-muted   { color: var(--muted); }
.text-success { color: var(--signal); }
.text-danger  { color: var(--danger); }
.text-warn    { color: var(--warn); }
.fw-bold      { font-weight: 700; }
.font-mono    { font-family: var(--mono); }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1       { flex: 1; }
.w-100        { width: 100%; }
.p-20         { padding: 20px; }
.empty-state  { text-align: center; padding: 50px 20px; color: var(--muted); font-size: 13px; }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }

/* ══════════════════════════════════════════════════════════
   PRINT
══════════════════════════════════════════════════════════ */
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print, .btn, .sidebar-overlay { display: none !important; }
  .main { margin-left: 0; padding-top: 0; }
  .page-inner { padding: 0; }
  .invoice-wrap { border: none; box-shadow: none; }
}

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

/* ══════════════════════════════════════════════════════════
   TABLET (769px – 1024px)
══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .kpi-grid        { grid-template-columns: repeat(2,1fr); }
  .kpi-grid.col3   { grid-template-columns: repeat(2,1fr); }
  .grid-3          { grid-template-columns: 1fr 1fr; }
  .grid-aside      { grid-template-columns: 1fr; }
  .grid-aside-l    { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════════
   MOBILE (≤ 768px) — Android WebView primary target
══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --topbar-h: 56px;
  }

  /* Hide desktop sidebar */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }

  /* Topbar: full width, show hamburger */
  .topbar {
    left: 0; padding: 0 16px;
  }
  .topbar-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; background: none; border: none;
    cursor: pointer; font-size: 20px; color: var(--text);
    padding: 0; flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .breadcrumb { display: none; }
  .page-title { font-size: 15px; }

  /* Main: no left margin, bottom padding for nav */
  .main {
    margin-left: 0;
    padding-bottom: var(--bottom-nav-h);
  }
  .page-inner { padding: 14px; }

  /* Bottom navigation bar */
  .bottom-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: var(--white); border-top: 1px solid var(--border);
    z-index: 100; padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bottom-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; padding: 6px 4px;
    color: var(--muted); font-size: 10px; font-weight: 600;
    cursor: pointer; border-radius: 8px; transition: all .15s;
    text-decoration: none; position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-item.active { color: var(--sky); }
  .bottom-nav-item .bn-icon { font-size: 20px; line-height: 1; }
  .bottom-nav-item .bn-badge {
    position: absolute; top: 4px; right: calc(50% - 16px);
    background: var(--danger); color: white;
    font-size: 8px; font-weight: 800;
    min-width: 14px; height: 14px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 3px;
  }

  /* Grids: single column on mobile */
  .kpi-grid         { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-grid.col3    { grid-template-columns: 1fr 1fr; }
  .kpi-grid.col2    { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3, .grid-aside, .grid-aside-l { grid-template-columns: 1fr; }
  .form-grid, .form-grid3 { grid-template-columns: 1fr; }
  .form-group.full  { grid-column: auto; }

  /* KPI card compact */
  .kpi-val   { font-size: 18px; }
  .kpi-icon  { font-size: 18px; margin-bottom: 6px; }
  .kpi-card  { padding: 12px; }

  /* Tables → mobile card list */
  .table-wrap { display: none; }
  .m-card-list { display: block; }

  /* Item line: stack vertically */
  .item-line { grid-template-columns: 1fr 1fr; }
  .item-line > div:first-child { grid-column: 1 / -1; }

  /* Page header: stack */
  .page-header .hd-row { flex-direction: column; align-items: stretch; }
  .page-header .hd-row > .btn,
  .page-header .hd-row > div:last-child { align-self: flex-start; }

  /* Filter bar: scroll horizontally */
  .filter-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-bar input, .filter-bar select { min-width: 140px; }

  /* Tabs: scroll */
  .tabs { margin-bottom: 12px; }

  /* Buttons */
  .btn { font-size: 13px; }
  .form-actions { gap: 8px; }
  .form-actions .btn { flex: 1; min-height: 44px; }

  /* Invoice */
  .invoice-parties { grid-template-columns: 1fr; }
  .invoice-body    { padding: 16px; }
  .invoice-header  { padding: 16px; }
  .invoice-totals  { justify-content: stretch; }
  .totals-box      { width: 100%; }

  /* Role cards */
  .grid-3.role-grid { grid-template-columns: 1fr; }

  /* Section head: wrap */
  .section-head { flex-wrap: wrap; }

  /* Sidebar footer hidden on mobile (logout in top) */
  .sidebar-footer { padding-bottom: 20px; }

  /* Modal */
  .modal-box { width: calc(100vw - 32px) !important; max-width: 400px; }
}

/* ══════════════════════════════════════════════════════════
   SMALL PHONE (≤ 375px)
══════════════════════════════════════════════════════════ */
@media (max-width: 375px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .page-inner { padding: 10px; }
  .kpi-val  { font-size: 16px; }
}

/* ── UCWORDS inputs — subtle visual cue ─────────────────── */
.ucwords-input { text-transform: capitalize; }
.ucwords-input::placeholder { text-transform: none; }



/* ============================================================
   TOPBAR DROPDOWN (desktop avatar click)
   ============================================================ */
.topbar-right { position: relative; }

.user-dropdown {
    position: absolute;
    top: 52px; right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,.18);
    min-width: 210px;
    z-index: 600;
    overflow: hidden;
}
.user-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--light);
}
.user-dropdown-item {
    display: -webkit-flex; display: flex;
    -webkit-align-items: center; align-items: center;
    gap: 10px; padding: 12px 16px;
    font-size: 13px; color: var(--text);
    border-bottom: 1px solid var(--border);
    text-decoration: none;
}
.user-dropdown-item:last-child { border-bottom: none; }
.user-dropdown-item:hover      { background: var(--light); }
.user-dropdown-signout         { color: var(--danger); font-weight: 600; }

/* ============================================================
   BOTTOM NAVIGATION
   Always hidden; shown only by the @media rule below.
   ============================================================ */
.bottom-nav { display: none; }

/* ============================================================
   MOBILE ACCOUNT SHEET
   A bottom-sheet that slides up when the Account tab is tapped.
   
   Structure:
     #accountSheet  — full-screen fixed overlay (backdrop)
       .account-sheet-panel — slides up from bottom

   IMPORTANT: JS sets #accountSheet to display:block (not flex).
   The panel is absolutely positioned at the bottom.
   This is the most compatible approach for Android WebView.
   ============================================================ */

/* @keyframes defined OUTSIDE @media for Android WebView compatibility */
@-webkit-keyframes ims-slideup {
    0%   { -webkit-transform: translateY(100%); }
    100% { -webkit-transform: translateY(0);    }
}
@keyframes ims-slideup {
    0%   { transform: translateY(100%); }
    100% { transform: translateY(0); }
}

/* Overlay — covers full screen, acts as backdrop */
.account-sheet {
    display: none;           /* JS sets to block when open  */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
    z-index: 800;
    /* No flex — panel is positioned absolutely */
}

/* Panel — sticks to bottom of viewport */
.account-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--navy);
    border-radius: 20px 20px 0 0;
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-animation: ims-slideup 0.28s ease-out;
            animation: ims-slideup 0.28s ease-out;
}

.account-sheet-handle {
    width: 44px; height: 5px;
    background: rgba(255,255,255,.22);
    border-radius: 3px;
    margin: 14px auto 2px;
}

.account-sheet-user {
    display: -webkit-flex; display: flex;
    -webkit-align-items: center; align-items: center;
    gap: 14px;
    padding: 16px 20px 14px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.account-sheet-avatar {
    width: 46px; height: 46px;
    border-radius: 12px;
    background: var(--sky);
    display: -webkit-flex; display: flex;
    -webkit-align-items: center; align-items: center;
    -webkit-justify-content: center; justify-content: center;
    color: #fff; font-size: 20px; font-weight: 700;
    -webkit-flex-shrink: 0; flex-shrink: 0;
}

.account-sheet-actions { padding: 6px 0; }

.account-sheet-btn {
    display: -webkit-flex; display: flex;
    -webkit-align-items: center; align-items: center;
    gap: 14px;
    padding: 15px 20px;
    color: rgba(255,255,255,.88);
    font-size: 15px; font-weight: 500;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,.07);
    text-decoration: none;
    background: transparent;
    width: 100%;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255,255,255,.06);
    box-sizing: border-box;
}
.account-sheet-btn:active { background: rgba(255,255,255,.1); }

.asb-icon  { font-size: 22px; width: 30px; text-align: center; -webkit-flex-shrink:0; flex-shrink:0; line-height:1; }
.asb-text  { -webkit-flex:1; flex:1; text-align:left; }
.asb-arrow { color: rgba(255,255,255,.26); font-size: 20px; font-weight: 300; }

.account-sheet-signout             { color: #ff7070 !important; }
.account-sheet-signout .asb-arrow { color: rgba(255,80,80,.3); }

.account-sheet-close {
    display: block;
    width: calc(100% - 32px);
    margin: 10px 16px 14px;
    padding: 15px;
    border-radius: 12px;
    background: rgba(255,255,255,.12);
    color: #fff;
    font-size: 15px; font-weight: 700;
    font-family: var(--sans);
    border: none;
    cursor: pointer;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}
.account-sheet-close:active { background: rgba(255,255,255,.2); }

/* ============================================================
   @media MOBILE (≤ 768px)
   ============================================================ */
@media screen and (max-width: 768px) {
    /* Show bottom nav */
    .bottom-nav {
        display: -webkit-flex;
        display: flex;
    }
    /* Push page content above bottom nav */
    .main {
        padding-bottom: 64px;
    }
    /* Remove any old sign-out bar */
    .mobile-signout-bar { display: none !important; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .sidebar, .topbar, .bottom-nav, .no-print,
    .sidebar-overlay, .account-sheet { display: none !important; }
    .main { margin-left: 0; padding-top: 0; padding-bottom: 0; }
    .page-inner { padding: 0; }
}
