/* =====================================================================
   Aussie Home Water Filtration — ERP design system
   Brand: deep navy #0b2a4a · aqua #1793d1 · clean surfaces
   ===================================================================== */
:root {
  --navy: #0b2a4a;
  --navy-2: #123a63;
  --brand-light-blue: #a9d7ee; /* sidebar + auth hero panel */
  --aqua: #1793d1;
  --aqua-2: #0f7cb2;
  --aqua-soft: #e3f2fb;
  --bg: #f3f7fb;
  --surface: #ffffff;
  --border: #e2eaf2;
  --text: #1c2f42;
  --muted: #64798e;
  --green: #12945f;  --green-soft: #e0f5ec;
  --red: #d1403a;    --red-soft: #fdeaea;
  --amber: #b97d10;  --amber-soft: #fdf3df;
  --violet: #6d4fc4; --violet-soft: #efeafa;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 42, 74, .06), 0 4px 16px rgba(11, 42, 74, .06);
  --sidebar-w: 248px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: 'Outfit', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--aqua-2); text-decoration: none; }
a:hover { text-decoration: none; }

/* ---- Shell ---------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }
.content { padding: 24px 28px 60px; flex: 1; }

/* ---- Sidebar --------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--brand-light-blue);
  color: #111;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto; flex-shrink: 0;
  scrollbar-width: thin; scrollbar-color: rgba(0, 0, 0, .25) transparent;
  border-right: 1px solid rgba(0, 0, 0, .08);
}
.brand {
  padding: 18px 65px 14px;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--aqua), #4fc3f7);
  display: grid; place-items: center; color: #fff; font-size: 20px;
  flex-shrink: 0;
}
.brand-logo-img { width:80px; }
.brand-name { font-weight: 700; color: #111; font-size: .95rem; line-height: 1.2; }
.brand-sub { font-size: .68rem; color: rgba(17, 17, 17, .6); letter-spacing: .08em; text-transform: uppercase; }

.nav-section { padding: 12px 12px 4px; }
.nav-label {
  font-size: .66rem; letter-spacing: .12em; text-transform: uppercase;
  color: rgba(17, 17, 17, .55); padding: 8px 10px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px; margin: 1px 0;
  color: #111; font-size: .9rem; transition: background .15s, color .15s;
}
.nav-item i { font-size: 1.1rem; opacity: .7; }
.nav-item:hover { background: rgba(0, 0, 0, .07); color: #000; }
.nav-item.active { background: var(--aqua); color: #fff; font-weight: 600; }
.nav-item.active i { opacity: 1; }
.sidebar-footer { margin-top: auto; padding: 14px 16px; font-size: .72rem; color: rgba(17, 17, 17, .5); }

/* ---- Topbar ---------------------------------------------------------- */
.topbar {
  height: 62px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px; position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-spacer { flex: 1; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 10px; cursor: default;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--aqua-soft); color: var(--aqua-2);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.user-meta { line-height: 1.15; }
.user-name { font-weight: 600; font-size: .85rem; }
.user-role { font-size: .72rem; color: var(--muted); }

/* Impersonation banner */
.acting-banner {
  background: linear-gradient(90deg, #b97d10, #d99a1f);
  color: #fff; padding: 8px 28px; font-size: .85rem;
  display: flex; align-items: center; gap: 12px;
}
.acting-banner form { margin-left: auto; }

/* ---- Mobile shell: sidebar becomes an off-canvas drawer below 900px,
   same for every role — there's only ever this one shared layout. Placed
   after the base .sidebar/.topbar/.content rules above so it actually wins
   the cascade at matching widths, instead of being overridden by them. --- */
@media (max-width: 900px) {
  .sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 1.25rem; flex-shrink: 0;
  }
  .sidebar {
    position: fixed; z-index: 60; top: 0; left: 0;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 8px 30px rgba(11, 42, 74, .25);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-open {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(11, 42, 74, .45);
  }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-title { font-size: .95rem; }
  .content { padding: 16px 14px 40px; }
  .topbar-search { width: auto; flex: 1; max-width: 220px; }
  .user-meta { display: none; }
  .user-chip { padding: 0; }
  .page-head .right { width: 100%; flex-wrap: wrap; }
}
/* Nothing should ever force the page to scroll sideways as a whole — wide
   content (tables, etc) scrolls inside its own .table-wrap instead. */
body { overflow-x: hidden; }
@media (max-width: 520px) {
  .topbar-search { display: none; }
}

/* ---- Cards / stats --------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  /* Flex/grid items default to min-width:auto (sized to their widest child) —
     without this, a wide table inside a card forces the whole card, its grid
     track, and everything up the chain to grow past the viewport instead of
     letting .table-wrap's own overflow-x:auto handle it. */
  min-width: 0;
}
.card-pad { padding: 20px; }
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-title { font-weight: 700; font-size: .95rem; }
.card-header .right { margin-left: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  display: flex; gap: 14px; align-items: center;
}
.stat-ico {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0;
}
.stat-val { font-size: 1.45rem; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--muted); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3-2 { grid-template-columns: 3fr 2fr; }
@media (max-width: 1000px) { .grid-2, .grid-3-2 { grid-template-columns: 1fr; } }

/* ---- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: 9px; border: 1px solid transparent;
  font: 600 .86rem 'Outfit', sans-serif; cursor: pointer; transition: .15s;
  white-space: nowrap;
}
.btn i { font-size: 1rem; }
.btn-primary { background: var(--aqua); color: #fff; }
.btn-primary:hover { background: var(--aqua-2); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: .8rem; border-radius: 7px; }
.btn:disabled { opacity: .7; cursor: not-allowed; }
@keyframes ph-spin { to { transform: rotate(360deg); } }
.ph-spin { display: inline-block; animation: ph-spin .8s linear infinite; }
.btn-block { width: 100%; justify-content: center; }

/* ---- Badges ----------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 700;
}
.badge-new { background: var(--aqua-soft); color: var(--aqua-2); }
.badge-appointment { background: var(--violet-soft); color: var(--violet); }
.badge-quoted { background: var(--amber-soft); color: var(--amber); }
.badge-won { background: var(--green-soft); color: var(--green); }
.badge-lost { background: var(--red-soft); color: var(--red); }
.badge-hold { background: #eceff3; color: #5a6b7d; }
.badge-muted { background: #eef2f6; color: var(--muted); }

/* ---- Tables ----------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
  text-align: left; padding: 11px 16px; color: var(--muted);
  font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f8fbfd; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: .78rem; color: var(--muted); }

/* ---- Sortable column headers ------------------------------------------- */
.th-sort {
  display: inline-flex; align-items: center; gap: 4px; color: inherit;
  text-decoration: none; cursor: pointer;
}
.th-sort:hover { color: var(--aqua-2); }
.th-sort i { font-size: .85rem; }

/* ---- Forms ------------------------------------------------------------ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 6px; }
.field .req { color: var(--red); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 13px; border-radius: 9px;
  border: 1px solid var(--border); background: #fff;
  font: 400 .9rem 'Outfit', sans-serif; color: var(--text);
  transition: border .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--aqua); box-shadow: 0 0 0 3px rgba(23, 147, 209, .15); }
textarea.input { resize: vertical; min-height: 90px; }
.error-text { color: var(--red); font-size: .78rem; margin-top: 4px; }

/* ---- Pipeline tabs ---------------------------------------------------- */
.pipe-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.pipe-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: .82rem; font-weight: 600;
}
.pipe-tab .count { background: #eef2f6; border-radius: 99px; padding: 1px 8px; font-size: .74rem; }
.pipe-tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.pipe-tab.active .count { background: rgba(255,255,255,.18); color: #fff; }

/* ---- Timeline --------------------------------------------------------- */
.timeline { list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before {
  content: ''; position: absolute; left: 7px; top: 6px; bottom: -4px;
  width: 2px; background: var(--border);
}
.timeline li:last-child::before { display: none; }
.timeline .dot {
  position: absolute; left: 0; top: 4px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--aqua-soft); border: 3px solid var(--aqua);
}
.timeline .t-title { font-weight: 600; font-size: .86rem; }
.timeline .t-meta { font-size: .75rem; color: var(--muted); }

/* ---- Auth page -------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
}
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { display: none; } }
.auth-hero {
  background: var(--brand-light-blue);
  color: #111; padding: 60px; display: flex; flex-direction: column; justify-content: center;
}
.auth-hero h1 { color: #111; font-size: 2rem; line-height: 1.25; margin: 18px 0 14px; }
.auth-hero p { color: #111; max-width: 460px; line-height: 1.6; }
.auth-points { margin-top: 34px; display: grid; gap: 14px; }
.auth-point { display: flex; gap: 12px; align-items: center; color: #111; font-size: .92rem; }
.auth-point i { color: #111; font-size: 1.2rem; }
.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 1.4rem; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 26px; }

/* ---- Auth hero logo — bigger, left-aligned, logo + name on one row, independent of the sidebar .brand size --- */
.auth-logo { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.auth-logo img { max-width: 260px; object-fit: contain; flex-shrink: 0; }
.auth-logo-mark {
  width: 60px; height: 60px; border-radius: 16px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--aqua), #4fc3f7);
  display: grid; place-items: center; color: #fff; font-size: 1.8rem;
}
.auth-logo-name { font-weight: 700; color: #111; font-size: 1.1rem; line-height: 1.3; }
.auth-logo-sub { font-size: .72rem; color: #111; letter-spacing: .1em; text-transform: uppercase; margin-top: 3px; }

/* ---- Toasts / alerts -------------------------------------------------- */
.toast-wrap { position: fixed; right: 20px; top: 76px; z-index: 999; display: grid; gap: 10px; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 18px;
  border-radius: 10px; box-shadow: var(--shadow); font-size: .88rem;
  display: flex; gap: 10px; align-items: center; min-width: 260px;
  animation: slideIn .25s ease;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Misc ------------------------------------------------------------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.35rem; }
.page-head .right { margin-left: auto; display: flex; gap: 10px; }
.muted { color: var(--muted); }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mt-4 { margin-top: 24px; }
.mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; } .mb-4 { margin-bottom: 24px; }
.flex { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty {
  text-align: center; color: var(--muted); padding: 42px 20px;
}
.empty i { font-size: 2.2rem; display: block; margin-bottom: 10px; color: #b7c8d8; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 500; }
.pagination { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: .84rem; color: var(--text);
}
.pagination .active span { background: var(--aqua); border-color: var(--aqua); color: #fff; }
.pagination .disabled span { opacity: .45; }

/* Simple modal */
.overlay {
  position: fixed; inset: 0; background: rgba(11, 42, 74, .45);
  display: none; place-items: center; z-index: 100; padding: 20px;
}
.overlay.open { display: grid; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(11,42,74,.3); animation: pop .18s ease;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-title { font-weight: 700; }
.modal-header .close { margin-left: auto; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Suburb autocomplete ---------------------------------------------- */
.suggest-wrap { position: relative; }
.suggest-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; display: none;
}
.suggest-list.open { display: block; }
.suggest-item {
  padding: 9px 14px; cursor: pointer; font-size: .88rem;
  display: flex; justify-content: space-between; gap: 10px;
}
.suggest-item:hover, .suggest-item.hl { background: var(--aqua-soft); }
.suggest-item .pc { color: var(--muted); font-size: .8rem; }

/* ---- Global search dropdown (topbar) ----------------------------------- */
.gsr-list { max-height: 420px; }
.gsr-group-label {
  padding: 8px 14px 4px; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.gsr-item {
  display: block; padding: 8px 14px; cursor: pointer; text-decoration: none; color: inherit;
}
.gsr-item:hover, .gsr-item.hl { background: var(--aqua-soft); }
.gsr-item-title { font-size: .88rem; font-weight: 600; color: var(--text); }
.gsr-item-sub { font-size: .78rem; color: var(--muted); margin-top: 1px; }
.gsr-empty, .gsr-loading { padding: 14px; font-size: .85rem; color: var(--muted); text-align: center; }
.gsr-footer {
  display: block; padding: 10px 14px; text-align: center; font-size: .82rem; font-weight: 600;
  color: var(--aqua); text-decoration: none; border-top: 1px solid var(--border);
}
.gsr-footer:hover { background: var(--aqua-soft); }

/* ---- Mode toggle (new prospect / existing customer / lead) ------------ */
.mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.mode-tab {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1.5px solid var(--border); background: #fff; border-radius: 10px;
  padding: 9px 16px; font-size: .88rem; font-weight: 600; color: var(--muted);
}
.mode-tab:has(input:checked) { border-color: var(--aqua); color: var(--aqua-2); background: var(--aqua-soft); }
.mode-tab input { accent-color: var(--aqua); }

/* ---- Bulk actions bar ---------------------------------------------------- */
/* Sits above the table (not below it) and stays visible while scrolling a long
   list — sticks just under the topbar rather than requiring a scroll to the
   bottom to find "Export selected" / "Delete selected". */
.bulk-bar {
  display: none; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--navy); color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  position: sticky; top: 62px; z-index: 30;
}
.bulk-bar b { font-weight: 700; }
.bulk-bar .btn-ghost { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; }
.bulk-bar .btn-ghost:hover { background: rgba(255,255,255,.18); }

/* ---- Settings shell (sidebar-tab layout) --------------------------------- */
.settings-shell { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .settings-shell { grid-template-columns: 1fr; } }
.settings-nav {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px; position: sticky; top: 78px;
}
.settings-nav-label {
  font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  padding: 14px 12px 6px;
}
.settings-nav-label:first-child { padding-top: 6px; }
.settings-nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text); margin: 2px 0;
}
.settings-nav-item i { font-size: 1.3rem; color: var(--muted); flex-shrink: 0; }
.settings-nav-item:hover { background: var(--bg); }
.settings-nav-item.active { background: var(--aqua-soft); }
.settings-nav-item.active i { color: var(--aqua-2); }
.settings-nav-item-title { font-weight: 600; font-size: .87rem; }
.settings-nav-item-sub { font-size: .74rem; color: var(--muted); }
.settings-content { min-width: 0; }

/* Company-card style used by Business Identity + master-data list cards */
.settings-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.settings-entity-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.settings-entity-card .kv { margin-top: 12px; }
.settings-entity-card .actions { display: flex; gap: 14px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: .85rem; }
.settings-entity-card .actions a, .settings-entity-card .actions button { color: var(--aqua-2); background: none; border: none; cursor: pointer; font: inherit; padding: 0; }
.settings-entity-card .actions .danger { color: var(--red); }

/* Color swatch input */
input[type="color"].swatch { width: 44px; height: 36px; padding: 2px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; }

/* Section tabs (e.g. customer profile) */
.section-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.section-tab { padding: 10px 16px; font-size: .86rem; font-weight: 600; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.section-tab:hover { color: var(--text); }
.section-tab.active { color: var(--navy); border-bottom-color: var(--aqua-2); }
.site-group-label { font-weight: 700; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 8px; }
.site-group-label:first-child { margin-top: 0; }

/* Basic-info preview shown after picking an existing lead/customer in a target-picker form */
.target-info-panel { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
