/* ============================================================
ROOT VARIABLES & RESET
============================================================ */
:root {
    --primary: #1f5eff;
    --secondary: #101c3f;
    --accent: #f5a623;
    --bg: #eef1f6;
    --card: #fff;
    --ink: #1c2430;
    --mut: #68738a;
    --line: #e2e7f0;
    --radius: 10px;
}

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

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
h1 { font-size: 19px; }
h3 { font-size: 15px; }

/* ============================================================
APP LAYOUT (Sidebar + Main)
============================================================ */
.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 236px;
    background: var(--secondary);
    color: #cfd6e6;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
    z-index: 50;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand img {
    height: 38px;
    border-radius: 6px;
    background: #fff;
    padding: 2px;
}

.brand strong {
    display: block;
    color: #fff;
    font-size: 15px;
    line-height: 1.2;
}

.brand small {
    font-size: 11px;
    color: #93a0bd;
}

.sidebar nav {
    padding: 12px 10px;
    overflow-y: auto;
    flex: 1;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #c3cddd;
    margin: 2px 0;
    font-size: 13.5px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.sidebar nav a .ni {
    width: 18px;
    text-align: center;
    opacity: .85;
}

.sidebar nav a:hover {
    background: rgba(255,255,255,.07);
    color: #fff;
}

.sidebar nav a.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.side-foot {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.side-foot a {
    color: #93a0bd;
    font-size: 13px;
    display: block;
    padding: 10px 0;
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* Main content area */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    padding: 12px 22px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 60;
    min-height: 60px;
}

.hamburger {
    display: none;
    background: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 20px;
    padding: 8px 12px;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.topbar h1 {
    flex: 1;
    font-size: 18px;
}

.userchip {
    display: flex;
    gap: 9px;
    align-items: center;
}

.userchip .dot {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
}

.userchip strong {
    display: block;
    font-size: 13px;
    line-height: 1.2;
}

.userchip small {
    color: var(--mut);
    font-size: 11px;
}

.content {
    padding: 22px;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}

/* ============================================================
CARDS, KPIs & GRIDS
============================================================ */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 18px;
}

.card-h {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.kpi {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.kpi small {
    color: var(--mut);
    text-transform: uppercase;
    font-size: 10.5px;
    letter-spacing: .4px;
}

.kpi strong {
    display: block;
    font-size: 20px;
    margin: 4px 0 2px;
}

.kpi em {
    font-style: normal;
    color: var(--mut);
    font-size: 11.5px;
}

.kpi-accent {
    border-left-color: var(--accent);
}

/* Chart containers - FIXED for proper rendering */
.chart-box {
    height: 300px;
    position: relative;
    width: 100%;
}

.chart-box canvas {
    width: 100% !important;
    height: 100% !important;
}

.quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ============================================================
TABLES
============================================================ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--mut);
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid var(--line);
}

td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    font-size: 14px;
}

tr:hover td {
    background: #f7f9fd;
}

td.low {
    color: #d64545;
    font-weight: 700;
}

td.r, .r {
    text-align: right;
}

.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.row-actions form {
    display: inline;
}

.muted {
    color: var(--mut);
}

/* ============================================================
FORMS
============================================================ */
label {
    display: block;
    font-size: 12.5px;
    color: var(--mut);
    margin-bottom: 10px;
    font-weight: 600;
}

input, select, textarea {
    width: 100%;
    padding: 12px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    background: #fff;
    color: var(--ink);
    font-size: 16px;
    min-height: 44px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent);
    border-color: var(--primary);
}

input[type=color] {
    padding: 3px;
    height: 44px;
}

input[type=checkbox], input[type=radio] {
    width: 20px;
    height: 20px;
    margin-right: 7px;
}

label.check {
    display: flex;
    align-items: center;
    font-weight: 500;
    color: var(--ink);
    min-height: 44px;
    padding: 8px 0;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

legend {
    font-size: 12px;
    color: var(--mut);
    padding: 0 6px;
    font-weight: 700;
}

fieldset.assign {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
}

.form .grid-2 label, .form .grid-3 label {
    margin-bottom: 10px;
}

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 12px;
}

.form-actions .spacer {
    flex: 1;
}

.filters {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.filters label {
    margin: 0;
}

.totals-mini {
    display: flex;
    gap: 18px;
    font-size: 13px;
    color: var(--mut);
}

.totals-mini b {
    color: var(--ink);
}

.totals-mini .t-grand {
    color: var(--primary);
    font-weight: 700;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
}

.logo-prev {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.logo-prev img {
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px;
    background: #fff;
}

/* ============================================================
BUTTONS & BADGES
============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    padding: 12px 14px;
    border-radius: 8px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: .15s;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover {
    filter: brightness(1.08);
    color: #fff;
}

.btn-success {
    background: #1f9d63;
    border-color: #1f9d63;
    color: #fff;
}

.btn-danger {
    background: #d64545;
    border-color: #d64545;
    color: #fff;
}

.btn-danger:hover {
    filter: brightness(1.08);
    color: #fff;
}

.btn-sm {
    padding: 8px 10px;
    font-size: 13px;
    min-height: 36px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.icon-btn {
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--mut);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    color: #d64545;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
}

.b-green {
    background: #e2f6ec;
    color: #177a4b;
}

.b-orange {
    background: #fdeeda;
    color: #b06a12;
}

.b-red {
    background: #fbe3e3;
    color: #b23232;
}

.b-gray {
    background: #e9ecf2;
    color: #5b6577;
}

.b-blue {
    background: #e2ecff;
    color: #274fae;
}

.b-teal {
    background: #dcf4f4;
    color: #0e7575;
}

.b-dark {
    background: #39404e;
    color: #fff;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 14px;
    border: 1px solid transparent;
    transition: opacity .4s;
}

.alert-success {
    background: #e2f6ec;
    color: #177a4b;
    border-color: #bfe8d4;
}

.alert-error {
    background: #fbe3e3;
    color: #b23232;
    border-color: #f2c4c4;
}

/* ============================================================
DOCUMENT SHEET
============================================================ */
.doc-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.doc-actions form {
    display: inline;
}

.doc-sheet {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 34px 38px;
    max-width: 860px;
    margin: 0 auto;
}

.ds-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 3px solid var(--primary);
    padding-bottom: 16px;
    flex-wrap: wrap;
}

.ds-brand {
    display: flex;
    gap: 12px;
    align-items: center;
}

.ds-brand img {
    height: 56px;
}

.ds-brand h2 {
    color: var(--primary);
    font-size: 19px;
}

.ds-brand p {
    color: var(--mut);
    font-size: 12px;
}

.ds-type {
    text-align: right;
}

.ds-type h1 {
    color: var(--primary);
    font-size: 24px;
    letter-spacing: 1px;
}

.ds-num {
    font-weight: 700;
    margin: 2px 0 6px;
}

.ds-meta {
    display: flex;
    gap: 26px;
    margin: 18px 0;
    flex-wrap: wrap;
}

.ds-meta h4 {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--mut);
    margin-bottom: 5px;
    font-weight: 700;
}

.ds-meta > div {
    font-size: 13px;
    line-height: 1.55;
}

.ds-from, .ds-to, .ds-details {
    flex: 1;
    min-width: 200px;
    font-size: 13px;
    line-height: 1.55;
}

.ds-details {
    text-align: right;
}

.ds-items {
    margin: 8px 0 4px;
}

.ds-items th {
    background: var(--primary);
    color: #fff;
    padding: 8px 10px;
}

.ds-items td {
    padding: 8px 10px;
}

.ds-totals {
    width: 44%;
    margin-left: auto;
    margin-top: 8px;
    font-size: 13.5px;
}

.ds-totals > div {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
}

.ds-totals .t-grand {
    border-top: 2px solid var(--primary);
    font-weight: 700;
    color: var(--primary);
    font-size: 15px;
    margin-top: 4px;
}

.ds-totals .t-bal {
    font-weight: 700;
}

.ds-notes {
    margin-top: 14px;
    font-size: 12.5px;
    color: var(--mut);
}

.ds-pay {
    margin-top: 16px;
    padding: 12px 14px;
    border-left: 4px solid var(--accent);
    background: #f8f9fc;
    font-size: 12.5px;
    line-height: 1.6;
}

.ds-pay h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 4px;
}

.ds-foot {
    margin-top: 26px;
    text-align: center;
    color: var(--mut);
    font-size: 11px;
}

/* Invoice source banner */
.ds-invoice-banner {
    background: #f0faf4;
    border-left: 4px solid #1f9d63;
    padding: 10px 14px;
    margin-bottom: 14px;
    border-radius: 0 6px 6px 0;
    font-size: 12px;
}

.stmt .sub td {
    font-weight: 700;
    border-top: 1px solid var(--line);
}

.stmt .grand td {
    font-weight: 800;
    font-size: 15px;
    border-top: 2px solid var(--primary);
    color: var(--primary);
}

.items input, .items select {
    padding: 7px 9px;
}

/* ============================================================
THEME CARD (Settings Page)
============================================================ */
.theme-card {
    transition: all .2s ease;
}

.theme-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
}

/* ============================================================
PAYMENT SETTINGS PAGE
============================================================ */
.payment-gateway-card {
    background: var(--card);
    border: 2px solid var(--line);
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.payment-gateway-card.active {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(31, 94, 255, 0.1);
}

.payment-gateway-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    background: linear-gradient(to right, rgba(31, 94, 255, 0.03), transparent);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    gap: 12px;
}

.payment-gateway-header h3 {
    margin: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.payment-gateway-header h3 small {
    display: block;
    font-size: 11px;
    color: var(--mut);
    font-weight: normal;
    margin-top: 2px;
}

.gateway-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
}

.gateway-icon.mpesa {
    background: linear-gradient(135deg, #4caf50, #2e7d32);
}

.gateway-icon.pesapal {
    background: linear-gradient(135deg, #0b85c0, #075a85);
}

.gateway-icon.stripe {
    background: linear-gradient(135deg, #635bff, #4238b0);
}

.gateway-icon.subscription {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
}

.gateway-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.enabled {
    background: #e2f6ec;
    color: #177a4b;
}

.status-badge.disabled {
    background: #e9ecf2;
    color: #5b6577;
}

.payment-gateway-body {
    padding: 20px;
}

.gateway-config {
    display: none;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--line);
}

.gateway-config.visible {
    display: block;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #cbd5e1;
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

.toggle-switch input:disabled + .toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Gateway Info Box */
.gateway-info-box {
    background: #f7f9fd;
    border-left: 4px solid var(--primary);
    padding: 12px 14px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 16px;
    font-size: 12.5px;
    line-height: 1.6;
}

.gateway-info-box a {
    color: var(--primary);
    font-weight: 600;
}

.url-display {
    background: #f7f9fd;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--ink);
    word-break: break-all;
    margin-top: 4px;
}

/* Summary Grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.summary-item {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
}

.summary-item .count {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin: 4px 0;
}

.summary-item .label {
    font-size: 11px;
    color: var(--mut);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Section Divider */
.section-divider {
    margin: 30px 0 20px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Method Option (Radio Cards) */
.method-option {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    border: 2px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--card);
}

.method-option:hover {
    border-color: var(--primary);
    background: #f7f9fd;
}

.method-option.selected {
    border-color: var(--primary);
    background: linear-gradient(to right, rgba(31, 94, 255, 0.05), transparent);
}

.method-option input[type="radio"] {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.method-option-content {
    flex: 1;
}

.method-option-content h4 {
    margin: 0 0 4px 0;
    font-size: 14px;
    color: var(--ink);
}

.method-option-content p {
    margin: 0;
    font-size: 12px;
    color: var(--mut);
    line-height: 1.5;
}

.method-fields {
    display: none;
    margin-top: 16px;
    padding: 16px;
    background: #f7f9fd;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
}

.method-fields.visible {
    display: block;
}

/* Info / Warning Boxes */
.info-box {
    background: #f0faf4;
    border-left: 4px solid #1f9d63;
    padding: 12px 14px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 16px;
    font-size: 12.5px;
    line-height: 1.6;
}

.warning-box {
    background: #fdeeda;
    border-left: 4px solid #f5a623;
    padding: 12px 14px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 16px;
    font-size: 12.5px;
    line-height: 1.6;
}

/* ============================================================
AUTHENTICATION PAGE (Login + Registration)
============================================================ */
.auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    position: relative;
    overflow-x: hidden;
}

.auth-container {
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
    z-index: 3;
}

/* Background & overlay layers */
.login-bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.login-bg-layer.no-image {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
}

.login-overlay-layer {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.auth-page::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    pointer-events: none;
}

.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary, #1f5eff), var(--secondary, #101c3f));
    color: #fff;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 800;
    margin: 0 auto 16px;
    box-shadow: 0 8px 20px rgba(31, 94, 255, 0.3);
}

/* Custom logo image */
.auth-logo-image {
    max-width: 180px;
    max-height: 80px;
    margin-bottom: 16px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.auth-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--ink, #1c2430);
    margin: 0 0 4px 0;
}

.auth-subtitle {
    font-size: 13px;
    color: var(--mut, #68738a);
    margin: 0;
}

/* Tabs */
.auth-tabs {
    display: flex;
    gap: 4px;
    background: #f7f9fd;
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
}

.auth-tab {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--mut, #68738a);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.auth-tab:hover {
    color: var(--ink, #1c2430);
}

.auth-tab.active {
    background: #fff;
    color: var(--primary, #1f5eff);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Forms */
.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form .field-group {
    margin-bottom: 16px;
}

.auth-form .field-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink, #1c2430);
    margin-bottom: 8px;
}

.auth-form .field-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--line, #e2e7f0);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s;
    background: #fff;
    box-sizing: border-box;
    min-height: 48px;
}

.auth-form .field-group input:focus {
    outline: none;
    border-color: var(--primary, #1f5eff);
    box-shadow: 0 0 0 3px rgba(31, 94, 255, 0.1);
}

.auth-form .field-group input::placeholder {
    color: #a0a8b8;
}

.auth-form .btn-block {
    width: 100%;
    margin-top: 8px;
    padding: 14px;
    font-size: 16px;
    min-height: 48px;
}

.auth-help {
    text-align: center;
    font-size: 14px;
    color: var(--mut, #68738a);
    margin: 16px 0 0 0;
}

.auth-help a {
    color: var(--primary, #1f5eff);
    font-weight: 600;
    text-decoration: none;
    padding: 8px;
    display: inline-block;
}

.auth-help a:hover {
    text-decoration: underline;
}

.auth-card .alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
}

.auth-card .alert-error {
    background: #fbe3e3;
    border: 1px solid #f5c6c6;
    color: #b23232;
}

.auth-card .alert-success {
    background: #e2f6ec;
    border: 1px solid #b8e6cc;
    color: #177a4b;
}

.auth-footer {
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 12px;
    position: relative;
    z-index: 3;
}

.auth-footer a {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* Form extras (remember me + forgot password) */
.form-extras {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 13px;
}

.form-extras .check {
    margin: 0;
}

.form-extras a {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
}

.form-extras a:hover {
    text-decoration: underline;
}

/* Forgot password info text */
.forgot-password-info {
    font-size: 13px;
    color: var(--mut);
    margin: 0 0 16px 0;
    text-align: center;
}

/* ============================================================
WHITELABEL SETTINGS PAGE
============================================================ */
.whitelabel-container {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 20px;
    align-items: start;
}

.preview-frame {
    position: sticky;
    top: 20px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.preview-header {
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: #fff;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-mockup {
    position: relative;
    aspect-ratio: 16/10;
    overflow: hidden;
    background: #1a1a2e;
}

.preview-mockup .bg-layer {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 0;
}

.preview-mockup .overlay-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

.preview-mockup .content-layer {
    position: relative;
    z-index: 2;
    display: flex;
    padding: 20px;
    gap: 20px;
    height: 100%;
    align-items: center;
}

.preview-mockup .brand-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
}

.preview-mockup .brand-side .logo {
    width: 48px;
    height: 48px;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
}

.preview-mockup .brand-side h2 {
    font-size: 18px;
    margin: 0 0 4px 0;
    font-weight: 700;
}

.preview-mockup .brand-side p {
    font-size: 11px;
    opacity: 0.85;
    margin: 0;
}

.preview-mockup .form-side {
    width: 180px;
    background: rgba(255,255,255,0.98);
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.preview-mockup .form-side .field {
    height: 20px;
    background: #f0f2f5;
    border-radius: 4px;
    margin-bottom: 8px;
}

.preview-mockup .form-side .btn {
    height: 24px;
    border-radius: 4px;
    margin-top: 8px;
}

.preview-mockup .footer-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 16px;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-size: 9px;
    text-align: center;
}

.color-swatch-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.color-swatch {
    flex: 1;
    height: 40px;
    border-radius: 8px;
    border: 2px solid var(--line);
    position: relative;
    overflow: hidden;
}

.color-swatch::after {
    content: attr(data-label);
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 9px;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    font-weight: 600;
}

.layout-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 2px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.layout-option:hover {
    border-color: var(--primary);
    background: #f7f9fd;
}

.layout-option.selected {
    border-color: var(--primary);
    background: #f0f7ff;
}

.layout-option input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.layout-thumb {
    width: 60px;
    height: 40px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--line);
}

.layout-thumb.split {
    display: flex;
}

.layout-thumb.split .left {
    flex: 1;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
}

.layout-thumb.split .right {
    width: 40%;
    background: #fff;
}

.layout-thumb.centered .card {
    width: 60%;
    height: 70%;
    margin: 15% auto;
    background: #fff;
    border-radius: 4px;
}

.layout-thumb.centered {
    background: linear-gradient(135deg, var(--secondary), var(--primary));
}

.image-preview-box {
    margin-top: 10px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--line);
    position: relative;
    aspect-ratio: 16/9;
    background: #f7f9fd;
}

.image-preview-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-box .remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(214, 69, 69, 0.9);
    color: #fff;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
}

.overlay-preset-btn {
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: transform 0.2s;
}

.overlay-preset-btn:hover {
    transform: translateY(-1px);
}

/* ============================================================
NOTIFICATION BELL & BUSINESS SWITCHER
============================================================ */
.notification-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #f7f9fd;
    border: 1px solid var(--line);
    text-decoration: none;
    font-size: 18px;
    transition: 0.2s;
}

.notification-bell:hover {
    background: #e2ecff;
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #d64545;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
}

#businessSwitcher {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
}

/* ============================================================
SEND EMAIL MODAL
============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--ink);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--mut);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--ink);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    background: var(--bg);
    border-radius: 0 0 12px 12px;
}

.btn-loader {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-loader::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================================
PRELOADER OVERLAY
============================================================ */
.preloader-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 99999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    backdrop-filter: blur(6px);
}

.preloader-overlay.active {
    display: flex;
}

.preloader-spinner {
    width: 70px;
    height: 70px;
    border: 5px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--primary, #1f5eff);
    border-radius: 50%;
    animation: preloaderSpin 0.9s linear infinite;
}

.preloader-content {
    text-align: center;
    margin-top: 24px;
}

.preloader-title {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.preloader-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    margin-bottom: 16px;
}

.preloader-progress-container {
    width: 280px;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    overflow: hidden;
    margin: 0 auto;
}

.preloader-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary, #1f5eff), var(--accent, #f5a623));
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

.preloader-percentage {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    margin-top: 12px;
}

@keyframes preloaderSpin {
    to { transform: rotate(360deg); }
}

/* File input loading state */
.file-input-wrapper {
    position: relative;
}

.file-input-wrapper.loading {
    opacity: 0.6;
    pointer-events: none;
}

.file-input-wrapper.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(31, 94, 255, 0.2);
    border-top-color: var(--primary, #1f5eff);
    border-radius: 50%;
    animation: preloaderSpin 0.8s linear infinite;
}

/* Image preview loading state */
.image-preview-box {
    position: relative;
    overflow: hidden;
}

.image-preview-box.loading {
    opacity: 0.7;
}

.image-preview-box.loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview-box.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: preloaderSpin 0.8s linear infinite;
    z-index: 11;
}

/* Success/Error states for preloader */
.preloader-overlay.success .preloader-spinner {
    border-top-color: #1f9d63;
    animation: none;
}

.preloader-overlay.success .preloader-spinner::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 32px;
    color: #1f9d63;
}

.preloader-overlay.error .preloader-spinner {
    border-top-color: #d64545;
    animation: none;
}

.preloader-overlay.error .preloader-spinner::after {
    content: '✕';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 32px;
    color: #d64545;
}

/* ============================================================
DISABLED ACCOUNT POPUP MODAL
============================================================ */
.disabled-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(16, 28, 63, 0.75);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: fadeIn 0.3s ease-out;
}

.disabled-popup-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    max-width: 460px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: popIn 0.3s ease-out;
}

.disabled-popup-icon {
    width: 72px;
    height: 72px;
    background: #fbe3e3;
    color: #d64545;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    margin: 0 auto 20px;
    box-shadow: 0 8px 20px rgba(214, 69, 69, 0.2);
}

.disabled-popup-title {
    font-size: 22px;
    color: #1c2430;
    margin: 0 0 12px 0;
    font-weight: 700;
}

.disabled-popup-message {
    font-size: 15px;
    color: #68738a;
    line-height: 1.6;
    margin: 0 0 24px 0;
}

.disabled-popup-btn {
    display: inline-block;
    padding: 12px 28px;
    margin-bottom: 16px;
}

.disabled-popup-close {
    background: none;
    border: none;
    color: #68738a;
    cursor: pointer;
    font-size: 13px;
    text-decoration: underline;
    font-family: inherit;
    padding: 8px;
}

.disabled-popup-close:hover {
    color: #1c2430;
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* ============================================================
RESPONSIVE
============================================================ */
@media (max-width: 1100px) {
    .whitelabel-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1080px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
    .grid-3 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 100;
        transform: translateX(-105%);
        transition: transform .22s;
        box-shadow: 0 0 40px rgba(0,0,0,.35);
    }
    
    body.nav-open .sidebar {
        transform: none;
    }
    
    .hamburger {
        display: flex;
    }
    
    .topbar {
        padding: 10px 14px;
    }
    
    .content {
        padding: 14px;
    }
    
    .doc-sheet {
        padding: 20px;
    }
    
    .ds-totals {
        width: 100%;
    }
    
    .ds-meta {
        flex-direction: column;
        gap: 14px;
    }
    
    .ds-details {
        text-align: left;
    }
}

@media (max-width: 600px) {
    .grid-3 {
        grid-template-columns: 1fr;
    }
    
    .userchip div {
        display: none;
    }
    
    .kpi strong {
        font-size: 17px;
    }
    
    .ds-head {
        flex-direction: column;
    }
    
    .ds-type {
        text-align: left;
    }
    
    .topbar h1 {
        font-size: 16px;
    }
    
    table {
        font-size: 13px;
    }
    
    th, td {
        padding: 10px 8px;
    }
    
    .btn {
        font-size: 14px;
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 24px 20px;
    }
    
    .auth-title {
        font-size: 20px;
    }
    
    .auth-logo {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    
    .content {
        padding: 10px;
    }
    
    .card {
        padding: 14px;
    }
    
    .kpi {
        padding: 12px;
    }
    
    .kpi strong {
        font-size: 16px;
    }
    
    .btn {
        padding: 11px;
        font-size: 13px;
    }
}

/* ============================================================
PRINT
============================================================ */
@media print {
    .sidebar, .topbar, .no-print, .doc-actions, .alert {
        display: none !important;
    }
    
    body {
        background: #fff;
    }
    
    .content {
        padding: 0;
        max-width: none;
    }
    
    .card {
        border: none;
        padding: 0;
    }
    
    .doc-sheet {
        border: none;
        max-width: none;
        padding: 0;
    }
}
/* ISP interactive sidebar groups */
.sidebar-nav{padding:10px 10px 16px;overflow-y:auto;flex:1}
.menu-group{margin:2px 0 8px}
.menu-group summary{list-style:none;cursor:pointer;padding:9px 10px;color:#8f9bb5;text-transform:uppercase;font-size:10px;letter-spacing:.7px;display:flex;justify-content:space-between;align-items:center;border-radius:7px;user-select:none}
.menu-group summary::-webkit-details-marker{display:none}
.menu-group summary:hover{background:rgba(255,255,255,.05);color:#fff}
.menu-group summary span{font-size:13px;transition:transform .15s}
.menu-group[open] summary span{transform:rotate(180deg)}
.menu-group-items{display:flex;flex-direction:column}
.sidebar nav.menu-group-items a,.menu-group-items a{display:flex;align-items:center;gap:10px;padding:9px 12px;border-radius:8px;color:#c3cddd;margin:2px 0;font-size:13.5px;min-height:42px}
.menu-group-items a:hover{background:rgba(255,255,255,.07);color:#fff}
.menu-group-items a.active{background:var(--primary);color:#fff;font-weight:600}
.menu-group-items a .ni{width:18px;text-align:center;opacity:.9}
@media(max-width:900px){.sidebar{position:fixed;left:-260px;top:0;transition:left .2s ease;box-shadow:10px 0 30px rgba(0,0,0,.25)}body.nav-open .sidebar{left:0}.hamburger{display:inline-flex;align-items:center;justify-content:center}}

/* ============================================================
MOBILE FIXES (v2): nothing may be wider than the screen
============================================================ */
html, body { max-width: 100%; overflow-x: hidden; }
.layout, .main, .content, .card, .card-h, .grid-2, .grid-3 { min-width: 0; max-width: 100%; }
.card { overflow-wrap: anywhere; word-break: break-word; }
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
pre, code, .mono { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
input, select, textarea, button { max-width: 100%; }
.table-wrap, .js-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table-wrap > table, .js-table-wrap > table { min-width: 560px; }
td form { display: inline-block; margin: 2px 0; }
@media (max-width: 700px) {
    .content { padding: 10px; }
    .card { padding: 12px; }
    .topbar { flex-wrap: wrap; gap: 8px; }
    .topbar h1 { font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .grid-2, .grid-3, .form .grid-2, .form .grid-3 { grid-template-columns: 1fr !important; }
    .card-h { flex-direction: column; align-items: stretch; }
    .card-h .btn, .card-h form, .card-h select { width: 100%; }
    td[style*="nowrap"], th[style*="nowrap"] { white-space: normal !important; }
    td .btn, td button.btn { width: auto; min-height: 36px; padding: 8px 10px; font-size: 13px; }
    .btn { max-width: 100%; }
    .modal, .modal-box, .dialog { width: auto !important; max-width: calc(100vw - 24px) !important; }
    [style*="min-width"][style*="px"] { min-width: 0 !important; }
    [style*="width:"][style*="px"]:not(td):not(th):not(img):not(svg) { max-width: 100% !important; }
}

/* =====================================================================
   UI refresh (v15): calmer surfaces, clearer hierarchy, better tables.
   Colours still come from the business theme (--primary/--secondary/--accent).
   ===================================================================== */
:root{--bg:#f4f6fb;--line:#e6eaf2;--ink:#1a2233;--mut:#64708a;--radius:14px;
  --shadow:0 1px 2px rgba(16,28,63,.04),0 4px 14px rgba(16,28,63,.06);--ring:0 0 0 3px color-mix(in srgb,var(--primary) 22%,transparent)}
body{font-family:"Inter","Segoe UI",system-ui,-apple-system,Roboto,Arial,sans-serif;font-size:14px;line-height:1.5;letter-spacing:-.005em;-webkit-font-smoothing:antialiased}
h1,h2,h3{letter-spacing:-.02em}
/* sidebar */
.sidebar{width:248px;background:linear-gradient(180deg,var(--secondary),color-mix(in srgb,var(--secondary) 82%,#000));box-shadow:2px 0 18px rgba(16,28,63,.10)}
.brand{padding:20px 18px}
.menu-group summary{font-weight:600;color:#7f8caa}
.menu-group-items a{transition:background .15s,color .15s,transform .15s}
.menu-group-items a:hover{background:rgba(255,255,255,.08);color:#fff;transform:translateX(2px)}
.menu-group-items a.active{background:var(--primary);color:#fff;box-shadow:0 4px 12px color-mix(in srgb,var(--primary) 45%,transparent)}
.sidebar .ni{width:22px;text-align:center;opacity:.95}
.side-foot{border-top:1px solid rgba(255,255,255,.08)}
.logout-link{border-radius:8px}
/* top bar and content */
.topbar{background:rgba(255,255,255,.86);backdrop-filter:saturate(1.4) blur(8px);-webkit-backdrop-filter:saturate(1.4) blur(8px);border-bottom:1px solid var(--line);position:sticky;top:0;z-index:40}
.topbar h1{font-size:19px;font-weight:700}
.content{padding:24px 28px;max-width:1280px}
/* cards */
.card{border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:20px;margin-bottom:18px}
.card-h{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;margin-bottom:14px}
.card-h h3{font-size:15px;font-weight:700}
.muted,.card p.muted{color:var(--mut)}
/* summary tiles */
.stat-row{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:14px;margin-bottom:18px}
.stat{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:16px 18px;display:flex;flex-direction:column;gap:2px;position:relative;overflow:hidden}
.stat::before{content:"";position:absolute;left:0;top:0;bottom:0;width:4px;background:var(--primary)}
.stat span{font-size:12px;color:var(--mut);font-weight:500}
.stat b{font-size:22px;font-weight:700;letter-spacing:-.02em;word-break:break-word}
.stat em{font-style:normal;font-size:12px;color:var(--mut)}
/* tables */
.table-wrap{border:1px solid var(--line);border-radius:12px;overflow-x:auto;background:var(--card)}
table{border-collapse:separate;border-spacing:0;width:100%}
thead th{background:#f7f9fc;color:var(--mut);font-size:11.5px;text-transform:uppercase;letter-spacing:.05em;font-weight:600;text-align:left;padding:11px 14px;border-bottom:1px solid var(--line);white-space:nowrap}
tbody td{padding:12px 14px;border-bottom:1px solid #eef1f6;vertical-align:top}
tbody tr:last-child td{border-bottom:0}
tbody tr:hover td{background:#fafbfe}
tfoot th{padding:12px 14px;background:#f7f9fc;border-top:1px solid var(--line);text-align:left}
.num{text-align:right!important;font-variant-numeric:tabular-nums;white-space:nowrap}
td small,th small{color:var(--mut)}
/* buttons */
.btn{border-radius:9px;font-weight:600;transition:box-shadow .15s,transform .05s,background .15s;cursor:pointer}
.btn:active{transform:translateY(1px)}
.btn:focus-visible{outline:none;box-shadow:var(--ring)}
.btn-primary{background:var(--primary);border-color:var(--primary);color:#fff;box-shadow:0 2px 8px color-mix(in srgb,var(--primary) 35%,transparent)}
.btn-sm{padding:6px 11px;font-size:12.5px;border-radius:8px}
/* forms */
input,select,textarea{border:1px solid #d5dbe8;border-radius:9px;background:#fff;padding:9px 11px;font:inherit;max-width:100%;transition:border-color .15s,box-shadow .15s}
input:focus,select:focus,textarea:focus{outline:none;border-color:var(--primary);box-shadow:var(--ring)}
label{font-weight:500;color:#394560}
.form label{display:block;margin-bottom:12px}
.form label input,.form label select,.form label textarea{display:block;width:100%;margin-top:5px}
.inline-form{display:inline-flex;gap:6px;align-items:center;flex-wrap:wrap;margin:0}
.grid-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px}
/* badges */
.badge{border-radius:999px;padding:3px 10px;font-size:11.5px;font-weight:600;letter-spacing:.01em;white-space:nowrap}
/* alerts */
.alert{border-radius:12px;border:1px solid var(--line);box-shadow:var(--shadow)}
/* statement */
.stmt-head{display:flex;justify-content:space-between;align-items:center;gap:18px;flex-wrap:wrap}
.stmt-head h2{font-size:20px;margin-bottom:2px}
.stmt-balance{display:flex;flex-direction:column;align-items:flex-end;gap:4px;padding:12px 18px;border-radius:12px;background:#ecfdf3;border:1px solid #bbf0d3}
.stmt-balance span{font-size:12px;color:var(--mut);font-weight:600;text-transform:uppercase;letter-spacing:.05em}
.stmt-balance b{font-size:26px;letter-spacing:-.02em}
.stmt-balance.owing{background:#fff4f2;border-color:#fbcfc8}.stmt-balance.owing b{color:#b42318}
.stmt-balance.clear b{color:#067647}
table.stmt tbody tr td:nth-child(3){max-width:340px}
/* auth / login page keeps its own layout; do not widen it */
@media (max-width:900px){.content{padding:16px 14px}.grid-2{grid-template-columns:1fr}.stat b{font-size:19px}.card{padding:15px;border-radius:12px}.stmt-balance{align-items:flex-start;width:100%}}
@media (max-width:640px){.stat-row{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.topbar h1{font-size:16px}thead th,tbody td{padding:10px 10px}}
@media print{.stat::before{display:none}.card,.stat,.table-wrap{box-shadow:none}.topbar{position:static}}
@media (max-width:640px){.table-wrap table{min-width:540px}tbody td:first-child{white-space:nowrap}.card-h{justify-content:flex-start}.card-h h3{text-align:left}}

/* ---- Busy overlay (preloader) shown while a page talks to a MikroTik router ---- */
#busy-overlay{position:fixed;inset:0;z-index:9999;display:none;align-items:center;justify-content:center;background:rgba(15,23,42,.55);backdrop-filter:blur(2px);padding:16px}
#busy-overlay.on{display:flex}
#busy-overlay .busy-box{background:var(--card,#fff);color:var(--text,#14213d);border-radius:16px;padding:26px 28px;max-width:380px;width:100%;text-align:center;box-shadow:0 20px 50px rgba(0,0,0,.3)}
#busy-overlay .busy-spin{width:46px;height:46px;margin:0 auto 14px;border:4px solid rgba(120,130,150,.28);border-top-color:var(--primary,#1f5eff);border-radius:50%;animation:busyspin .8s linear infinite}
#busy-overlay b{display:block;font-size:1.02rem;margin-bottom:4px}
#busy-overlay p{margin:4px 0;color:var(--muted,#667085);font-size:.9rem}
#busy-overlay .busy-late{display:none;margin-top:12px}
#busy-overlay.late .busy-late{display:block}
@keyframes busyspin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion:reduce){#busy-overlay .busy-spin{animation-duration:2.4s}}

/* ===== Mobile fit + fixed sign-out (v-mobile) ===== */
html,body{max-width:100%;overflow-x:clip}
.main{min-width:0;flex:1 1 0}
img,video,iframe,svg,canvas{max-width:100%;height:auto}
pre,code,.mono{white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;max-width:100%}
pre{overflow-x:auto}
input,select,textarea,button{max-width:100%;min-width:0}
.card,.card-h,.stat,.alert,td,th,label{overflow-wrap:anywhere}
.card-h{flex-wrap:wrap;gap:8px}
.form-actions,.inline-form,.doc-actions,.actions{flex-wrap:wrap}
.table-wrap{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
.table-wrap td,.table-wrap th{overflow-wrap:normal;word-break:normal}
/* the sidebar fills the visible screen (dvh excludes the mobile address bar) and the sign-out row never scrolls away */
.sidebar{height:100vh;height:100dvh;max-height:100dvh}
.sidebar nav{min-height:0;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
.side-foot{flex-shrink:0;position:sticky;bottom:0;background:inherit;padding-bottom:calc(12px + env(safe-area-inset-bottom,0px))}
.side-foot .logout-link{background:rgba(255,255,255,.06);color:#e7ecf8;padding:0 12px;justify-content:center;font-weight:600}
.topbar-logout{display:none;margin-left:auto;font-size:13px;font-weight:600;color:var(--primary);padding:8px 12px;border:1px solid var(--line,#dbe3f3);border-radius:8px;white-space:nowrap;background:#fff}
@media (max-width:900px){
  .topbar{display:flex;align-items:center;gap:8px;flex-wrap:nowrap}
  .topbar h1{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .topbar-logout{display:inline-flex}
  .notification-bell{flex-shrink:0}
  .sidebar{width:min(84vw,300px)}
  .content{padding:12px}
  .stat-row{grid-template-columns:repeat(auto-fit,minmax(140px,1fr))}
  .grid-2,.grid-3,.form .grid-2,.form .grid-3{grid-template-columns:1fr !important}
  .btn{white-space:normal}
  .doc-sheet,.statement{max-width:100%;overflow-x:auto}
}
@media (max-width:480px){.stat b{font-size:17px}.card{padding:12px}h1,h2,h3{overflow-wrap:anywhere}}

/* ===== StreamSuite: camera tiles, live wall, playback ===== */
.ss-wall{display:grid;gap:8px;grid-template-columns:repeat(var(--cols,2),minmax(0,1fr))}
.ss-wall.cols-1{--cols:1}.ss-wall.cols-2{--cols:2}.ss-wall.cols-3{--cols:3}.ss-wall.cols-4{--cols:4}
@media (max-width:700px){.ss-wall{--cols:1!important}}
.ss-tile{position:relative;background:#0b0f17;border-radius:10px;overflow:hidden;aspect-ratio:16/9;color:#fff}
.ss-tile video{width:100%;height:100%;object-fit:contain;background:#000;display:block}
.ss-tile:fullscreen{border-radius:0;aspect-ratio:auto}
.ss-tile .ss-label{position:absolute;left:8px;top:8px;display:flex;gap:6px;align-items:center;background:rgba(0,0,0,.55);padding:3px 8px;border-radius:6px;font-size:12px;max-width:calc(100% - 16px)}
.ss-tile .ss-label b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:600}
.ss-tile .ss-label em{font-style:normal;font-size:10px;letter-spacing:.06em;color:#fca5a5}
.ss-tile .ss-dot{width:8px;height:8px;border-radius:50%;background:#9ca3af;flex:none}
.ss-tile[data-state=live] .ss-dot{background:#ef4444;box-shadow:0 0 0 3px rgba(239,68,68,.25)}
.ss-tile[data-state=error] .ss-dot{background:#f59e0b}
.ss-tile .ss-msg{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;text-align:center;padding:20px;font-size:13px;color:#cbd5e1;pointer-events:none}
.ss-tile .ss-bar{position:absolute;right:8px;bottom:8px;display:flex;gap:4px;opacity:0;transition:opacity .2s}
.ss-tile:hover .ss-bar,.ss-tile:focus-within .ss-bar{opacity:1}
@media (hover:none){.ss-tile .ss-bar{opacity:1}}
.ss-tile .ss-bar button{background:rgba(0,0,0,.6);color:#fff;border:0;border-radius:6px;width:32px;height:30px;cursor:pointer;font-size:14px}
.ss-toolbar{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin-bottom:10px}
.ss-toolbar select,.ss-toolbar input{width:auto}
.ss-timeline{position:relative;height:34px;background:#eef2f7;border-radius:8px;overflow:hidden;cursor:pointer;margin:6px 0 2px}
.ss-timeline .seg{position:absolute;top:6px;bottom:6px;background:#2563eb;border-radius:3px;opacity:.85}
.ss-timeline .seg.dev{background:#059669}
.ss-timeline .cursor{position:absolute;top:0;bottom:0;width:2px;background:#ef4444}
.ss-hours{display:flex;justify-content:space-between;font-size:10px;color:var(--mut)}
.ss-cam-thumb{width:120px;aspect-ratio:16/9;object-fit:cover;border-radius:6px;background:#0b0f17}
.ss-code{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;word-break:break-all;background:#f6f8fb;border:1px solid #e5e9f0;border-radius:6px;padding:8px}
