:root {
    --primary: rgb(59 130 246);
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg-color: #0f172a;       /* Slate 900 */
    --card-bg: #182030;        /* Slate 800 */
    --text-main: #f8fafc;      /* Slate 50 */
    --text-muted: #94a3b8;     /* Slate 400 */
    --border-color: #334155;   /* Slate 700 */
    --hover-bg: #334155;       /* Hover state background */
    --disabled-bg: #273549;
}

/* Universal Box-Sizing Reset */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    max-width: 90%;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Header Styling --- */
.dashboard-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-bottom: 2rem;
    margin-top: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
}

.header-logo img {
    max-height: 50px;
    width: auto;
}

.dashboard-header h1 {
    margin: 0;
    font-size: 2rem;
    text-align: center;
    padding: 0 1.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: flex-end;
}

.user-info h2 {
    font-size: 1rem;
    margin: 0;
    color: var(--text-muted);
    font-weight: normal;
}

.header-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
}

.header-icon {
    width: 1rem;
    height: 1rem;
}

/* --- Search result highlighting --- */
mark {
    background-color: color-mix(in srgb, var(--primary) 66%, transparent);
    color: white;
    border-radius: 3px;
    padding: 0 0.15em;
}

/* --- Buttons --- */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background-color: var(--primary);
    color: white;
    text-decoration: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s;
}
.btn:not(:disabled):hover { background-color: var(--primary-hover); }

.btn-danger { background-color: var(--danger); }
.btn-danger:not(:disabled):hover { background-color: var(--danger-hover); }

.btn-secondary {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}
.btn-secondary:not(:disabled):hover {
    background-color: var(--hover-bg);
    border-color: var(--text-muted);
}

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border-radius: 4px;
}

.btn-tech { background-color: #3b82f6; }       /* Matches --primary */
.btn-tech:not(:disabled):hover { background-color: #2563eb; }

.btn-finance { background-color: #10b981; }    /* Emerald Green */
.btn-finance:not(:disabled):hover { background-color: #059669; }

.btn-other { background-color: #f97316; }      /* Orange */
.btn-other:not(:disabled):hover { background-color: #ea580c; }

.btn-home { background-color: #8b5cf6; }       /* Purple */
.btn-home:not(:disabled):hover { background-color: #7c3aed; }

.btn-generic { background-color: #8f40da; }    /* Deep Purple */
.btn-generic:not(:disabled):hover { background-color: #7a32bd; }

.btn-other-secondary { background-color: #10ac9f; }      /* Orange */
.btn-other-secondary:not(:disabled):hover { background-color: #12a8d6; }

/* --- Modal (see partials/link-list-modal.phtml, or the local copy on billing/services/form.phtml) --- */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.modal-content {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    color: var(--text-main);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    padding: 1.5rem;
    z-index: 1000;
    text-align: left;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--text-main);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body .btn {
    display: block;
    width: 100%;
    margin-bottom: 0.5rem;
}

.modal-body .btn:last-child {
    margin-bottom: 0;
}

/* --- Dashboard Layout & Cards --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--bg-color);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.card h2 {
    margin-top: 0;
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1.25rem;
}

.dashboard-grid > .card,
.card {
    min-width: 0;
}

/* Ensure block buttons inside cards stack cleanly */
.card .btn-block {
    margin-top: 0.75rem;
    text-align: center;
}

/* --- Overview & Detail Rows --- */
.overview-wrapper {
    flex-grow: 0.5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem 5rem 1rem;
}

.overview-card {
    width: 100%;
    max-width: 80%;
    background: var(--card-bg);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
}

.detail-row:last-child {
    border-bottom: none;
    padding-bottom: 0.25rem;
}

.detail-label {
    color: var(--text-muted);
    font-weight: 500;
}

.detail-value {
    font-weight: 600;
    color: var(--text-main);
    text-align: right;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1.25rem;
}

.card-header-flex h2 {
    margin: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.card-actions-footer {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-controls label {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.chart-controls select {
    width: auto;
}

.chart-container {
    position: relative;
    width: 100%;
    min-height: 350px;
}

.chart-container--compact {
    min-height: 220px;
}

.detail-value-highlight {
    font-size: 1.1rem;
    color: var(--primary);
}

.detail-notes {
    font-weight: normal;
    font-size: 0.9rem;
    text-align: right;
    max-width: 60%;
}

/* --- Navigation Groups --- */
.nav-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.nav-group:last-child {
    margin-bottom: 0;
}

.nav-group strong {
    color: var(--text-muted);
    width: 90px;
    font-size: 0.95rem;
}

.nav-group-actions {
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

/* --- Tables & Wrappers --- */
.table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    margin-top: 1rem;
    margin-bottom: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    border: none;
}

/* Two stacked tables sharing one .table-wrapper (e.g. a running-total table
   pinned under the main one) - fixed layout forces both to split their
   shared 100% width into equal columns instead of auto-sizing to their own
   content, so columns land in the same place in both tables. */
.data-table--aligned {
    table-layout: fixed;
}

.data-table--summary {
    border-top: 2px solid var(--border-color);
    box-shadow: none;
    border-radius: 0;
}

/* Tables placed directly inside a card (i.e. not already wrapped in
   .table-wrapper/.table-responsive) shouldn't spill outside the card - scroll
   horizontally instead. */
.card table {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

th, .data-table th {
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table th, .data-table td {
    padding: 0.85rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

/* Lets a cell size itself to its own content (e.g. a page path/URL) instead
   of forcing the whole table wider than the viewport - long values get a
   local horizontal scrollbar instead of blowing out the layout. */
.page-cell {
    display: inline-block;
    max-width: min(480px, 50vw);
    overflow-x: auto;
    white-space: nowrap;
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
    background-color: var(--hover-bg);
}

/* Rows that navigate on click as a whole (see tickets.js and
   crm/partials/tickets-table.phtml) work at every width, but this extra
   hover affordance is desktop-only - it doesn't mean anything on touch,
   and the mobile stacked-card layout already reads as one tappable unit. */
@media (min-width: 1001px) {
    .data-table--clickable-rows tbody tr {
        cursor: pointer;
    }

    .data-table--clickable-rows tbody tr:hover {
        box-shadow: inset 3px 0 0 var(--primary);
    }
}

/* --- Contract family trees (billing/contracts/list.phtml) --- */
/* The row list is already flattened depth-first, so a child contract's row
   always directly follows its parent (and any of the parent's earlier
   children) - indenting by --row-depth and drawing a small elbow into the
   name cell reads as "this belongs to the row above" without an actual
   nested <table>, which HTML/CSS makes awkward to align column-for-column
   with the outer one anyway. */
.child-contract-row {
    background: color-mix(in srgb, var(--primary) 5%, transparent);
}

/* Indenting the cell and drawing an elbow into it only makes sense in the
   table layout - the mobile stacked-card version (see the responsive
   block below) indents the whole card and skips the elbow instead. */
@media (min-width: 1001px) {
    .data-table td.contract-name-cell {
        position: relative;
        padding-left: calc(1.25rem + var(--row-depth, 0) * 1.5rem);
    }

    .child-contract-row td.contract-name-cell::before {
        content: "";
        position: absolute;
        left: calc(1.25rem + (var(--row-depth, 0) - 1) * 1.5rem + 0.4rem);
        top: 0;
        width: 0.75rem;
        height: 50%;
        border-left: 2px solid var(--border-color);
        border-bottom: 2px solid var(--border-color);
        border-bottom-left-radius: 6px;
    }
}

.data-table td[colspan] {
    padding: 2rem 1rem;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.data-table .numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table td.numeric.highlight {
    color: var(--primary);
    font-weight: 700;
}

.muted-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 1rem 0 0;
}

.cell-subtext {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 0.15rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary) 18%, transparent);
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

/* --- Rendered third-party HTML (ticket descriptions/replies from
   FreshService - see tickets/detail.phtml) --- */
/* Styled to match the rest of the dark theme. Mail clients (Outlook in
   particular) bake an explicit `color: rgb(0, 0, 0)` etc. onto every
   paragraph, which no non-!important rule can override - so every
   inherited author colour is forced back to the theme below, and the
   handful of elements that should still stand out (links, quotes, code)
   are re-asserted with their own !important on top of that. */
.rich-content, .rich-content * {
    color: var(--text-main) !important;
    background-color: transparent !important;
}

.rich-content {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    font-size: 0.95rem;
    line-height: 1.6;
    overflow-x: auto;
}

.rich-content > :first-child { margin-top: 0; }
.rich-content > :last-child { margin-bottom: 0; }

.rich-content h1, .rich-content h2, .rich-content h3,
.rich-content h4, .rich-content h5, .rich-content h6 {
    margin: 1.1em 0 0.5em;
    line-height: 1.3;
    color: inherit;
    border: none;
    padding: 0;
}
.rich-content h1 { font-size: 1.5rem; }
.rich-content h2 { font-size: 1.3rem; }
.rich-content h3 { font-size: 1.15rem; }
.rich-content h4, .rich-content h5, .rich-content h6 { font-size: 1rem; }

.rich-content p,
.rich-content ul,
.rich-content ol,
.rich-content blockquote,
.rich-content pre,
.rich-content table {
    margin: 0 0 1em;
}

.rich-content ul, .rich-content ol {
    padding-left: 1.5rem;
}

.rich-content a {
    color: var(--primary) !important;
    text-decoration: underline;
}

.rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.rich-content table {
    border-collapse: collapse;
    max-width: 100%;
}

.rich-content th, .rich-content td {
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
    text-align: left;
}

.rich-content blockquote {
    border-left: 3px solid var(--border-color);
    padding: 0.25rem 0 0.25rem 1rem;
    color: var(--text-muted) !important;
}

.rich-content pre {
    background: var(--hover-bg) !important;
    border-radius: 4px;
    padding: 0.75rem 1rem;
    overflow-x: auto;
}

.rich-content code {
    background: var(--hover-bg) !important;
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-size: 0.9em;
}

.rich-content pre code {
    padding: 0;
    background: none !important;
}

.rich-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5em 0;
}

/* --- Empty states & accordions (customer CRM pages: services, billing, invoices) --- */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
    margin: 0;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

details > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1.1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-weight: 600;
    color: var(--text-main);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

details > summary::-webkit-details-marker { display: none; }
details > summary::marker { content: ""; }

details > summary::after {
    content: "\25BE";
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

details > summary:hover { background: var(--hover-bg); }

details[open] > summary {
    border-color: var(--primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

details[open] > summary::after { transform: rotate(-180deg); }

.details-content {
    border: 1px solid var(--border-color);
    border-top: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    padding: 1.1rem;
}

.usage-details {
    margin-bottom: 1rem;
}

/* --- Time block usage summaries (crm/billing.phtml) --- */
.timeblock-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.timeblock-section:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.timeblock-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 1.5rem;
    padding: 0.85rem 1.1rem;
    margin-bottom: 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
}

.timeblock-summary strong {
    color: var(--text-main);
}

.timeblock-summary > div:last-child {
    margin-left: auto;
}

/* --- Pagination Controls --- */
.pagination-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-indicator {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Links & Status Pills --- */
.user-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.user-link:hover {
    text-decoration: underline;
}

.status {
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    display: inline-block;
}
/* Log Levels */
.alert { background: #881337; color: #fda4af; border: 1px solid #9f1239; }
.error { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }
.warning { background: #78350f; color: #fcb64d; border: 1px solid #92400e; }
.info { background: #0c4a6e; color: #7dd3fc; border: 1px solid #075985; }
.debug { background: #334155; color: #cbd5e1; border: 1px solid #475569; }

/* Contract Types */
.hybrid { background: #0c4a6e; color: #7dd3fc; border: 1px solid #075985; }
.inherit { background: #4c1d95; color: #c4b5fd; border: 1px solid #5b21b6; }
.group { background: #134e4a; color: #5eead4; border: 1px solid #115e59; }
.prepay { background: #14532d; color: #86efac; border: 1px solid #166534; }
.services { background: #701a75; color: #f0abfc; border: 1px solid #86198f; }

/* Invoices */
.draft { background: #0f172a; color: #cbd5e1; border: 1px solid #1e293b; }
.submitted { background: #1e1b4b; color: #c7d2fe; border: 1px solid #312e81; }
.authorised, .authorized { background: #7c2d12; color: #fed7aa; border: 1px solid #9a3412; }
.paid { background: #064e3b; color: #6ee7b7; border: 1px solid #065f46; }
.voided { background: #18181b; color: #d4d4d8; border: 1px solid #27272a; }
.deleted { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }

/* Services */
.expired { background: #78350f; color: #fcb64d; border: 1px solid #92400e; }
.notstarted { background: #0c4a6e; color: #7dd3fc; border: 1px solid #075985; }
.active { background: #14532d; color: #86efac; border: 1px solid #166534; }

/* Ticket Statuses */
.open { background: #14532d; color: #86efac; border: 1px solid #166534; }
.onsite { background: #0c4a6e; color: #7dd3fc; border: 1px solid #075985; }
.waiting_for_customer { background: #78350f; color: #fcb64d; border: 1px solid #92400e; }
.onsite_waiting_for_customer { background: #7c2d12; color: #fed7aa; border: 1px solid #9a3412; }
.closed { background: #334155; color: #cbd5e1; border: 1px solid #475569; }
.scheduled { background: #701a75; color: #f0abfc; border: 1px solid #86198f; }

/* Generic */
.ok { background: rgb(20 83 45 / 0.66); color: rgb(172 243 197); border: 1px solid rgb(22 101 52 / 0.66); }

span.low, td.low { color: #ff7676; font-weight: 600; }

/* Alert Row Enhancements */
.alert-row {
    background-color: rgba(239, 68, 68, 0.15) !important;
}
.alert-row:hover {
    background-color: rgba(239, 68, 68, 0.25) !important;
}
.alert-row td:first-child {
    border-left: 4px solid var(--danger);
}
.alert-row td {
    border-bottom: 1px solid rgba(239, 68, 68, 0.3) !important;
}
.new-row td {
    background-color: rgb(79 239 68 / 0.10) !important;
}
.new-row td:first-child {
    border-left: 4px solid rgb(79 239 68 / 0.50);
}

/* --- Log Navigation --- */
.log-nav {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.log-nav a {
    text-decoration: none;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    transition: all 0.2s;
}
.log-nav a:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
}
.log-nav a.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* --- Form Elements & Layouts --- */
.form-container { display: flex; flex-direction: column; gap: 1.5rem; justify-content: center; min-width: 65%; margin: 0 auto; }
.input-container { margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.4rem; }

.form-row { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.form-group { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 0.4rem; }
.form-section-footer { border-top: 1px solid var(--border-color); padding-top: 1rem; align-items: center; }

.checkbox-row { display: flex; align-items: center; gap: 0.75rem; }
.checkbox-inline-group { display: flex; align-items: center; gap: 0.75rem; margin: 0; }
.no-margin { margin-bottom: 0 !important; }

/* Typography */
.input-container label, .form-group label { font-weight: 500; color: var(--text-muted); font-size: 0.9rem; }
.checkbox-row label, .checkbox-inline-group label { color: var(--text-main); font-weight: normal; margin-bottom: 0; }

/* Input Styling */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="datetime-local"],
select {
    width: 100%;
    padding: 0.6rem;
    border-radius: 6px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}
input[type="text"]:disabled,
input[type="number"]:disabled,
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[readonly],
textarea[readonly],
select:disabled,
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--disabled-bg);
}

button:disabled:hover {
    cursor: not-allowed;
    background: var(--disabled-bg);
    border: none;
}

/* Custom File Upload Styling */
input[type="file"] {
    width: 100%;
    padding: 0.6rem;
    border-radius: 6px;
    background: var(--bg-color);
    border: 1px dashed var(--border-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}
input[type="file"]:hover {
    border-color: var(--primary);
    background: var(--hover-bg);
}
input[type="file"]::-webkit-file-upload-button {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.4rem 0.8rem;
    margin-right: 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background-color 0.2s;
}
input[type="file"]::-webkit-file-upload-button:hover {
    background: var(--hover-bg);
    border-color: var(--text-muted);
}

/* Specific Element Overrides */
.select-auto { width: auto; padding: 0.25rem; font-size: 0.85rem; }
.btn-block { width: 100%; margin-top: 1rem; padding: 0.75rem; font-size: 1rem; }
.spacer { flex-grow: 1; }

/* Banners */
.error-banner {
    background: rgba(239, 68, 68, 0.15);
    border-left: 4px solid var(--danger);
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
    color: var(--text-main);
}

.success-banner {
    background: rgba(34, 197, 94, 0.15);
    border-left: 4px solid #22c55e;
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
    color: var(--text-main);
}

/* --- Authentication & Login Viewport --- */
.auth-viewport {
    min-height: 85vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
    padding: 2.5rem 2rem;
    margin: auto;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.auth-logo {
    max-width: 85%;
    max-height: 55px;
    width: auto;
    height: auto;
    margin: 0 auto 1.5rem auto;
    display: block;
}

.provider-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    margin-top: 0.75rem;
    text-decoration: none;
}

.provider-btn img {
    width: 20px;
    height: 20px;
    object-fit: contain;
    flex-shrink: 0;
}

/* --- Helpers --- */
.hidden {
    display: none !important;
}

/* --- Responsive Adjustments --- */
@media (max-width: 1000px) {
    body {
        padding: 0 1rem;
        max-width: 100%;
    }

    /* A lot of one-off page layouts use inline `style="display: flex; ..."`
       row headers (title + actions, totals, etc.) rather than a shared
       class. Rather than touching every template, let any inline flex
       row wrap instead of squeezing/overflowing on narrow viewports. */
    [style*="display: flex"] {
        flex-wrap: wrap;
    }

    .dashboard-header {
        grid-template-columns: 1fr;
        gap: 1rem;
        text-align: center;
    }

    .dashboard-header {
        margin-top: 0.5rem;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }

    .dashboard-header h1 {
        font-size: 1.5rem;
        padding: 0;
    }

    .header-logo, .user-info {
        justify-content: center;
    }

    .card {
        padding: 1.1rem;
        margin-bottom: 1rem;
    }

    .card h2 {
        margin-bottom: 0.85rem;
        padding-bottom: 0.35rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .card-header-flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .card-actions-footer {
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .card-actions-footer .btn {
        flex: 1 1 auto;
        text-align: center;
    }

    /* --- Nav groups: full-width label above buttons that grow to fill
       the row instead of sitting left-aligned with empty space --- */
    .nav-group {
        gap: 0.5rem;
        margin-bottom: 0.85rem;
    }

    .nav-group strong {
        width: 100%;
    }

    .nav-group .btn {
        flex: 1 1 calc(50% - 0.375rem);
        text-align: center;
    }

    /* --- Tables: stacked label/value cards instead of a table that only
       works via horizontal scrolling. responsive-tables.js copies each
       column's header text onto its cells as `data-label`, which the
       ::before rules below turn into the visible label. --- */
    /* The row cards below carry their own border/background, so drop the
       wrapper's so tables don't end up double-bordered. */
    .table-wrapper, .table-responsive {
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .data-table thead {
        display: none;
    }

    .data-table, .data-table tbody {
        display: block;
        width: 100%;
        /* The table's own background (var(--card-bg), set for the desktop
           layout) would otherwise fill the gaps between row cards too -
           let the page/card background behind it show through there. */
        background: transparent;
    }

    .data-table tr {
        display: block;
        background: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 0.75rem;
        overflow: hidden;
    }

    .data-table tr:last-child {
        margin-bottom: 0;
    }

    /* Contract family trees (see the desktop rules above) - indent the
       whole card and give it a coloured edge instead of drawing an elbow
       into a single cell, so a child contract still visibly hangs off its
       parent once rows are stacked. */
    .data-table tr.child-contract-row {
        width: auto;
        margin-left: calc(0.5rem + var(--row-depth, 0) * 1rem);
        border-left: 3px solid var(--primary);
        background: color-mix(in srgb, var(--primary) 6%, var(--card-bg));
    }

    .data-table td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
        /* Several tables set a fixed pixel width inline for desktop column
           sizing (e.g. billing/view.phtml's alerts/event log). Inline
           styles beat this class regardless of specificity, so !important
           is needed to make the row card full-width again on mobile. */
        width: 100% !important;
        padding: 0.6rem 0.85rem;
        border-bottom: 1px dashed var(--border-color);
    }

    .data-table td:last-child {
        border-bottom: none;
    }

    .data-table td::before {
        content: attr(data-label);
        font-size: 0.7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
    }

    .data-table td:not([data-label]),
    .data-table td[data-label=""] {
        gap: 0;
    }

    .data-table td:not([data-label])::before,
    .data-table td[data-label=""]::before {
        content: none;
    }

    /* Cells with nothing worth showing (blank, or a muted "-"/"—"
       placeholder - see responsive-tables.js) just repeat the label with
       no value on a card; drop the field entirely instead. */
    .data-table td.is-empty-value {
        display: none;
    }

    /* Cells spanning the whole row (loading/empty states) shouldn't get
       the label treatment - keep them as plain centred blocks. */
    .data-table td[colspan] {
        display: block;
        text-align: center;
    }

    .data-table .numeric {
        text-align: left;
    }

    /* Long values (e.g. page URLs in the auth log) get a card-width line
       wrap instead of their own nested horizontal scrollbar. */
    .page-cell {
        display: block;
        max-width: 100%;
        overflow-x: visible;
        white-space: normal;
        word-break: break-all;
    }

    .action-buttons {
        flex-wrap: wrap;
    }

    /* --- Detail rows: stack label/value once the row can't fit both
       on one line, instead of squashing the value column --- */
    .detail-row {
        flex-wrap: wrap;
        gap: 0.25rem 1rem;
    }

    .detail-notes {
        max-width: 100%;
    }

    .timeblock-summary > div:last-child {
        margin-left: 0;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-container {
        min-width: 100%;
    }

    .overview-card {
        max-width: 100%;
    }

    .modal-content {
        width: calc(100% - 2rem);
        padding: 1.25rem;
    }
}