:root {
    /* Palette sampled directly from the Allied logo and alliedbiz.co.za site:
       --red is the logo wordmark red; --blue/--blue-dark are the deep teal-blue
       from the site's footer gradient (kept dark enough for text/button contrast);
       --blue-accent is the vivid sky-blue used across the site's hero/footer
       backgrounds, reserved for decorative accents rather than small text. */
    --blue: #08567d;
    --blue-dark: #063e5a;
    --blue-light: #e6f5fc;
    --blue-accent: #0098e4;
    --red: #d9232e;
    --red-dark: #a31a22;
    --red-light: #fcedee;
    --white: #ffffff;
    --gray-50: #f7f8fa;
    --gray-100: #eef0f3;
    --gray-200: #dde1e6;
    --gray-300: #c3c9d1;
    --gray-400: #9aa2ad;
    --gray-600: #5b6470;
    --gray-800: #262b33;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(20, 30, 60, 0.08), 0 1px 2px rgba(20, 30, 60, 0.06);
    --sidebar-width: 240px;

    /* Sidebar: light blue fill with dark, high-contrast text on top;
       Topbar: light grey, reusing --gray-100 which was already the exact
       shade we want. */
    --sidebar-bg: #a6c9ec;
    --sidebar-text: var(--gray-800);
    --sidebar-text-muted: var(--blue-dark);
    --sidebar-active-bg: var(--white);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.4);
    --sidebar-divider: rgba(6, 62, 90, 0.18);
    --topbar-bg: var(--gray-100);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell (sidebar + main) ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-divider);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
    border-bottom: 1px solid var(--sidebar-divider);
}
.brand-icon-img {
    height: 32px;
    width: auto;
    flex-shrink: 0;
    display: block;
}
.brand-text { min-width: 0; }
.brand-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--sidebar-text);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand-subtitle {
    font-size: 12px;
    color: var(--sidebar-text-muted);
    margin-top: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 14px;
}
.sidebar-nav a:hover { background: var(--sidebar-hover-bg); text-decoration: none; }
.sidebar-nav a.active { background: var(--sidebar-active-bg); color: var(--blue-dark); box-shadow: var(--shadow); }
.nav-label { display: flex; align-items: center; gap: 10px; }
.nav-icon {
    width: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: var(--sidebar-text-muted);
}
.sidebar-nav a.active .nav-icon { color: var(--blue-dark); }
.nav-count {
    background: rgba(255, 255, 255, 0.6);
    color: var(--blue-dark);
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}
.sidebar-nav a.active .nav-count { background: var(--blue-light); color: var(--blue-dark); }

.sidebar-divider {
    height: 1px;
    background: var(--sidebar-divider);
    margin: 10px 12px;
}

.sidebar-footer {
    padding: 16px 20px 20px;
    border-top: 1px solid var(--sidebar-divider);
    font-size: 12px;
}
.sidebar-footer-links { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--sidebar-text-muted); flex-wrap: wrap; }
.sidebar-footer-links a { color: var(--blue-dark); font-weight: 600; }
.sidebar-footer-note { color: var(--sidebar-text-muted); line-height: 1.4; }

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

.topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--gray-200);
    padding: 22px 32px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar-titles h1 { margin: 0; }
.topbar-titles .subtitle { margin-top: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.global-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0 12px;
}
.global-search .search-icon { color: var(--gray-400); font-size: 13px; }
.global-search input {
    border: none;
    background: transparent;
    padding: 9px 0;
    width: 220px;
    font-size: 14px;
}
.global-search input:focus { outline: none; box-shadow: none; }
.global-search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light); }

/* ---------- Layout ---------- */
.page { max-width: 1200px; margin: 0; padding: 28px 32px 60px; }
.footer { text-align: center; color: var(--gray-400); font-size: 12px; padding: 24px; }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Same dark blue as the primary/login button (--blue), for a matching feel. */
    background: var(--blue);
}
.auth-card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 40px;
    width: 360px;
}
.auth-card .brand { display: flex; align-items: center; justify-content: center; margin-bottom: 24px; }
.auth-card .brand img { height: 42px; width: auto; }

/* ---------- Flash messages ---------- */
.flash-stack { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    border: 1px solid transparent;
}
.flash-success { background: #e9f7ef; color: #1e7a3d; border-color: #c3ecd3; }
.flash-danger { background: var(--red-light); color: var(--red-dark); border-color: #f6c6cb; }
.flash-warning { background: #fff6e0; color: #8a6400; border-color: #f7e3a3; }
.flash-info { background: var(--blue-light); color: var(--blue-dark); border-color: #cdd9f2; }

/* ---------- Typography / headers ---------- */
h1 { font-size: 24px; margin: 0 0 4px; color: var(--gray-800); }
h2 { font-size: 18px; margin: 0 0 12px; color: var(--gray-800); }
h3 { font-size: 15px; margin: 0 0 4px; color: var(--gray-800); }
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.subtitle { color: var(--gray-600); font-size: 14px; margin-top: 4px; }

/* ---------- Content action rows (search / filter + primary button) ---------- */
.content-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.content-actions .search-form { margin-bottom: 0; flex: 1; max-width: 480px; }

/* ---------- Cards / stats ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    border-top: 3px solid var(--blue-accent);
}
.stat-card.stat-danger { border-top-color: var(--red); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--gray-800); }
.stat-card .stat-label { font-size: 13px; color: var(--gray-600); margin-top: 2px; }

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    margin-bottom: 20px;
}

/* ---------- Warranty warning banner ---------- */
.warning-banner {
    background: var(--red-light);
    border: 1px solid #f3b9c0;
    border-left: 4px solid var(--red);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
}
.warning-banner h2 { color: var(--red-dark); display: flex; align-items: center; gap: 8px; }
.warning-banner .warn-icon { font-size: 18px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gray-100); }
th { color: var(--gray-600); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--gray-50); }
td.numeric, th.numeric { text-align: right; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-ok { background: #e6f4ea; color: #1e7a3d; }
.badge-warning { background: #fff2cf; color: #92660a; }
.badge-expired { background: var(--red-light); color: var(--red-dark); }
.badge-unknown { background: var(--gray-100); color: var(--gray-600); }
.badge-admin { background: var(--blue-light); color: var(--blue-dark); }
.badge-user { background: var(--gray-100); color: var(--gray-600); }
.badge-viewer { background: var(--blue-light); color: var(--blue); }
.badge-inactive { background: var(--gray-100); color: var(--gray-400); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--blue); border-color: var(--gray-200); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Forms ---------- */
form .form-row { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--white);
    color: var(--gray-800);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-light);
}
textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

.search-form { display: flex; gap: 10px; margin-bottom: 20px; max-width: 480px; flex-wrap: wrap; }
.search-form input { flex: 1; }

.empty-state { color: var(--gray-400); padding: 32px 20px; text-align: center; font-size: 14px; }
.empty-state::before {
    content: "\25A2";
    display: block;
    font-size: 22px;
    color: var(--gray-300);
    margin-bottom: 10px;
}
.empty-state-title { color: var(--gray-800); font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.empty-state-text { color: var(--gray-600); font-size: 13px; max-width: 420px; margin: 0 auto; }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* ---------- Admin landing ---------- */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.admin-tile {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    display: block;
    color: inherit;
}
.admin-tile:hover { text-decoration: none; box-shadow: 0 4px 14px rgba(20, 30, 60, 0.12); }
.admin-tile-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--blue-light);
    color: var(--blue-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 14px;
}
.admin-tile h3 { margin: 0 0 4px; }
.admin-tile p { margin: 0; font-size: 13px; color: var(--gray-600); }
.breadcrumb { font-size: 13px; color: var(--gray-400); margin-bottom: 4px; }
.breadcrumb a { color: var(--gray-600); font-weight: 500; }

/* ---------- Ticket status pill row (dashboard) ---------- */
.pill-row {
    display: flex;
    align-items: center;
    gap: 40px;
    flex-wrap: wrap;
    row-gap: 18px;
}
.pill-stat { display: flex; align-items: center; gap: 12px; }
.pill-stat .pill-count { font-size: 26px; font-weight: 700; color: var(--gray-800); }
.status-pill {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}
.status-pill-open { background: var(--blue-light); color: var(--blue); }
.status-pill-pending { background: #fff2cf; color: #92660a; }
.status-pill-due { background: #ffe8cf; color: #a15a12; }
.status-pill-overdue { background: var(--red-light); color: var(--red-dark); }
.status-pill-neutral { background: var(--gray-100); color: var(--gray-600); }

/* ---------- Dashboard split row (two cards side by side) ---------- */
.dash-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}
.dash-split .card { margin-bottom: 0; }

/* ---------- Search results ---------- */
.result-group { margin-bottom: 20px; }
.result-group h2 { font-size: 15px; }

/* ---------- Customer entity header ---------- */
.entity-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.entity-header-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.entity-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
    flex-shrink: 0;
    font-size: 16px;
}
.entity-back:hover { background: var(--gray-100); text-decoration: none; }

.entity-avatar {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--blue-light);
    color: var(--blue-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    position: relative;
}
.entity-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.entity-avatar-edit {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 86, 125, 0.75);
    color: var(--white);
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
    opacity: 0;
    transition: opacity 0.15s;
    cursor: pointer;
}
.entity-avatar:hover .entity-avatar-edit { opacity: 1; }

.entity-name-block { min-width: 0; }
.entity-name-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.entity-name-row h1 { margin: 0; font-size: 20px; }
.entity-rank-form select {
    width: auto;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
}
.entity-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 6px; font-size: 13px; color: var(--gray-600); }
.entity-meta span { display: inline-flex; align-items: center; gap: 6px; }
.entity-meta .meta-icon { color: var(--gray-400); font-size: 12px; }
.entity-actions { display: flex; align-items: flex-start; gap: 8px; flex-shrink: 0; }

.overflow-menu { position: relative; }
.overflow-menu summary {
    list-style: none;
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-200);
    color: var(--gray-600);
    font-size: 16px;
}
.overflow-menu summary::-webkit-details-marker { display: none; }
.overflow-menu summary:hover { background: var(--gray-100); }
.overflow-menu[open] summary { background: var(--gray-100); }
.overflow-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 190px;
    z-index: 20;
    overflow: hidden;
}
.overflow-menu-list a, .overflow-menu-list button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--gray-800);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

/* Quick-add dropdown (topbar "+ Add" button) — reuses .overflow-menu's
   positioning/list, just with a labeled primary-button-style trigger
   instead of the small round "..." icon. */
.quick-add-menu summary {
    width: auto;
    height: auto;
    border-radius: var(--radius);
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    background: var(--blue);
    color: var(--white);
    border: none;
    gap: 6px;
}
.quick-add-menu summary:hover { background: var(--blue-dark); }
.quick-add-menu[open] summary { background: var(--blue-dark); }
.quick-add-menu .caret { font-size: 10px; }
.overflow-menu-list a:hover, .overflow-menu-list button:hover { background: var(--gray-100); text-decoration: none; }
.overflow-menu-list .danger { color: var(--red); }

/* ---------- Tabs ---------- */
.tab-nav {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--gray-200);
    margin: 18px 0 0;
    overflow-x: auto;
}
.tab-link {
    padding: 12px 4px;
    margin-right: 24px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    cursor: pointer;
}
.tab-link:hover { color: var(--blue); text-decoration: none; }
.tab-link.active { color: var(--gray-800); border-bottom-color: var(--red); }

.tab-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 18px 0 16px; flex-wrap: wrap; }
.tab-panel[hidden] { display: none; }

.inline-form-toggle { display: none; margin-bottom: 20px; }
.inline-form-toggle.open { display: block; }

/* ---------- Passwords ---------- */
.password-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 1px; }

/* ---------- Attachments ---------- */
.attachment-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--gray-100); }
.attachment-row:last-child { border-bottom: none; }
.attachment-file { display: flex; align-items: center; gap: 12px; min-width: 0; }
.attachment-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--gray-100);
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
}
.attachment-name { font-weight: 600; color: var(--gray-800); }
.attachment-meta-text { font-size: 12px; color: var(--gray-600); }

/* ---------- Small avatar chip (customer list) ---------- */
.avatar-chip {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--blue-light);
    color: var(--blue-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    overflow: hidden;
    vertical-align: middle;
    margin-right: 8px;
}
.avatar-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        position: relative;
        width: 100%;
        flex: none;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--gray-200);
    }
    .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
    .topbar { padding: 18px 20px; }
    .page { padding: 20px 20px 48px; }
    .global-search input { width: 140px; }
    .dash-split { grid-template-columns: 1fr; }
}
