/* =============================================================================
   ATC Invoice — Sarafi design system
   Ported from /htdocs/sarafi/assets/css/app.css and mapped onto the WowDash
   markup this app already uses, so all 30-plus pages restyle from one file
   instead of being rewritten.

   Loaded last, after style.css, so it wins.
   ========================================================================== */

/* ============ THEME VARIABLES ============ */
:root {
  /* Light theme (default) */
  --bg-page:        #f0eeea;
  --bg-surface:     #ffffff;
  --bg-surface2:    #f5f4f1;
  --bg-surface3:    #ebe9e4;
  --bg-card:        #ffffff;
  --bg-card-hover:  #f5f4f1;

  --border:         rgba(0,0,0,0.07);
  --border-strong:  rgba(0,0,0,0.12);

  --text-primary:   #18181a;
  --text-secondary: #52504d;
  --text-muted:     #989690;

  --accent:         #1d6f4e;
  --accent-hover:   #145c3e;
  --accent-light:   rgba(29,111,78,0.09);
  --gradient-accent: linear-gradient(135deg, #1d6f4e 0%, #0f4a33 100%);
  --border-accent:  rgba(29,111,78,0.3);

  --danger:         #c23b3b;
  --danger-light:   rgba(194,59,59,0.1);
  --warning:        #b5680d;
  --warning-light:  rgba(181,104,13,0.1);
  --info:           #1a5fa8;
  --info-light:     rgba(26,95,168,0.1);
  --success:        #1d8a5e;
  --success-light:  rgba(29,138,94,0.1);
  --purple:         #7c3aed;
  --purple-light:   rgba(124,58,237,0.1);

  --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 8px 24px rgba(0,0,0,0.09), 0 2px 6px rgba(0,0,0,0.05);
  --shadow-lg:  0 16px 48px rgba(0,0,0,0.11), 0 4px 12px rgba(0,0,0,0.07);
  --shadow-glow: 0 0 0 3px rgba(29,111,78,0.12);

  --radius:     12px;
  --radius-lg:  18px;
  --radius-xl:  24px;
  --radius-sm:  8px;
  --font:       'DM Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', ui-monospace, monospace;

  --transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-page:        #0c0c0a;
  --bg-surface:     #161614;
  --bg-surface2:    #1f1f1c;
  --bg-surface3:    #2a2a26;
  --bg-card:        #1f1f1c;
  --bg-card-hover:  #2a2a26;

  --border:         rgba(255,255,255,0.06);
  --border-strong:  rgba(255,255,255,0.11);

  --text-primary:   #f0efe9;
  --text-secondary: #9a9890;
  --text-muted:     #5a5855;

  --accent:         #4ade98;
  --accent-hover:   #38c47e;
  --accent-light:   rgba(74,222,152,0.1);
  --gradient-accent: linear-gradient(135deg, #4ade98 0%, #22c55e 100%);
  --border-accent:  rgba(74,222,152,0.3);

  --danger:         #f87171;
  --danger-light:   rgba(248,113,113,0.1);
  --warning:        #fbbf24;
  --warning-light:  rgba(251,191,36,0.1);
  --info:           #60a5fa;
  --info-light:     rgba(96,165,250,0.1);
  --success:        #4ade98;
  --success-light:  rgba(74,222,152,0.1);
  --purple:         #a78bfa;
  --purple-light:   rgba(167,139,250,0.1);

  --shadow-xs:  0 1px 2px rgba(0,0,0,0.4);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:  0 8px 24px rgba(0,0,0,0.6), 0 2px 6px rgba(0,0,0,0.4);
  --shadow-lg:  0 16px 48px rgba(0,0,0,0.7), 0 4px 12px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 0 3px rgba(74,222,152,0.12);
}

/* ============ BASE ============ */

body {
  background: var(--bg-page) !important;
  color: var(--text-primary) !important;
  font-family: var(--font) !important;
  font-size: 0.92rem;
}

h1, h2, h3, h4, h5, h6,
.card-title, .fw-semibold, .fw-bold {
  font-family: var(--font) !important;
  color: var(--text-primary);
  letter-spacing: -0.015em;
}

/* Figures line up in columns and read as data, not prose. */
.atc-num, .atc-stat-value, .mono, .amount,
td.atc-num, .table td.atc-num {
  font-family: var(--font-mono) !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* iconify-icon is a custom element and defaults to inline with no baseline
   alignment, which dropped icons onto their own line above headings. */
iconify-icon {
    display: inline-block;
    vertical-align: -0.125em;
    line-height: 1;
}

/* The template's success/primary utility colours map onto the accent, so a
   page written against Bootstrap tones still lands in the palette. */
.text-success, .text-success-600 { color: var(--accent) !important; }
.bg-success, .bg-success-600 { background: var(--accent) !important; }
.text-danger, .required { color: var(--danger) !important; }

::selection { background: var(--accent-light); color: var(--text-primary); }

/* Scrollbars, so the chrome matches the surface rather than the OS default */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ SIDEBAR ============ */

.sidebar,
.sidebar .sidebar-menu-area {
  background: var(--bg-surface) !important;
  border-right: 1px solid var(--border) !important;
}

.sidebar .sidebar-logo {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.sidebar-menu li a {
  color: var(--text-secondary) !important;
  border-radius: var(--radius-sm) !important;
  font-weight: 500;
  font-size: 0.875rem;
  transition: var(--transition);
}

.sidebar-menu li a:hover {
  background: var(--accent-light) !important;
  color: var(--accent) !important;
}

.sidebar-menu li a.active-page,
.sidebar-menu li a.active {
  background: var(--gradient-accent) !important;
  color: #fff !important;
  box-shadow: 0 2px 10px rgba(29,111,78,0.25);
}

[data-theme="dark"] .sidebar-menu li a.active-page,
[data-theme="dark"] .sidebar-menu li a.active {
  color: #0c0c0a !important;
}

.sidebar-menu li a.active-page .menu-icon,
.sidebar-menu li a.active .menu-icon {
  color: inherit !important;
  background: transparent !important;
}

.sidebar-menu-group-title {
  color: var(--text-muted) !important;
  font-size: 0.68rem !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* An open dropdown parent kept the template's blue fill while its active child
   was green. Both now use the accent. */
.sidebar-menu li.dropdown.open > a,
.sidebar-menu li.dropdown.dropdown-open > a,
.sidebar-menu li.dropdown.open > a:hover,
.sidebar-menu li.dropdown.dropdown-open > a:hover {
  background: var(--accent-light) !important;
  color: var(--accent) !important;
}

.sidebar-menu li.dropdown.open > a .menu-icon,
.sidebar-menu li.dropdown.dropdown-open > a .menu-icon,
.sidebar-menu li.dropdown.open > a::after,
.sidebar-menu li.dropdown.dropdown-open > a::after {
  color: var(--accent) !important;
  background: transparent !important;
}

/* Submenu rows: the bullet and the active pill */
.sidebar-submenu li a { color: var(--text-secondary) !important; font-size: 0.83rem; }
.sidebar-submenu li a:hover { color: var(--accent) !important; }

.sidebar-submenu li a.active-page,
.sidebar-submenu li a.active {
  background: var(--gradient-accent) !important;
  color: #fff !important;
}

[data-theme="dark"] .sidebar-submenu li a.active-page,
[data-theme="dark"] .sidebar-submenu li a.active { color: #0c0c0a !important; }

.sidebar-submenu li a::before,
.sidebar-submenu li a .ri-circle-fill { color: currentColor !important; }

/* Brand */
.sidebar-logo, .sidebar .sidebar-logo * {
  color: var(--accent) !important;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ============ TOPBAR ============ */

.navbar-header {
  background: var(--bg-surface) !important;
  border-bottom: 1px solid var(--border) !important;
  box-shadow: none !important;
}

.navbar-header .sidebar-toggle,
.navbar-header .sidebar-mobile-toggle,
.navbar-header button {
  color: var(--text-secondary);
}

/* ============ PAGE ============ */

.dashboard-main-body {
  background: var(--bg-page) !important;
}

.dashboard-main-body > .d-flex h6 {
  font-size: 1.15rem;
  font-weight: 700;
}

/* ============ CARDS ============ */

.card {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-sm) !important;
  transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-md) !important; }

.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 1.1rem 1.15rem;
}

.card-footer { background: transparent !important; border-top: 1px solid var(--border) !important; }

/* Some pages give the card header a solid accent fill. Keep that, but tie it
   to the palette and make sure the text reads against it. */
.card-header.bg-success,
.card-header.bg-primary,
.card-header.bg-primary-600 {
  background: var(--gradient-accent) !important;
  border-bottom: 0 !important;
  border-radius: calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0 0;
}

.card-header.bg-success *,
.card-header.bg-primary *,
.card-header.bg-primary-600 * { color: #fff !important; }

[data-theme="dark"] .card-header.bg-success *,
[data-theme="dark"] .card-header.bg-primary *,
[data-theme="dark"] .card-header.bg-primary-600 * { color: #0c0c0a !important; }

/* ---- Form section headings -------------------------------------------------
   These are h6 elements, but the template sizes h6 like a page title, so an
   "Invoice Details" sub-heading rendered larger than the card title above it. */
.atc-form h6,
.card-body > .row > .col-12 > h6 {
  font-size: 0.78rem !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted) !important;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding-bottom: 0.6rem;
  margin-bottom: 1.1rem !important;
  border-bottom: 1px solid var(--border);
}

.atc-form h6 iconify-icon,
.card-body > .row > .col-12 > h6 iconify-icon {
  font-size: 1rem;
  color: var(--accent) !important;
  margin: 0 !important;
}

.card-title, .atc-panel-title {
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.015em;
}

.atc-panel-sub {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin: 3px 0 0;
}

/* ============ STAT TILES ============ */
/* Sarafi's stat-card: tinted gradient, accent hairline on top, soft icon chip */

.atc-stat-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg) !important;
  border: 1px solid var(--border) !important;
  background: var(--bg-card) !important;
}

/* A soft accent glow around the tile, instead of the hard rule that used to
   sit across the top edge. */
.atc-stat-card {
  box-shadow:
    0 0 0 1px var(--card-glow-ring, rgba(29, 111, 78, .10)),
    0 4px 18px -6px var(--card-glow, rgba(29, 111, 78, .22)),
    var(--shadow-xs) !important;
}

.atc-stat-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 0 1px var(--card-glow-ring, rgba(29, 111, 78, .18)),
    0 10px 30px -8px var(--card-glow, rgba(29, 111, 78, .34)),
    var(--shadow-sm) !important;
}

/* The icon chip glows in the tile's own tone */
.atc-stat-card .atc-stat-icon {
  box-shadow: 0 0 14px -2px var(--card-glow, rgba(29, 111, 78, .35));
}

.atc-stat-card .atc-stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-primary);
}

.atc-stat-card .atc-stat-label {
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.atc-stat-card .atc-stat-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--card-accent-light, var(--accent-light)) !important;
  color: var(--card-accent, var(--accent)) !important;
}

.atc-stat-card .atc-stat-icon iconify-icon { color: inherit !important; }

/* Accent per tile, replacing the template's bg-gradient-start-N */
.atc-stat-card.tone-accent  { --card-accent: var(--accent);  --card-accent-light: var(--accent-light);
  --card-glow: rgba(29,111,78,0.28);  --card-glow-ring: rgba(29,111,78,0.14);
  background: linear-gradient(135deg, rgba(29,111,78,0.07) 0%, rgba(29,111,78,0.02) 100%) !important; }
.atc-stat-card.tone-warning { --card-accent: var(--warning); --card-accent-light: var(--warning-light);
  --card-glow: rgba(181,104,13,0.28); --card-glow-ring: rgba(181,104,13,0.14);
  background: linear-gradient(135deg, rgba(181,104,13,0.07) 0%, rgba(181,104,13,0.02) 100%) !important; }
.atc-stat-card.tone-success { --card-accent: var(--success); --card-accent-light: var(--success-light);
  --card-glow: rgba(29,138,94,0.28);  --card-glow-ring: rgba(29,138,94,0.14);
  background: linear-gradient(135deg, rgba(29,138,94,0.07) 0%, rgba(29,138,94,0.02) 100%) !important; }
.atc-stat-card.tone-purple  { --card-accent: var(--purple);  --card-accent-light: var(--purple-light);
  --card-glow: rgba(124,58,237,0.28); --card-glow-ring: rgba(124,58,237,0.14);
  background: linear-gradient(135deg, rgba(124,58,237,0.07) 0%, rgba(124,58,237,0.02) 100%) !important; }
.atc-stat-card.tone-info    { --card-accent: var(--info);    --card-accent-light: var(--info-light);
  --card-glow: rgba(26,95,168,0.28);  --card-glow-ring: rgba(26,95,168,0.14);
  background: linear-gradient(135deg, rgba(26,95,168,0.07) 0%, rgba(26,95,168,0.02) 100%) !important; }

[data-theme="dark"] .atc-stat-card.tone-accent  { --card-glow: rgba(74,222,152,0.30);  --card-glow-ring: rgba(74,222,152,0.18); background: linear-gradient(135deg, rgba(74,222,152,0.07) 0%, rgba(74,222,152,0.02) 100%) !important; }
[data-theme="dark"] .atc-stat-card.tone-warning { --card-glow: rgba(251,191,36,0.28); --card-glow-ring: rgba(251,191,36,0.16); background: linear-gradient(135deg, rgba(251,191,36,0.07) 0%, rgba(251,191,36,0.02) 100%) !important; }
[data-theme="dark"] .atc-stat-card.tone-success { --card-glow: rgba(74,222,152,0.28);  --card-glow-ring: rgba(74,222,152,0.16); background: linear-gradient(135deg, rgba(74,222,152,0.07) 0%, rgba(74,222,152,0.02) 100%) !important; }
[data-theme="dark"] .atc-stat-card.tone-purple  { --card-glow: rgba(167,139,250,0.28); --card-glow-ring: rgba(167,139,250,0.16); background: linear-gradient(135deg, rgba(167,139,250,0.07) 0%, rgba(167,139,250,0.02) 100%) !important; }

/* Neutralise the template's own gradient tiles wherever they survive */
.bg-gradient-start-1, .bg-gradient-start-2, .bg-gradient-start-3,
.bg-gradient-start-4, .bg-gradient-start-5 {
  background: var(--bg-card) !important;
}

/* ============ TABLES ============ */

.table, .atc-table {
  --bs-table-bg: transparent;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.table > :not(caption) > * > * { background: transparent; }

.atc-table thead th,
.table thead th {
  background: var(--bg-surface2) !important;
  color: var(--text-muted) !important;
  font-size: 0.68rem !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
  padding: 0.8rem 1rem !important;
  border-bottom: 1px solid var(--border) !important;
}

.atc-table tbody td,
.table tbody td {
  padding: 0.82rem 1rem !important;
  font-size: 0.86rem;
  vertical-align: middle;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border) !important;
  border-top: 0 !important;
}

.atc-table tbody tr:last-child td,
.table tbody tr:last-child td { border-bottom: 0 !important; }

.atc-table tbody tr,
.table tbody tr { transition: background 0.12s ease; }

.atc-table tbody tr:hover,
.table tbody tr:hover { background: var(--bg-card-hover) !important; }

.atc-table tbody td:first-child { color: var(--text-primary); font-weight: 500; }

.atc-table .atc-num { text-align: right; white-space: nowrap; }
.atc-table th.atc-num { text-align: right; }

/* Sortable headers */
.atc-table th a.atc-sort {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.atc-table th a.atc-sort:hover { color: var(--accent); }
.atc-table th a.atc-sort .atc-sort-icon { opacity: 0.35; }
.atc-table th a.atc-sort.is-active { color: var(--accent); }
.atc-table th a.atc-sort.is-active .atc-sort-icon { opacity: 1; }

/* Row avatar: initial in the accent tone, replacing the template's purple
   circle that matched nothing else in the palette. */
.atc-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  line-height: 1;
}

/* ============ BADGES ============ */

.badge {
  border-radius: 99px !important;
  font-weight: 600 !important;
  font-size: 0.7rem !important;
  letter-spacing: 0.02em;
  padding: 0.32rem 0.7rem !important;
  border: 0 !important;
}

.atc-badge-paid      { background: var(--success-light) !important; color: var(--success) !important; }
.atc-badge-part      { background: var(--info-light)    !important; color: var(--info) !important; }
.atc-badge-sent      { background: var(--warning-light) !important; color: var(--warning) !important; }
.atc-badge-draft     { background: var(--bg-surface3)   !important; color: var(--text-muted) !important; }
.atc-badge-overdue   { background: var(--danger-light)  !important; color: var(--danger) !important; }
.atc-badge-cancelled { background: var(--bg-surface3)   !important; color: var(--text-muted) !important; }

/* ============ BUTTONS ============ */

.btn {
  border-radius: var(--radius-sm) !important;
  font-weight: 600;
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-primary, .btn-primary-600 {
  background: var(--gradient-accent) !important;
  border: 0 !important;
  color: #fff !important;
  box-shadow: 0 2px 10px rgba(29,111,78,0.22);
}

.btn-primary:hover, .btn-primary-600:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(29,111,78,0.3);
  color: #fff !important;
}

[data-theme="dark"] .btn-primary,
[data-theme="dark"] .btn-primary-600 { color: #0c0c0a !important; }

.btn-outline-primary-600, .btn-outline-primary {
  background: transparent !important;
  border: 1px solid var(--border-accent) !important;
  color: var(--accent) !important;
}

.btn-outline-primary-600:hover, .btn-outline-primary:hover {
  background: var(--accent-light) !important;
  color: var(--accent) !important;
}

.btn-outline-danger {
  border: 1px solid rgba(194,59,59,0.35) !important;
  color: var(--danger) !important;
  background: transparent !important;
}
.btn-outline-danger:hover { background: var(--danger) !important; color: #fff !important; }

/* Round icon action buttons in table rows */
.w-32-px.rounded-circle {
  transition: var(--transition);
  border: 0;
}
.w-32-px.rounded-circle:hover { transform: scale(1.1); }

.bg-primary-light  { background: var(--accent-light) !important; }
.text-primary-600  { color: var(--accent) !important; }
.bg-info-focus     { background: var(--info-light) !important; }
.text-info-main    { color: var(--info) !important; }
.bg-warning-focus  { background: var(--warning-light) !important; }
.text-warning-main { color: var(--warning) !important; }
.bg-danger-focus   { background: var(--danger-light) !important; }
.text-danger-main  { color: var(--danger) !important; }
.bg-success-focus  { background: var(--success-light) !important; }
.text-success-main { color: var(--success) !important; }

.text-primary-light   { color: var(--text-secondary) !important; }
.text-secondary-light { color: var(--text-muted) !important; }

/* ============ FORMS ============ */

.form-control, .form-select {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-primary) !important;
  font-size: 0.87rem;
  padding: 0.6rem 0.85rem;
  transition: var(--transition);
}

.form-control:hover, .form-select:hover { border-color: var(--border-accent) !important; }

.form-control:focus, .form-select:focus {
  border-color: var(--accent) !important;
  box-shadow: var(--shadow-glow) !important;
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
}

.form-control::placeholder { color: var(--text-muted) !important; }

.form-label {
  color: var(--text-secondary) !important;
  font-weight: 600;
  font-size: 0.78rem;
  margin-bottom: 0.35rem;
}

.form-check-input:checked {
  background-color: var(--accent) !important;
  border-color: var(--accent) !important;
}
.form-check-input:focus { box-shadow: var(--shadow-glow) !important; }

/* The switch and its label were touching, so "Include VAT on this invoice"
   ran straight into the toggle. */
.form-switch { display: flex; align-items: center; gap: 0.6rem; padding-left: 0; }
.form-switch .form-check-input {
  width: 2.4rem;
  height: 1.3rem;
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
}
.form-switch .form-check-label {
  margin: 0;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Required-field marker */
.form-label .required, .required {
  color: var(--danger) !important;
  font-weight: 700;
  margin-left: 2px;
}

/* Long forms read better with slightly tighter rows than the template default */
.atc-form .form-group { margin-bottom: 0; }
.atc-form .row.g-3 { --bs-gutter-y: 1rem; }

.atc-form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--bg-surface);
}

.atc-form-section > legend,
.atc-form-section > .atc-form-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  float: none;
  width: auto;
}

/* Sticky save bar on long forms */
.atc-form-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg-page) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 0.9rem 0;
  margin-top: 0.5rem;
}

/* ============ FILTER BAR ============ */

.atc-filter-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  box-shadow: var(--shadow-sm);
}

.atc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.28rem 0.7rem;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--border-accent);
  text-decoration: none;
  transition: var(--transition);
}

/* Search field with a leading icon and a busy indicator while the debounced
   live search is in flight. */
.atc-search { position: relative; }

.atc-search .atc-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
  pointer-events: none;
}

.atc-search .form-control { padding-left: 2.3rem; }

/* Hide the browser's own clear button; it fights the spinner for space. */
.atc-search input[type="search"]::-webkit-search-cancel-button { display: none; }

.atc-search .atc-search-spinner {
  position: absolute;
  right: 0.7rem;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.atc-search.is-busy .atc-search-spinner {
  opacity: 1;
  animation: atc-spin 0.6s linear infinite;
}

@keyframes atc-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .atc-search.is-busy .atc-search-spinner { animation: none; }
}

.atc-chip:hover { background: var(--accent); color: #fff; }
[data-theme="dark"] .atc-chip:hover { color: #0c0c0a; }
.atc-chip .atc-chip-x { opacity: 0.65; }
.atc-chip:hover .atc-chip-x { opacity: 1; }

/* ============ ALERTS ============ */

.alert {
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  font-size: 0.86rem;
}
.alert-success { background: var(--success-light) !important; color: var(--success) !important; border-color: transparent !important; }
.alert-danger  { background: var(--danger-light)  !important; color: var(--danger)  !important; border-color: transparent !important; }

/* ============ PAGINATION ============ */

.pagination .page-link {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm) !important;
  margin: 0 2px;
  font-size: 0.82rem;
  font-weight: 600;
}
.pagination .page-link:hover { background: var(--accent-light); color: var(--accent); }
.pagination .page-item.active .page-link {
  background: var(--gradient-accent);
  border-color: transparent;
  color: #fff;
}
[data-theme="dark"] .pagination .page-item.active .page-link { color: #0c0c0a; }
.pagination .page-item.disabled .page-link { opacity: 0.45; }

/* ============ EMPTY STATE ============ */

.atc-empty { padding: 3.5rem 1.5rem; text-align: center; }
.atc-empty iconify-icon { font-size: 44px; opacity: 0.3; color: var(--text-muted); }
.atc-empty p { margin: 0.85rem 0 0; color: var(--text-muted); font-size: 0.87rem; }

/* ============ MODALS ============ */

.modal-content {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  color: var(--text-primary);
}
.modal-header, .modal-footer { border-color: var(--border) !important; }

/* ============ INSTALL PROMPT ============ */

.atc-install-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 0.5rem;
}

.atc-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--border-accent);
  border-radius: 99px;
  padding: 0.35rem 0.85rem;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.atc-install-btn:hover { background: var(--accent); color: #fff; }
[data-theme="dark"] .atc-install-btn:hover { color: #0c0c0a; }

.atc-install-dismiss {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  line-height: 1;
  border-radius: 50%;
}

.atc-install-dismiss:hover { color: var(--text-primary); background: var(--bg-surface3); }

@media (max-width: 575px) {
  .atc-install-btn span { display: none; }
  .atc-install-btn { padding: 0.4rem 0.5rem; }
}

/* ============ SIGN IN ============ */

.atc-auth-body { background: var(--bg-page); }

.atc-auth {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
  min-height: 100dvh;   /* dvh accounts for mobile browser chrome */
}

/* ---- Brand panel ---- */

.atc-auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3rem;
  color: #fff;
  background: var(--gradient-accent);
  overflow: hidden;
}

/* A soft light source, so the panel is not a flat block of colour */
.atc-auth-brand::after {
  content: '';
  position: absolute;
  top: -30%;
  right: -20%;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .16) 0%, transparent 70%);
  pointer-events: none;
}

.atc-auth-brand-inner { position: relative; margin: auto 0; max-width: 30rem; }

.atc-auth-logo {
  border-radius: 16px;
  background: #fff;
  padding: 6px;
  margin-bottom: 1.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.atc-auth-brand h1 {
  color: #fff;
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -.03em;
  margin: 0 0 .35rem;
}

.atc-auth-tagline {
  font-size: .95rem;
  font-weight: 600;
  opacity: .9;
  margin: 0 0 1.5rem;
}

.atc-auth-blurb {
  font-size: .95rem;
  line-height: 1.65;
  opacity: .82;
  margin: 0;
  max-width: 26rem;
}

.atc-auth-foot {
  position: relative;
  font-size: .78rem;
  opacity: .7;
  margin: 0;
}

/* ---- Form side ---- */

.atc-auth-form {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  background: var(--bg-page);
}

.atc-auth-form-inner { width: 100%; max-width: 25rem; }

.atc-auth-form h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.025em;
  margin: 0 0 .35rem;
}

.atc-auth-sub {
  color: var(--text-muted);
  font-size: .9rem;
  margin: 0 0 1.75rem;
}

.atc-auth-mobile-brand { display: none; }

/* Inputs with a leading icon and, for the password, a reveal button */

.atc-input-icon { position: relative; }

.atc-input-icon > iconify-icon {
  position: absolute;
  left: .9rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.15rem;
  color: var(--text-muted);
  pointer-events: none;
}

.atc-input-icon .form-control {
  height: 3.25rem;
  padding-left: 2.75rem;
  padding-right: 2.75rem;
  background: var(--bg-surface) !important;
}

.atc-reveal {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.atc-reveal:hover { color: var(--accent); background: var(--accent-light); }

.atc-caps-hint {
  display: flex;
  align-items: center;
  gap: .3rem;
  margin: .45rem 0 0;
  font-size: .75rem;
  font-weight: 600;
  color: var(--warning);
}

.atc-auth-submit {
  height: 3.1rem;
  font-size: .95rem;
  font-weight: 700;
}

.atc-auth-help {
  margin: 1.75rem 0 0;
  text-align: center;
  font-size: .78rem;
  color: var(--text-muted);
}

/* ---- Narrow screens: the brand panel becomes a small header ---- */

@media (max-width: 991.98px) {
  .atc-auth { grid-template-columns: 1fr; }

  .atc-auth-brand { display: none; }

  .atc-auth-mobile-brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin-bottom: 2rem;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -.02em;
  }

  .atc-auth-mobile-brand img {
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
  }

  .atc-auth-form { align-items: flex-start; padding-top: 3rem; }
}

@media (max-width: 575.98px) {
  .atc-auth-form { padding: 2rem 1.15rem; }
  .atc-auth-form h2 { font-size: 1.4rem; }
  /* 16px stops iOS zooming the page when a field takes focus */
  .atc-input-icon .form-control { font-size: 16px; }
}

/* ============ MOBILE BOTTOM NAVIGATION ============ */
/* Below 992px the sidebar is off-canvas, so the main destinations need to be
   reachable without opening it first. */

.atc-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1040;
  /* Opaque: content scrolling underneath must not show through the labels. */
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 0 var(--border), 0 -8px 24px rgba(0, 0, 0, .07);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0));
  align-items: stretch;
}

.atc-bottom-nav .bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--text-muted);
  font-family: var(--font);
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
  transition: color .16s ease, background .16s ease;
  min-height: 48px;
}

.atc-bottom-nav .bn-item:active { background: var(--bg-surface2); }

.atc-bottom-nav .bn-item:hover,
.atc-bottom-nav .bn-item:focus-visible { color: var(--text-secondary); }

.atc-bottom-nav .bn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  font-size: 1.28rem;
  line-height: 1;
}

.atc-bottom-nav .bn-label {
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: .005em;
}

/* Active tab: a soft accent pill behind the icon, no hard rule anywhere. */
.atc-bottom-nav .bn-item.active { color: var(--accent); }
.atc-bottom-nav .bn-item.active .bn-label { font-weight: 700; }

.atc-bottom-nav .bn-item.active .bn-icon {
  position: relative;
}

.atc-bottom-nav .bn-item.active .bn-icon::before {
  content: '';
  position: absolute;
  width: 42px;
  height: 26px;
  border-radius: 999px;
  background: var(--accent-light);
  z-index: -1;
}

/* New Invoice: the primary action, raised clear of the bar. Its label sits
   inside the same rhythm as the others so the row still reads as one line. */
.atc-bottom-nav .bn-primary { color: var(--accent); }

.atc-bottom-nav .bn-primary .bn-icon {
  width: 44px;
  height: 44px;
  margin-top: -22px;
  margin-bottom: 1px;
  border-radius: 50%;
  font-size: 1.4rem;
  color: #fff;
  background: var(--gradient-accent);
  border: 4px solid var(--bg-page);
  box-shadow: 0 4px 12px -2px rgba(29, 111, 78, .45);
}

[data-theme="dark"] .atc-bottom-nav .bn-primary .bn-icon {
  color: #0c0c0a;
  box-shadow: 0 4px 12px -2px rgba(74, 222, 152, .4);
}

.atc-bottom-nav .bn-primary .bn-icon::before { display: none !important; }
.atc-bottom-nav .bn-primary:active { background: none; }

@media (max-width: 991.98px) {
  .atc-bottom-nav { display: flex; }

  /* Clear the bar so the last row of any page stays reachable */
  .dashboard-main-body {
    padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0)) !important;
  }

  /* A sticky form bar must sit above the nav, not under it */
  .atc-form-actions {
    bottom: calc(4rem + env(safe-area-inset-bottom, 0));
  }
}

/* ============ RESPONSIVE ============ */

@media (max-width: 991.98px) {
  /* Page header stacks instead of squeezing the title */
  .dashboard-main-body > .d-flex.justify-content-between {
    align-items: flex-start !important;
  }

  .atc-stat-card .atc-stat-value { font-size: 1.45rem; }
}

@media (max-width: 767.98px) {
  body { font-size: 0.88rem; }

  .dashboard-main-body { padding: 1rem 0.85rem; }

  .card { border-radius: var(--radius) !important; }
  .card-body { padding: 1rem; }

  /* Header actions become full width buttons rather than a cramped row */
  .dashboard-main-body > .d-flex.justify-content-between > .d-flex {
    width: 100%;
  }
  .dashboard-main-body > .d-flex.justify-content-between > .d-flex .btn {
    flex: 1;
    justify-content: center;
  }

  .atc-filter-bar { padding: 0.85rem; border-radius: var(--radius) !important; }

  /* Filters stack, and each control gets a full-width tap target */
  .atc-filter-bar .row > [class*="col-"] { width: 100%; flex: 0 0 100%; max-width: 100%; }

  /* Tables scroll sideways inside their own container. The page itself must
     never scroll horizontally. */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .atc-table thead th,
  .atc-table tbody td { padding: 0.7rem 0.75rem !important; }

  .atc-table tbody td { font-size: 0.82rem; }

  /* Truncated cells were sized for a desktop column */
  .atc-table .text-truncate { max-width: 150px !important; }

  /* Row actions wrap rather than forcing the table wider */
  .atc-table td .d-flex.gap-1 { flex-wrap: nowrap; }

  /* Pager and page-size sit on their own lines */
  .card-footer { flex-direction: column; align-items: stretch !important; gap: 0.75rem !important; }
  .card-footer nav { display: flex; justify-content: center; }

  /* Stat tiles: two per row reads better than one tall column */
  .atc-stat-card .atc-stat-value { font-size: 1.3rem; }
  .atc-stat-card .atc-stat-icon { width: 38px; height: 38px; }
  .atc-stat-card .card-body { padding: 0.85rem !important; }

  /* Forms: one column, and inputs at 16px so iOS does not zoom on focus */
  .atc-form .form-control,
  .atc-form .form-select,
  .atc-filter-bar .form-control,
  .atc-filter-bar .form-select { font-size: 16px; }

  .atc-form-section { padding: 1rem; }

  /* Modals meet the bottom of the screen, which is easier to reach */
  .modal-dialog { margin: 0.5rem; }

  /* Active filter chips wrap */
  .atc-chip { font-size: 0.7rem; }
}

@media (max-width: 575.98px) {
  .dashboard-main-body { padding: 0.85rem 0.7rem; }

  .dashboard-main-body > .d-flex h6 { font-size: 1.05rem; }

  /* Bulk action bars stack */
  #bulkBar .d-flex,
  #atcListForm #bulkBar .d-flex { flex-direction: column; align-items: stretch !important; }
  #bulkBar .btn { width: 100%; }

  /* Aging tiles: two across rather than one */
  .atc-stat-card .atc-stat-value { font-size: 1.15rem; }
}

/* Nothing may push the page sideways */
html, body { max-width: 100%; overflow-x: hidden; }

/* ============ RESPONSIVE INVOICE DOCUMENTS ============ */
/* The documents are fixed at 800px for A4. On a phone that forces a sideways
   scroll of the whole page, so they scale down instead. Print is untouched. */

@media screen and (max-width: 860px) {
  .invoice-container {
    width: auto !important;
    max-width: 100%;
    margin: 10px !important;
    padding: 12px !important;
  }

  .letterhead { flex-wrap: wrap; gap: 8px; }
  .letterhead .logo-left, .letterhead .logo-right { width: 60px !important; }
  .letterhead p { font-size: 11px !important; }

  .ref-date, .to-from { flex-direction: column; gap: 10px; }
  .to-from div { width: 100% !important; }

  .items-table, .context-table { font-size: 11px; }
  .items-table th, .items-table td,
  .context-table th, .context-table td { padding: 4px !important; font-size: 11px !important; }
  .context-table th { width: 110px !important; }

  .invoice-header h2 { font-size: 18px !important; }
}

/* ============ PRINT ============ */

@media print {
  .atc-filter-bar, .atc-form-actions, .sidebar, .navbar-header,
  .atc-bottom-nav, .print-button { display: none !important; }
  .dashboard-main-body { padding-bottom: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border: 0 !important; }
}

/* ============ CONFIRM MODAL ============
 * Replaces window.confirm() for [data-confirm] actions (assets/js/atc-forms.js).
 * A native confirm() cannot be themed or animated and looks foreign next to
 * the rest of the app, so destructive actions get this instead.
 */

.atc-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1080;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 12, 10, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.atc-confirm-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease;
}

.atc-confirm-modal {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 22px;
  text-align: center;
  transform: scale(0.9) translateY(10px);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

.atc-confirm-backdrop.is-open .atc-confirm-modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.atc-confirm-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--danger-light);
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.6);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) 0.08s, opacity 0.2s ease 0.08s;
}

.atc-confirm-backdrop.is-open .atc-confirm-icon {
  transform: scale(1);
  opacity: 1;
}

.atc-confirm-icon svg { width: 26px; height: 26px; }

.atc-confirm-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 6px;
}

.atc-confirm-message {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0 0 22px;
}

.atc-confirm-actions {
  display: flex;
  gap: 10px;
}

.atc-confirm-btn {
  flex: 1;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.atc-confirm-btn-cancel {
  background: var(--bg-surface2);
  border-color: var(--border);
  color: var(--text-primary);
}

.atc-confirm-btn-cancel:hover { background: var(--bg-surface3); }

.atc-confirm-btn-danger {
  background: var(--danger);
  color: #fff;
}

.atc-confirm-btn-danger:hover { filter: brightness(0.92); }

.atc-confirm-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .atc-confirm-backdrop, .atc-confirm-modal, .atc-confirm-icon {
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 420px) {
  .atc-confirm-actions { flex-direction: column-reverse; }
}

/* ============ DRAWN ICONS ============
   partials/drawn-icons.php, generated by tools/atc-icons/build.py.
   Pen-and-ink: one firm pen, one fine pen, one flat tone, all in currentColor. */

.atc-ico {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  flex-shrink: 0;
  vertical-align: -0.22em;
  overflow: visible;
}
.atc-ico-l { stroke-width: 2; }
.atc-ico-f { stroke-width: 1.25; stroke-opacity: .75; }

.sidebar-menu li a .atc-ico.menu-icon { width: 1.3em; height: 1.3em; }
.atc-bottom-nav .bn-icon .atc-ico { width: 24px; height: 24px; }
.atc-bottom-nav .bn-primary .bn-icon .atc-ico { width: 22px; height: 22px; }
.atc-bottom-nav .bn-primary .bn-icon .atc-ico-l { stroke-width: 2.4; }

.atc-plate {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.atc-plate-w { fill: currentColor; fill-opacity: .14; stroke: none; }
.atc-plate-l { stroke-width: 1.3; }
.atc-plate-f { stroke-width: .72; stroke-opacity: .8; }

/* Stat tiles: the plate stands on its own, no chip behind it. */
.atc-stat-card .atc-stat-icon.has-plate {
  width: 64px;
  height: 64px;
  background: none !important;
  box-shadow: none;
  border-radius: 0;
}
[data-theme="dark"] .atc-plate-w { fill-opacity: .16; }

.atc-empty .atc-plate {
  width: 96px;
  height: 96px;
  margin: 0 auto;
  color: var(--text-muted);
}

@media (max-width: 575.98px) {
  .atc-stat-card .atc-stat-icon.has-plate { width: 56px; height: 56px; }
}
