/* assets/style.css */
:root {
    color-scheme: dark;
    font-size: 14px;
    --primary-color: #3568bd;
    --secondary-color: #2f4158;
    --accent-color: #63a8f4;
    --success-color: #43c794;
    --warning-color: #f0b858;
    --danger-color: #ef7777;
    --bg-color: #0b1220;
    --card-bg: #121d2c;
    --sidebar-bg: #0e1725;
    --text-color: #e8eef7;
    --text-muted: #a7b4c6;
    --border-color: #29384b;
    --glass-border: 1px solid var(--border-color);
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    --sidebar-width: 240px;
    --control-height: 36px;
    --form-font-size: 13px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

a:hover {
    color: #91c5ff;
}

:focus-visible {
    outline: 3px solid #8fc2ff;
    outline-offset: 3px;
}

.skip-link {
    position: fixed;
    z-index: 1200;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.75rem 1rem;
    transform: translateY(-160%);
    border-radius: 8px;
    background: #fff;
    color: #102033;
    font-weight: 700;
}

.skip-link:focus {
    transform: translateY(0);
}

.glass-panel {
    border: var(--glass-border);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.btn {
    min-height: var(--control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.45rem 0.8rem;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-color);
    font-weight: 600;
    font-size: 13px;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.btn:hover {
    color: #fff;
}

.btn-primary {
    border-color: #5c91ed;
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 210, 0.2);
}

.btn-primary:hover {
    border-color: #78a7f5;
    background: #3d72d1;
    color: #fff;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    z-index: 1010;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    border-right: 1px solid var(--border-color);
    border-radius: 0;
    background: var(--sidebar-bg);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.12);
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sidebar .brand-logo img {
    max-width: 170px !important;
}

.nav-section-label {
    padding: 1rem 0.8rem 0.35rem;
    color: #8494aa;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding: 0.65rem 0.8rem;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.nav-link:hover {
    background: rgba(148, 173, 205, 0.09);
    color: #fff;
}

.nav-link.active {
    border-color: rgba(99, 168, 244, 0.2);
    background: rgba(76, 131, 230, 0.16);
    color: #a8ceff;
}

.nav-link i {
    width: 1.15rem;
    flex: 0 0 1.15rem;
    color: #91a6c2;
    text-align: center;
}

.nav-link.active i {
    color: #8fc2ff;
}

.main-content {
    width: calc(100% - var(--sidebar-width));
    min-width: 0;
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    padding: clamp(1rem, 2vw, 1.75rem);
    overflow-x: hidden;
}

.main-content > .glass-panel {
    padding: 1rem !important;
    margin-bottom: 0.85rem !important;
}

.main-content > div[style*="grid-template-columns"] > .glass-panel {
    padding: 0.85rem !important;
}

.dashboard-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)) !important;
    gap: 0.75rem !important;
    margin-bottom: 0.85rem !important;
}

.dashboard-entity-grid {
    gap: 0.75rem !important;
}

.dashboard-entity-grid > div {
    padding: 0.75rem !important;
}

.main-content > .dashboard-summary-grid > .dashboard-summary-card.glass-panel,
.main-content > .invoice-summary-grid > .invoice-summary-card.glass-panel {
    padding: 0.75rem !important;
}

.dashboard-summary-value,
.invoice-summary-value {
    font-size: 1.25rem !important;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.main-content .glass-panel div[style*="font-size: 1.5rem"] {
    font-size: 1.25rem !important;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.invoice-data-table th,
.invoice-data-table td {
    padding: 0.55rem 0.7rem;
}

.invoice-data-table {
    min-width: 1240px;
}

.invoice-data-table td:nth-child(1),
.invoice-data-table td:nth-child(2),
.invoice-data-table td:nth-child(5),
.invoice-data-table td:nth-child(6),
.invoice-data-table td:nth-child(7),
.invoice-data-table td:nth-child(8),
.invoice-data-table td:nth-child(9),
.invoice-data-table td:nth-child(10) {
    white-space: nowrap;
}

.invoice-data-table td:nth-child(3) {
    min-width: 210px;
}

.invoice-data-table td:nth-child(4) {
    min-width: 160px;
}

.form-group {
    min-width: 0;
    margin-bottom: 0.75rem;
}

.main-content form div[style*="display: grid"] {
    gap: 0.75rem !important;
    min-width: 0;
}

.main-content form div[style*="display: grid"] > .form-group {
    margin-bottom: 0;
}

.main-content form .form-control {
    font-size: var(--form-font-size) !important;
}

.main-content form > div[style*="margin-top: 2rem"] {
    margin-top: 1rem !important;
}

.main-content form h3,
.main-content form h4 {
    margin-top: 0.85rem !important;
    margin-bottom: 0.6rem !important;
    padding-bottom: 0.4rem !important;
    font-size: 1rem;
}

.settings-layout {
    gap: 1rem !important;
}

.settings-navigation {
    flex: 0 0 190px !important;
}

.settings-form-panel {
    min-width: 0;
    padding: 1rem !important;
}

.settings-form-panel form .row {
    gap: 0.75rem;
    margin: 0 !important;
}

.settings-form-panel form .row > .form-group {
    padding: 0 !important;
}

.main-content .glass-panel > h1,
.main-content .glass-panel > h2 {
    margin-bottom: 0.75rem !important;
}

.table.pending-invoices-table {
    min-width: 850px;
}

.pending-invoices-table td {
    white-space: nowrap;
}

.table.pending-invoices-table th,
.table.pending-invoices-table td {
    padding: 0.4rem 0.45rem;
}

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

.pending-invoices-table .inv-allocation {
    width: 105px;
    min-width: 105px;
    text-align: right;
}

.tds-rate {
    display: block;
    font-size: 12px;
    line-height: 1.3;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.inv-checkbox {
    width: 18px;
    height: 18px;
    vertical-align: middle;
}

.invoice-form-panel {
    padding: 1rem !important;
}

.invoice-form .form-group {
    margin-bottom: 0;
}

.invoice-form .form-label {
    margin-bottom: 0.3rem;
}

.invoice-items-section {
    padding: 0.85rem !important;
}

.invoice-item-fields .form-control {
    min-width: 0;
}

.main-content .invoice-form .invoice-item-fields {
    gap: 0.6rem !important;
}

.invoice-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.25rem;
    color: #c1ccda;
    font-size: 12px;
    font-weight: 600;
}

.form-control {
    width: 100%;
    min-height: var(--control-height);
    padding: 0.4rem 0.65rem;
    border: 1px solid #3a4b61;
    border-radius: 8px;
    background: #0d1725;
    color: var(--text-color);
    font-size: var(--form-font-size);
    line-height: 1.4;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

.form-control::placeholder {
    color: #91a0b4;
    opacity: 1;
}

.form-control:focus {
    border-color: #78a7f5;
    outline: none;
    box-shadow: 0 0 0 3px rgba(76, 131, 230, 0.22);
}

.form-control:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.password-visibility-toggle {
    position: absolute;
    top: 50%;
    right: 0.25rem;
    width: 44px;
    height: var(--control-height);
    display: grid;
    place-items: center;
    transform: translateY(-50%);
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #b7c8dc;
    cursor: pointer;
}

.password-visibility-toggle:hover {
    background: rgba(148, 173, 205, 0.12);
    color: #fff;
}

.table-container {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    scrollbar-color: #536780 #152235;
}

.table {
    width: 100%;
    min-width: 640px;
    margin-top: 0;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.4;
}

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

.table th {
    background: #162336;
    color: #bdc9d8;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.025em;
}

.table td {
    color: #dce5ef;
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table tbody tr:hover {
    background: rgba(148, 173, 205, 0.055);
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0.2rem 0.55rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
}

.badge-success {
    border-color: rgba(67, 199, 148, 0.25);
    background: rgba(67, 199, 148, 0.13);
    color: #76e0b5;
}

.badge-warning {
    border-color: rgba(240, 184, 88, 0.25);
    background: rgba(240, 184, 88, 0.13);
    color: #f6cc7c;
}

.badge-danger {
    border-color: rgba(239, 119, 119, 0.25);
    background: rgba(239, 119, 119, 0.13);
    color: #ff9a9a;
}

.badge-info {
    border-color: rgba(124, 196, 248, 0.28);
    background: rgba(124, 196, 248, 0.13);
    color: #9fd4fb;
}

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

.text-danger {
    color: #ff9a9a !important;
}

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background:
        radial-gradient(ellipse at 50% 0, rgba(53, 102, 177, 0.2), transparent 55%),
        var(--bg-color);
}

.login-box {
    width: 100%;
    max-width: 420px;
    padding: clamp(1.5rem, 5vw, 2.5rem);
}

.brand-logo {
    margin-bottom: 2rem;
    color: #a9ccff;
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
}

.mobile-nav-toggle,
.sidebar-scrim {
    display: none;
}

@media (max-width: 760px) {
    :root {
        --control-height: 44px;
        --form-font-size: 14px;
    }

    .sidebar {
        width: min(290px, calc(100vw - 48px));
        visibility: hidden;
        transform: translateX(-100%);
        transition: transform 180ms ease, visibility 180ms ease;
    }

    .sidebar .brand-logo {
        padding-top: 3.5rem;
    }

    .sidebar.is-open {
        visibility: visible;
        transform: translateX(0);
    }

    .sidebar-scrim {
        position: fixed;
        z-index: 1005;
        inset: 0;
        display: block;
        border: 0;
        background: rgba(3, 8, 15, 0.72);
        cursor: pointer;
    }

    .sidebar-scrim[hidden] {
        display: none;
    }

    .mobile-nav-toggle {
        position: fixed;
        z-index: 1020;
        top: 0.75rem;
        left: 0.75rem;
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.55rem;
        padding: 0.55rem 0.75rem;
        border: 1px solid #3a4b61;
        border-radius: 8px;
        background: #142237;
        color: #e8eef7;
        font-weight: 600;
        cursor: pointer;
        box-shadow: 0 5px 16px rgba(0, 0, 0, 0.22);
    }

    .main-content {
        width: 100%;
        margin-left: 0;
        padding: 4.5rem 1rem 1.5rem;
    }

    .invoice-fields-grid,
    .invoice-item-fields {
        grid-template-columns: 1fr !important;
    }

    .invoice-fields-grid > .form-group[style*="grid-column: span 2"] {
        grid-column: 1 / -1 !important;
    }

    .invoice-form-actions .btn {
        flex: 1;
    }

    .main-content form div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .main-content form div[style*="grid-template-columns: 1fr 1fr"] > .form-group {
        grid-column: 1 / -1 !important;
    }

    .settings-layout,
    .settings-form-panel form .row {
        flex-direction: column;
    }

    .settings-navigation,
    .settings-form-panel {
        flex: auto !important;
        width: 100%;
        max-width: none !important;
    }

    .settings-navigation ul {
        flex-direction: row !important;
        flex-wrap: wrap;
    }

    .settings-navigation a {
        min-height: 44px;
        padding: 0.65rem 0.75rem !important;
    }
}

@media (max-width: 420px) {
    .main-content {
        padding-right: 0.75rem;
        padding-left: 0.75rem;
    }

    .table th,
    .table td {
        padding: 0.55rem 0.65rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---- Users, roles and activity log ---- */
.nav-user {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin: 0 0.25rem 0.75rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.nav-user-name {
    overflow: hidden;
    color: var(--text-color);
    font-size: 0.85rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-user-role {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.auth-flash {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(240, 184, 88, 0.35);
    border-radius: 8px;
    background: rgba(240, 184, 88, 0.1);
    color: #f6cf8a;
}

.access-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.access-tabs a {
    margin-bottom: -1px;
    padding: 0.6rem 0.9rem;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-weight: 600;
    text-decoration: none;
}

.access-tabs a:hover {
    color: var(--text-color);
}

.access-tabs a[aria-current="page"] {
    border-bottom-color: var(--accent-color);
    color: var(--text-color);
}

.access-flash {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
}

.access-flash-ok {
    border: 1px solid rgba(67, 199, 148, 0.35);
    background: rgba(67, 199, 148, 0.1);
    color: #8fe6c2;
}

.access-flash-err {
    border: 1px solid rgba(239, 119, 119, 0.35);
    background: rgba(239, 119, 119, 0.1);
    color: #ffb4b4;
}

.access-flash-err ul {
    margin: 0.35rem 0 0 1.1rem;
    padding: 0;
}

.user-cell-name {
    color: var(--text-color);
    font-weight: 600;
}

.user-cell-sub {
    color: var(--text-muted);
    font-size: 0.8rem;
}

tr.user-off td {
    opacity: 0.55;
}

.form-hint {
    margin-top: 0.3rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Permission grid: the left edge of each select shows the level at a glance. */
.perm-grid th:first-child,
.perm-grid td:first-child {
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 1;
}

.perm-select {
    min-width: 150px;
    border-left-width: 4px !important;
}

.perm-select.lvl-0 { border-left-color: #4a5a70 !important; color: var(--text-muted); }
.perm-select.lvl-1 { border-left-color: #7cc4f8 !important; }
.perm-select.lvl-2 { border-left-color: #f0b858 !important; }
.perm-select.lvl-3 { border-left-color: #43c794 !important; }

.perm-fixed {
    color: #76e0b5;
    font-weight: 600;
}

.perm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 0;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    list-style: none;
}

.perm-legend li::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 0.9em;
    margin-right: 0.45rem;
    border-radius: 2px;
    vertical-align: -0.1em;
    background: currentColor;
}

.perm-legend .lvl-0::before { background: #4a5a70; }
.perm-legend .lvl-1::before { background: #7cc4f8; }
.perm-legend .lvl-2::before { background: #f0b858; }
.perm-legend .lvl-3::before { background: #43c794; }

/* Activity log */
.act-time {
    white-space: nowrap;
}

.act-time small {
    display: block;
    color: var(--text-muted);
}

.act-badge {
    min-width: 92px;
    justify-content: center;
}

.act-neutral {
    border-color: rgba(167, 180, 198, 0.25);
    background: rgba(167, 180, 198, 0.1);
    color: #c3cedc;
}

.act-changes summary {
    margin-top: 0.3rem;
    color: var(--accent-color);
    font-size: 0.8rem;
    cursor: pointer;
}

.act-changes dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 0.75rem;
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
}

.act-changes dt {
    color: var(--text-muted);
}

.act-changes dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.act-changes del {
    color: #ff9a9a;
}

.act-changes ins {
    color: #76e0b5;
    text-decoration: none;
}

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}
