/* ═══════════════════════════════════════════════════════════════
   InvoiceFlow — Mobile-First Design System
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  --bg-popup:  #16202e;
  --text-popup: #e8edf5;
  --bg-base:       #080f1a;
  --bg-surface:    #0d1829;
  --bg-elevated:   #111f35;
  --bg-overlay:    #162540;

  --border:        rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.14);

  --text-primary:  #e8edf5;
  --text-secondary:#8fa3c0;
  --text-muted:    #4e6485;

  --accent:        #10d97a;
  --accent-dim:    rgba(16,217,122,0.12);
  --accent-hover:  #0fca70;

  --danger:        #ff4d6d;
  --danger-dim:    rgba(255,77,109,0.12);
  --warning:       #f5a623;
  --warning-dim:   rgba(245,166,35,0.12);
  --info:          #4a9eff;
  --info-dim:      rgba(74,158,255,0.12);

  --status-draft:    #4e6485;
  --status-sent:     #4a9eff;
  --status-viewed:   #a78bfa;
  --status-partial:  #f5a623;
  --status-paid:     #10d97a;
  --status-overdue:  #ff4d6d;
  --status-cancelled:#4e6485;
  --status-accepted: #10d97a;
  --status-declined: #ff4d6d;
  --status-expired:  #f5a623;
  --status-converted:#a78bfa;

  --font-body:  'DM Sans',  system-ui, sans-serif;
  --font-mono:  'DM Mono',  monospace;

  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;
  --r-xl:  20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);

  --sidebar-w:  240px;
  --topbar-h:   60px;
  --bottom-nav: 64px;  /* mobile bottom nav height */

  /* Touch-friendly minimum target sizes */
  --touch-min:  48px;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; /* remove tap flash on mobile */
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }

/* ── App Layout ─────────────────────────────────────────────── */
#invoiceflow-root { min-height: 100dvh; }

.if-app {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.if-sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100dvh;
  z-index: 100;
  transition: transform 0.25s ease;
}

.if-sidebar__logo {
  padding: 20px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  flex-direction: column;
  text-align: center;
}
.if-sidebar__logo-img {
  width: 100%;
  max-width: 180px;
  height: auto;
  max-height: 110px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}
.if-sidebar__logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.if-sidebar__logo-text span { color: var(--accent); }

.if-sidebar__tenant {
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.if-sidebar__tenant strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.if-sidebar__tenant span { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.if-sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
}
.if-sidebar__nav::-webkit-scrollbar { width: 4px; }
.if-sidebar__nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.if-nav-section { margin-bottom: 8px; }
.if-nav-section__label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 10px 4px;
}
.if-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  min-height: var(--touch-min);
}
.if-nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.if-nav-link:hover  { background: var(--bg-elevated); color: var(--text-primary); }
.if-nav-link:hover svg { opacity: 1; }
.if-nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}
.if-nav-link.active svg { opacity: 1; }

.if-sidebar__footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}
.if-user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s;
  min-height: var(--touch-min);
}
.if-user-pill:hover { background: var(--bg-elevated); }
.if-user-pill__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--accent);
  flex-shrink: 0;
}
.if-user-pill__info { flex: 1; min-width: 0; }
.if-user-pill__name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.if-user-pill__role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

/* ── Main Content ─────────────────────────────────────────────── */
.if-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.if-topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.if-topbar__menu-btn {
  display: none;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--r-md);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  align-items: center;
  justify-content: center;
}
.if-topbar__menu-btn svg { width: 22px; height: 22px; }
.if-topbar__title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.if-topbar__actions { display: flex; gap: 8px; align-items: center; }

.if-svt-credit {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.if-svt-credit__img { width: 20px; height: 20px; object-fit: contain; border-radius: 4px; flex-shrink: 0; }
.if-svt-credit__text sup { font-size: 9px; }

.if-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

/* ── Bottom Navigation (mobile only) ─────────────────────────── */
.if-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 90;
  padding: 0 4px;
  align-items: stretch;
}
.if-bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 4px;
  border-radius: var(--r-sm);
  transition: color 0.15s, background 0.15s;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  min-height: var(--bottom-nav);
}
.if-bottom-nav__item svg { width: 22px; height: 22px; }
.if-bottom-nav__item:hover  { color: var(--text-secondary); }
.if-bottom-nav__item.active { color: var(--accent); }

/* ── Login Page ─────────────────────────────────────────────── */
.if-login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.if-login-page::before {
  content: '';
  position: absolute;
  top: -200px; right: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(16,217,122,0.06) 0%, transparent 70%);
  pointer-events: none;
}
.if-login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}
.if-login-card__logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.if-login-card__logo-img {
  width: 48px; height: 48px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}
.if-login-card__logo-text { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; }
.if-login-card__logo-text span { color: var(--accent); }
.if-login-card h2 { font-size: 24px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.03em; }
.if-login-card p  { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
/* SVT watermark — only rendered on login/reset pages via JS */
#if-login-watermark {
  position: fixed;
  bottom: 18px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  pointer-events: none;
  z-index: 10;
}
.if-login-error {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  margin-bottom: 16px;
}

/* ── Form Controls ──────────────────────────────────────────── */
.if-field { margin-bottom: 16px; }
.if-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 7px;
}
.if-input, .if-select, .if-textarea {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: var(--touch-min);
}
.if-input:focus, .if-select:focus, .if-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.if-input::placeholder { color: var(--text-muted); }
.if-textarea { resize: vertical; min-height: 88px; }

/* ── Date / month inputs ─────────────────────────────────────────────────
   color-scheme: dark  →  tells the browser to render the native calendar
   icon and date-picker popup in dark mode (white icon, dark popup).
   This is the official spec approach and works across Chrome, Edge, Firefox.
   The -webkit-calendar-picker-indicator rules below are a belt-and-braces
   fallback for older Chromium builds that support the pseudo-element.
   ──────────────────────────────────────────────────────────────────────── */
input[type="date"],
input[type="month"] {
  cursor: pointer;
  color-scheme: dark;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  filter: brightness(0) invert(1);
  cursor: pointer;
  opacity: 0.6;
  padding: 4px;
  border-radius: 4px;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}
.if-select option { background: var(--bg-elevated); }
.if-input-group { display: flex; gap: 10px; }
.if-input-group .if-field { flex: 1; }

/* ── Buttons ─────────────────────────────────────────────────── */
.if-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
  text-align: center;
  justify-content: center;
  min-height: var(--touch-min);
  -webkit-tap-highlight-color: transparent;
}
.if-btn svg { width: 17px; height: 17px; }
.if-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.if-btn:active:not(:disabled) { transform: scale(0.97); }

.if-btn--primary {
  background: var(--accent);
  color: #080f1a;
  font-weight: 600;
}
.if-btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.if-btn--secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.if-btn--secondary:hover:not(:disabled) { background: var(--bg-overlay); }

.if-btn--danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.if-btn--danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.if-btn--ghost {
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.if-btn--ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }

.if-btn--sm {
  padding: 8px 14px;
  font-size: 13px;
  min-height: 36px;
  gap: 6px;
}
.if-btn--sm svg { width: 14px; height: 14px; }
.if-btn--lg {
  padding: 14px 28px;
  font-size: 16px;
  min-height: 52px;
}
.if-btn--full { width: 100%; }
.if-btn--icon {
  padding: 10px;
  width: var(--touch-min);
  height: var(--touch-min);
}

/* ── Cards ───────────────────────────────────────────────────── */
.if-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.if-card__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.if-card__title svg { width: 16px; height: 16px; color: var(--accent); }

/* ── Stat Cards ──────────────────────────────────────────────── */
.if-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.if-stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.if-stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.if-stat-card:hover::after { opacity: 1; }
.if-stat-card__label { font-size: 11px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 10px; }
.if-stat-card__value { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; font-family: var(--font-mono); }
.if-stat-card__sub   { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Tables ──────────────────────────────────────────────────── */
.if-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.if-table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.if-table-toolbar__title { font-weight: 600; flex: 1; min-width: 100px; }
.if-search-input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  width: 220px;
  min-height: 44px;
  transition: border-color 0.15s;
}
.if-search-input:focus { outline: none; border-color: var(--accent); }
.if-search-input::placeholder { color: var(--text-muted); }

.if-table { width: 100%; border-collapse: collapse; }
.if-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.if-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.if-table tr:last-child td { border-bottom: none; }
.if-table tbody tr { transition: background 0.1s; }
.if-table tbody tr:hover { background: var(--bg-elevated); cursor: pointer; }
.if-table .mono { font-family: var(--font-mono); font-size: 13px; }
.if-table .amount { font-family: var(--font-mono); text-align: right; }
.if-table .actions { text-align: right; white-space: nowrap; }

/* ── Mobile table card rows ──────────────────────────────────── */
/* On small screens, each <tr> becomes a card */
@media (max-width: 768px) {
  /* ── Mobile card layout for data tables ───────────────────────────────────
     Tables with many columns collapse to stacked cards.
     Each <td data-label="..."> shows a label:value pair.
     Columns marked data-mobile-hide="true" are suppressed.         */

  .if-table-wrap { overflow-x: visible; }
  .if-table      { min-width: 0; width: 100%; }

  /* Hide the header row — labels come from data-label on each td */
  .if-table thead { display: none; }

  /* Each body row = a card */
  .if-table tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    cursor: pointer;
  }
  .if-table tbody tr:hover { background: var(--bg-card); }

  /* Each cell = a label:value row inside the card */
  .if-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 4px 0;
    font-size: 13px;
    border: none;
    white-space: normal;
    gap: 8px;
  }

  /* Hide cells with no label or explicitly hidden */
  .if-table td:not([data-label]),
  .if-table td[data-label=""],
  .if-table td[data-mobile-hide="true"] { display: none; }

  /* Label shown before the value */
  .if-table td[data-label]::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    min-width: 90px;
    flex-shrink: 0;
    padding-top: 1px;
  }

  /* Make certain cells stand out */
  .if-table td.amount {
    font-size: 15px;
    font-weight: 700;
    text-align: left;
    font-family: var(--font-mono);
  }

  /* Action buttons fill the card bottom */
  .if-table td.actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
  }
  .if-table td.actions::before { display: none; }

  .if-badge { font-size: 10px; padding: 2px 7px; }
  .if-table .mono { font-size: 12px; }
}


/* ── Status Badges ───────────────────────────────────────────── */
.if-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.if-badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.if-badge--draft     { color: var(--status-draft);    background: rgba(78,100,133,0.15); }
.if-badge--sent      { color: var(--status-sent);     background: var(--info-dim); }
.if-badge--viewed    { color: var(--status-viewed);   background: rgba(167,139,250,0.12); }
.if-badge--partial   { color: var(--status-partial);  background: var(--warning-dim); }
.if-badge--paid      { color: var(--status-paid);     background: var(--accent-dim); }
.if-badge--overdue   { color: var(--status-overdue);  background: var(--danger-dim); }
.if-badge--cancelled { color: var(--status-cancelled); background: rgba(78,100,133,0.15); }
.if-badge--accepted  { color: var(--status-accepted); background: var(--accent-dim); }
.if-badge--declined  { color: var(--status-declined); background: var(--danger-dim); }
.if-badge--expired   { color: var(--status-expired);  background: var(--warning-dim); }
.if-badge--converted { color: var(--status-converted); background: rgba(167,139,250,0.12); }
.if-badge--pending   { color: var(--status-partial);  background: var(--warning-dim); }
.if-badge--approved  { color: var(--status-paid);     background: var(--accent-dim); }
.if-badge--rejected  { color: var(--status-overdue);  background: var(--danger-dim); }
.if-badge--active    { color: var(--status-paid);     background: var(--accent-dim); }
.if-badge--paused    { color: var(--status-partial);  background: var(--warning-dim); }

/* ── Modal ───────────────────────────────────────────────────── */
.if-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: if-fade-in 0.15s ease;
}
.if-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 640px;
  max-height: 92dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: if-slide-up 0.2s ease;
}
.if-modal--xl  { max-width: 1100px; }
.if-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}
.if-modal__header h3 { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.if-modal__body   { padding: 20px 24px; }
.if-modal__footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--bg-surface);
  position: sticky;
  bottom: 0;
}

/* ── Page Header ─────────────────────────────────────────────── */
.if-page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.if-page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  flex: 1;
}
.if-page-header__sub { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

/* ── Line Items Editor ───────────────────────────────────────── */
.if-line-items { margin: 16px 0; }
.if-line-items__header {
  display: grid;
  grid-template-columns: 1fr 80px 120px 80px 100px 44px;
  gap: 8px;
  padding: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.if-line-item {
  display: grid;
  grid-template-columns: 1fr 80px 120px 80px 100px 44px;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.if-line-item .if-input { padding: 9px 10px; font-size: 13px; min-height: 40px; }
.if-line-items__total {
  display: flex;
  justify-content: flex-end;
  padding: 16px 0 0;
}
.if-totals-table { width: 280px; }
.if-totals-table tr td { padding: 6px 0; font-size: 14px; }
.if-totals-table tr td:last-child { text-align: right; font-family: var(--font-mono); }
.if-totals-table .total-row td { font-size: 17px; font-weight: 700; padding-top: 10px; border-top: 1px solid var(--border); }

/* ── Tabs ─────────────────────────────────────────────────────── */
.if-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-base);
  padding: 4px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.if-tab {
  padding: 9px 18px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
  min-height: 40px;
}
.if-tab:hover { color: var(--text-primary); }
.if-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.if-tab--sm {
  padding: 6px 14px;
  font-size: 13px;
  min-height: 32px;
}

/* ── Empty state ─────────────────────────────────────────────── */
.if-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
.if-empty svg { width: 52px; height: 52px; color: var(--text-muted); margin-bottom: 16px; opacity: 0.5; }
.if-empty h3  { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.if-empty p   { color: var(--text-muted); font-size: 14px; max-width: 300px; }

/* ── Loader ──────────────────────────────────────────────────── */
.if-loader { display: flex; align-items: center; justify-content: center; padding: 48px; }
.if-spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: if-spin 0.6s linear infinite;
}

/* ── Toast ───────────────────────────────────────────────────── */
.if-toasts {
  position: fixed;
  bottom: calc(var(--bottom-nav) + 12px);
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.if-toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 13px 18px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: if-slide-up 0.2s ease;
  pointer-events: all;
  max-width: 340px;
}
.if-toast--success { border-left: 3px solid var(--accent);  color: var(--accent); }
.if-toast--error   { border-left: 3px solid var(--danger);  color: var(--danger); }
.if-toast--warning { border-left: 3px solid var(--warning); color: var(--warning); }

/* ── Animations ──────────────────────────────────────────────── */
@keyframes if-spin    { to { transform: rotate(360deg); } }
@keyframes if-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes if-slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Chart container ─────────────────────────────────────────── */
.if-chart-wrap { width: 100%; height: 240px; position: relative; }

/* ── Pagination ──────────────────────────────────────────────── */
.if-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.if-pagination__pages { display: flex; gap: 4px; }
.if-pagination__btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.if-pagination__btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.if-pagination__btn.active { background: var(--accent); color: #080f1a; font-weight: 600; border-color: var(--accent); }

/* ── Mobile overlay ──────────────────────────────────────────── */
.if-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

/* ── Settings Grid ───────────────────────────────────────────── */
.if-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

/* ── Logo Upload ─────────────────────────────────────────────── */
.if-logo-upload {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.if-logo-preview {
  width: 160px; height: 100px;
  border: 2px dashed var(--border);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  overflow: hidden;
  flex-shrink: 0;
}
.if-logo-preview img {
  max-width: 150px; max-height: 90px;
  width: auto; height: auto;
  object-fit: contain;
}
.if-logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}
.if-logo-placeholder svg { width: 28px; height: 28px; opacity: .4; }
.if-logo-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

/* ── SMTP settings section ───────────────────────────────────── */
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
#ios-install-bar { box-shadow: 0 -4px 20px rgba(0,0,0,.4); }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (max 1024px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .if-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (max 768px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --topbar-h: 56px; }

  /* Sidebar slides off-screen; bottom nav takes over */
  .if-sidebar { transform: translateX(-100%); }
  .if-sidebar.open { transform: translateX(0); }
  /* sidebar-overlay shown via JS only when sidebar opens */

  .if-main { margin-left: 0; padding-bottom: var(--bottom-nav); }
  .if-topbar { padding: 0 12px; }
  .if-topbar__menu-btn { display: flex; }
  .if-topbar__title { font-size: 16px; }
  .if-content { padding: 14px 14px calc(var(--bottom-nav) + 14px); }

  /* Show bottom nav */
  .if-bottom-nav { display: flex; }

  /* Stat cards: 2 columns */
  .if-stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .if-stat-card { padding: 14px; }
  .if-stat-card__value { font-size: 22px; }

  /* Modals: full-screen bottom sheet */
  .if-modal-overlay { align-items: flex-end; padding: 0; }
  .if-modal {
    margin: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 94dvh;
    max-width: 100%;
  }

  /* Modal footer: full-width stacked buttons */
  .if-modal__footer {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .if-modal__footer .if-btn { width: 100%; justify-content: center; }
  .if-modal__footer .if-btn--danger { order: 3; }

  /* Search input full width */
  .if-search-input { width: 100%; }

  /* Table toolbar wraps */
  .if-table-toolbar { gap: 8px; }

  /* Input groups stack on narrow */
  .if-input-group { flex-direction: column; gap: 0; }

  /* Page header */
  .if-page-header { margin-bottom: 16px; }
  .if-page-header h1 { font-size: 20px; }
  .if-page-header .if-btn { width: 100%; }

  /* Settings grid */
  .if-settings-grid { grid-template-columns: 1fr; }

  /* Logo upload */
  .if-logo-upload { flex-direction: column; }
  .if-logo-preview { width: 100%; height: 120px; }

  /* Line items on mobile: horizontal scroll */
  .if-line-items { overflow-x: auto; }
  .if-line-items__header,
  .if-line-item {
    grid-template-columns: 1fr 65px 100px 65px 90px 44px;
    gap: 6px;
    min-width: 480px;
  }

  /* Toast sits above bottom nav */
  .if-toasts { right: 12px; bottom: calc(var(--bottom-nav) + 12px); }

  /* Tabs scroll horizontally */
  .if-tabs { overflow-x: auto; flex-wrap: nowrap; width: 100%; }
}

@media (max-width: 480px) {
  .if-stats-grid { grid-template-columns: 1fr 1fr; }
  .if-login-card { padding: 28px 20px; }
  .if-login-card h2 { font-size: 20px; }
}

/* ═══════════════════════════════════════════════════════════════
   LIGHT THEME
   Toggle by adding class "if-light" to <html>
   ═══════════════════════════════════════════════════════════════ */
html.if-light {
  --bg-base:       #f0f4f8;
  --bg-surface:    #ffffff;
  --bg-elevated:   #e8f0f7;
  --bg-overlay:    #d8e6f2;

  --border:        rgba(15,23,42,0.08);
  --border-strong: rgba(15,23,42,0.16);

  --text-primary:  #0f172a;
  --text-secondary:#334155;
  --text-muted:    #94a3b8;

  --accent:        #059669;
  --accent-dim:    rgba(5,150,105,0.10);
  --accent-hover:  #047857;

  --warning:       #d97706;
  --danger:        #dc2626;
}
html.if-light body          { background: var(--bg-base); }
html.if-light .if-sidebar   { box-shadow: 2px 0 12px rgba(0,0,0,0.06); }
html.if-light .if-topbar    { box-shadow: 0 1px 4px rgba(0,0,0,0.07); }
html.if-light .if-card      { box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
html.if-light .if-stat-card { box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
html.if-light .if-modal     { box-shadow: 0 24px 64px rgba(0,0,0,0.18); }
html.if-light .if-login-card{ box-shadow: 0 4px 24px rgba(0,0,0,0.10); }
html.if-light .if-table-wrap{ box-shadow: 0 1px 4px rgba(0,0,0,0.06); }

/* Inputs need white bg in light mode */
html.if-light .if-input,
html.if-light .if-select,
html.if-light .if-textarea  { background: #fff; }

/* Light theme: switch back to light color-scheme and undo the inversion fallback */
html.if-light input[type="date"],
html.if-light input[type="month"] {
  color-scheme: light;
}
html.if-light input[type="date"]::-webkit-calendar-picker-indicator,
html.if-light input[type="month"]::-webkit-calendar-picker-indicator {
  filter: opacity(0.5);
}
html.if-light input[type="date"]::-webkit-calendar-picker-indicator:hover,
html.if-light input[type="month"]::-webkit-calendar-picker-indicator:hover {
  filter: opacity(1);
  background: rgba(0,0,0,0.06);
}

/* Chart grid lines - softer in light mode */
html.if-light .if-chart-wrap { background: #fff; }

/* Bottom nav needs slight shadow in light mode */
html.if-light .if-bottom-nav { box-shadow: 0 -1px 4px rgba(0,0,0,0.08); }

/* ═══════════════════════════════════════════════════════════════
   MOBILE IMPROVEMENTS
   Goal: everything fits on screen without horizontal scroll or
   excess vertical space. Cards/blocks sized to content, not comfort.
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Stop the page scrolling horizontally */
  body, .if-main, .if-content { overflow-x: hidden; max-width: 100vw; }

  /* Tighter content padding */
  .if-content { padding: 12px 12px calc(var(--bottom-nav) + 12px); }

  /* Dashboard: force 2-column stat grid that fits on screen */
  .if-stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; width: 100%; min-width: 0; }
  .if-stat-card { padding: 12px 10px; min-width: 0; overflow: hidden; }
  .if-stat-card__label { font-size: 9px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .if-stat-card__value { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .if-stat-card__sub   { font-size: 10px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Cards */
  .if-card { padding: 14px 12px; }
  .if-card__title { font-size: 13px; margin-bottom: 10px; padding-bottom: 8px; }

  /* Page header */
  .if-page-header { margin-bottom: 10px; }
  .if-page-header h1 { font-size: 17px; }
  .if-page-header__sub { font-size: 11px; }

  /* Buttons */
  .if-btn { padding: 9px 14px; font-size: 13px; }
  .if-btn--sm { padding: 6px 10px; font-size: 11px; }
  .if-btn--lg { padding: 11px 20px; font-size: 14px; }

  /* Inputs / selects */
  .if-input, .if-select, .if-textarea { padding: 9px 11px; font-size: 13px; }
  .if-field { margin-bottom: 10px; }
  .if-label { font-size: 11px; margin-bottom: 4px; }

  /* Table toolbar */
  .if-table-toolbar { padding: 8px 10px; gap: 6px; }
  .if-table-toolbar__title { font-size: 12px; }

  /* Mobile card-view rows: table cells displayed as compact pills */
  .if-table td { padding: 7px 10px; font-size: 12px; }
  .if-table th { padding: 6px 10px; font-size: 9px; }

  /* Table card rows on mobile: tighter */
  .if-table tr { margin-bottom: 6px; padding: 2px 0; }
  .if-table td::before { font-size: 9px; }

  /* Modal */
  .if-modal__header { padding: 12px 14px; }
  .if-modal__header h3 { font-size: 14px; }
  .if-modal__body   { padding: 12px 14px; }
  .if-modal__footer { padding: 10px 14px; gap: 6px; }
  .if-modal__footer .if-btn { padding: 10px 14px; font-size: 13px; }

  /* Bottom nav: icon only, no labels */
  .if-bottom-nav { height: 52px; padding: 0 2px; }
  .if-bottom-nav__item { padding: 4px 2px; font-size: 0; gap: 0; }
  .if-bottom-nav__item svg { width: 22px; height: 22px; }

  /* Sign-out label hidden */
  #logout-btn .btn-label { display: none; }

  /* Totals table */
  .if-totals-table tr td { font-size: 12px; padding: 4px 0; }
  .if-totals-table .total-row td { font-size: 14px; }

  /* Empty state */
  .if-empty { padding: 32px 14px; }
  .if-empty h3 { font-size: 14px; }
  .if-empty p  { font-size: 12px; }

  /* Tabs */
  .if-tabs { gap: 2px; }
  .if-tab  { padding: 7px 12px; font-size: 12px; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .if-content { padding: 8px 8px calc(var(--bottom-nav) + 8px); }

  /* Stat cards: very compact so all 4 fit on one screen */
  .if-stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
  .if-stat-card { padding: 10px 8px; min-width: 0; overflow: hidden; }
  .if-stat-card__label { font-size: 9px; margin-bottom: 3px; letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .if-stat-card__value { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .if-stat-card__sub   { font-size: 10px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Cards: tight but readable */
  .if-card { padding: 10px; }
  .if-card__title { font-size: 12px; margin-bottom: 8px; padding-bottom: 6px; }

  /* Buttons: finger-friendly but compact */
  .if-btn { padding: 9px 12px; font-size: 13px; }
  .if-btn--sm { padding: 5px 9px; font-size: 11px; }

  /* Inputs */
  .if-input, .if-select, .if-textarea { padding: 8px 10px; font-size: 13px; }
  .if-field { margin-bottom: 8px; }
  .if-label { font-size: 10px; }

  /* Login */
  .if-login-card { padding: 22px 14px; }
  .if-login-card h2 { font-size: 18px; }

  /* Page header */
  .if-page-header h1 { font-size: 15px; }
  .if-page-header { margin-bottom: 8px; }
}

/* Very small phones */
@media (max-width: 375px) {
  html { font-size: 13px; }
  .if-stat-card__value { font-size: 14px; }
  .if-stat-card { padding: 8px 6px; }
  .if-content { padding: 6px 6px calc(var(--bottom-nav) + 6px); }
}
/* ── Dashboard grid ─────────────────────────────────────────────────────────── */
.if-dash-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  margin-bottom: 24px;
}

/* 5-card stats: last card full-width on 2-col grid so nothing orphans oddly */
.if-stats-grid .if-stat-card:last-child:nth-child(odd) {
  grid-column: span 2;
}

/* Outstanding invoice action column: allow wrap */
.if-outstanding-actions { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; }

@media (max-width: 768px) {
  /* Stack chart + status side-by-side column into single column */
  .if-dash-grid { grid-template-columns: 1fr !important; gap: 14px; }

  /* Outstanding invoice table: card-style rows */
  .if-outstanding-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .if-outstanding-wrap table { min-width: 480px; }

  /* On very narrow, collapse outstanding to card list instead */
}

@media (max-width: 480px) {
  .if-dash-grid { gap: 10px; }
  /* Outstanding table: show as stacked cards */
  .if-outstanding-wrap { overflow-x: unset; }
  .if-outstanding-wrap table { display: none; }
  .if-outstanding-cards { display: flex !important; flex-direction: column; gap: 8px; }
}

/* Quick payment modal */
.if-quick-pay-modal { max-width: 360px; }

/* ── Notification Bell ──────────────────────────────────────────────────────── */
.if-notif-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.if-notif-bell {
  position: relative;
}

.if-notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--danger, #dc2626);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
}

.if-notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  background: var(--bg-popup);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 10px);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  z-index: 2000;
  max-height: 420px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.if-notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.if-notif-list {
  overflow-y: auto;
  flex: 1;
}

.if-notif-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.if-notif-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: default;
  transition: background .15s;
}

.if-notif-item:hover {
  background: var(--bg-elevated);
}

.if-notif-item.read {
  opacity: .65;
}

.if-notif-item:last-child {
  border-bottom: none;
}

.if-notif-item__icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.if-notif-item__icon svg {
  width: 16px;
  height: 16px;
}

.if-notif-item__body {
  flex: 1;
  min-width: 0;
}

.if-notif-item__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.if-notif-item__msg {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.if-notif-item__time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

@media (max-width: 480px) {
  .if-notif-panel {
    width: calc(100vw - 24px);
    right: -12px;
  }
}

/* ── Card expiry badge on card list ─────────────────────────────────────────── */
.if-card-expiry-warn {
  color: #d97706;
  font-size: 11px;
  font-weight: 600;
}

.if-card-expiry-err {
  color: #dc2626;
  font-size: 11px;
  font-weight: 600;
}


/* ── Permission Matrix ──────────────────────────────────────────────────────── */
.if-perm-matrix {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  font-size: 13px;
}

.if-perm-matrix__header {
  display: grid;
  grid-template-columns: 1fr repeat(3, 110px);
  gap: 0;
  padding: 10px 14px;
  background: var(--bg-elevated);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}

.if-perm-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}

.if-perm-row:last-child { border-bottom: none; }
.if-perm-row:hover { background: var(--bg-elevated); }

.if-perm-row--child {
  padding-left: 32px;
  background: var(--bg-base);
}
.if-perm-row--child .if-perm-row__label::before {
  content: '↳ ';
  color: var(--text-muted);
}

.if-perm-row__label {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.if-perm-row__controls {
  display: flex;
  gap: 4px;
}

.if-perm-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 80px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all .12s;
  font-size: 11px;
  color: var(--text-muted);
}

.if-perm-opt input[type="radio"] { display: none; }

.if-perm-opt:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-weight: 600;
}

.if-perm-opt--none:has(input:checked) {
  border-color: var(--text-muted);
  color: var(--text-muted);
  background: transparent;
}

.if-perm-opt--full:has(input:checked) {
  border-color: #22c55e;
  color: #22c55e;
  background: color-mix(in srgb, #22c55e 10%, transparent);
}

@media (max-width: 600px) {
  .if-perm-matrix__header { display: none; }
  .if-perm-row { grid-template-columns: 1fr; gap: 8px; }
  .if-perm-row__controls { flex-wrap: wrap; }
  .if-perm-opt { width: 70px; font-size: 10px; }
}

/* ── Reports expenses grid — stack on mobile ────────────────────────────────── */
@media (max-width: 700px) {
  .if-report-exp-grid {
    grid-template-columns: 1fr !important;
  }
  .if-report-exp-grid > div:first-child {
    order: 1;
  }
  .if-report-exp-grid > div:last-child {
    order: 2;
  }
}

/* ── Statements ─────────────────────────────────────────────────────────────── */

/* ═══════════════════════════════════════════════════════════════
   MOBILE FRIENDLY — comprehensive polish pass
   ═══════════════════════════════════════════════════════════════ */

/* ── Force all modals to respect full-width on mobile ─────────── */
@media (max-width: 768px) {
  .if-modal { max-width: 100% !important; width: 100% !important; }
  /* Wide content modals (search, bulk import): taller bottom sheet */
  .if-modal[style*="max-width:920"],
  .if-modal[style*="max-width:1000"],
  .if-modal[style*="max-width:860"] {
    max-height: 98dvh !important;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
}

/* ── Page header: wrap buttons on mobile ──────────────────────── */
@media (max-width: 600px) {
  .if-page-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .if-page-header > div:first-child { flex: 1 1 100%; }
  .if-page-header > div:last-child,
  .if-page-header > button,
  .if-page-header > a {
    width: 100%;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  .if-page-header > div > .if-btn,
  .if-page-header > .if-btn { flex: 1; justify-content: center; min-width: 120px; }
}

/* ── Filter bars: wrap controls ───────────────────────────────── */
@media (max-width: 640px) {
  .if-card .if-card__body,
  .if-card > div[style*="display:flex"],
  .if-card > div[style*="display: flex"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  /* Search inputs full width on mobile */
  .if-card input[type="text"].if-input,
  .if-card input[type="search"].if-input,
  .if-card .if-input[placeholder*="Search"],
  .if-card .if-input[placeholder*="Filter"] {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100%;
  }
  /* Date inputs: side by side */
  .if-card input[type="date"].if-input {
    flex: 1;
    min-width: 130px;
  }
}

/* ── Split stat card (expenses + profit): stack on small phones ── */
@media (max-width: 420px) {
  .if-stat-card[style*="display:flex"] {
    flex-direction: column !important;
  }
  .if-stat-card[style*="display:flex"] > div {
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px !important;
  }
  .if-stat-card[style*="display:flex"] > div:last-child {
    border-bottom: none;
  }
}

/* ── Tables: sticky actions column, better touch ─────────────── */
@media (max-width: 768px) {
  .if-table-wrap { position: relative; }
  .if-table td.actions,
  .if-table th.actions,
  .if-table td:last-child,
  .if-table th:last-child {
    position: sticky;
    right: 0;
    background: var(--bg-surface);
    z-index: 2;
    box-shadow: -2px 0 4px rgba(0,0,0,0.06);
  }
  .if-table tr:hover td:last-child { background: var(--bg-elevated); }
  /* Action buttons: icon only on mobile */
  .if-table .if-btn--sm svg { width: 14px; height: 14px; }
}

/* ── Topbar: tighter on mobile ────────────────────────────────── */
@media (max-width: 480px) {
  .if-topbar__actions { gap: 4px; }
  /* Hide "Settings" label in topbar, keep icon */
  .if-topbar .btn-label { display: none; }
}

/* ── Form modals: better layout on mobile ─────────────────────── */
@media (max-width: 600px) {
  .if-modal__body .if-input-group { flex-direction: column; gap: 0; }
  .if-modal__body .if-field { margin-bottom: 10px; }
  /* Radio groups: wrap */
  .if-modal__body > div[style*="display:flex"][style*="gap:16px"],
  .if-modal__body div[style*="gap:16px"] > label { flex-wrap: wrap; }
}

/* ── Bottom sheet handle indicator ───────────────────────────── */
@media (max-width: 768px) {
  .if-modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    margin: 8px auto 0;
    opacity: 0.5;
  }
}

/* ── Bulk import / statement search: full-height on mobile ──── */
@media (max-width: 768px) {
  /* These large modals should fill nearly the whole screen */
  .if-modal[style*="max-width:1000"],
  .if-modal[style*="max-width:920"] {
    height: 96dvh !important;
    max-height: 96dvh !important;
  }
  /* Their action bars wrap */
  #bi-action-bar > div,
  #sr-action-bar > div {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  #bi-action-bar select,
  #sr-action-bar select { max-width: 100% !important; width: 100%; }
  /* Import/search toolbar: filter + buttons wrap */
  #bi-action-bar > div > div,
  #sr-action-bar > div > div { flex: 1 1 100%; }
}

/* ── Payroll: tables scroll, tabs stay ───────────────────────── */
@media (max-width: 640px) {
    /* Payslip modal: readable */
  .payslip-modal .if-modal__body { padding: 8px; font-size: 12px; }
}

/* ── Invoice / quote line items: horizontal scroll ──────────── */
@media (max-width: 640px) {
  .if-line-items {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -8px;
    padding: 0 8px;
  }
}

/* ── Reports: charts full width ──────────────────────────────── */
@media (max-width: 640px) {
  .if-chart-wrap { height: 180px !important; }
}

/* ── Settings: nav tabs scroll ────────────────────────────────── */
@media (max-width: 640px) {
  }

/* ── Notification panel: full width on mobile ─────────────────── */
@media (max-width: 480px) {
  .if-notif-panel {
    width: calc(100vw - 24px) !important;
    right: 0 !important;
    left: 0 !important;
    margin: 0 12px;
  }
}

/* ── Touch feedback ───────────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .if-btn:active { opacity: 0.75; transform: scale(0.97); }
  .if-nav-link:active { background: var(--bg-overlay); }
  .if-table tr:active td { background: var(--bg-elevated); }
}

/* ── Permission-based visibility ─────────────────────────────────────────── */
/* ── Permission-based UI rules ─────────────────────────────────── */

/* VIEW: hide all action/edit/create buttons */
#if-content[data-perm="view"] .if-btn--primary,
#if-content[data-perm="view"] .if-btn--danger,
#if-content[data-perm="view"] .if-btn--secondary,
#if-content[data-perm="view"] .if-table-toolbar__actions,
#if-content[data-perm="view"] .if-fab,
#if-content[data-perm="view"] td.actions,
#if-content[data-perm="view"] th.actions,
#if-content[data-perm="view"] [id$="-save"],
#if-content[data-perm="view"] [id^="new-"],
#if-content[data-perm="view"] [id^="add-"] { display: none !important; }

/* VIEW: filter/search inputs remain interactive */

/* CREATE: hide delete-only buttons */
#if-content[data-perm="create"] .if-btn--danger,
#if-content[data-perm="create"] .write-off-btn,
#if-content[data-perm="create"] .del-pay { display: none !important; }

/* Perm level badge colours */
.if-perm-badge { display:inline-block;padding:3px 10px;border-radius:20px;font-size:11px;font-weight:600;cursor:pointer;user-select:none;transition:opacity 0.15s }
.if-perm-badge:hover { opacity:0.8 }
.if-perm-badge[data-level="none"]   { background:#ef4444;color:#fff }
.if-perm-badge[data-level="view"]   { background:#f97316;color:#fff }
.if-perm-badge[data-level="create"] { background:#22c55e;color:#fff }
.if-perm-badge[data-level="full"]   { background:#7c3aed;color:#fff }

/* Expenses: missing-slip row highlight — stronger in dark mode (low-opacity
   amber barely reads against a dark background), subtler in light mode.
   Selector specificity is bumped to beat .if-table tbody tr's own background
   rule (used for the mobile stacked-card layout), which would otherwise win. */
.if-table tbody tr.if-row-noslip {
  background: rgba(245,158,11,0.16);
  border-left: 3px solid #f59e0b;
}
html.if-light .if-table tbody tr.if-row-noslip {
  background: rgba(245,158,11,0.08);
  border-left: 3px solid #d97706;
}
