:root {
    --navy: #1E3A5F;
    --navy-dark: #162D49;
    --green: #2E7D5B;
    --bg: #F5F7FA;
    --border: #E5E7EB;
    --text: #1F2937;
    --muted: #6B7280;
    --blue: #2563EB;
    --amber: #F59E0B;
    --red: #DC3545;
    --purple: #6F42C1;
    --dark-gray: #374151;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.btn-primary-custom,
.btn-success-custom,
.btn-info-custom,
.btn-warning-custom,
.btn-danger-custom,
.btn-secondary-custom {
    color: #fff;
    border: 0;
}

.btn-primary-custom { background: var(--navy); }
.btn-primary-custom:hover { background: var(--navy-dark); color: #fff; }
.btn-success-custom { background: var(--green); }
.btn-info-custom { background: var(--blue); }
.btn-warning-custom { background: var(--amber); }
.btn-danger-custom { background: var(--red); }
.btn-secondary-custom { background: var(--muted); }

.form-control,
.form-select {
    border-color: var(--border);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 .2rem rgba(30, 58, 95, .15);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background-image: url('/assets/images/bg1_archive_indigo.svg');
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
}

.login-card {
    width: min(100%, 440px);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(30, 58, 95, .12);
    padding: calc(2rem + 33px) 2rem 2rem;
}

.login-panel {
    width: min(100%, 440px);
}

.login-panel > .login-brand {
    justify-content: center;
    position: relative;
    z-index: 2;
    margin-bottom: -63px;
}

.login-logo-mark {
    width: 125px;
    height: 125px;
    display: grid;
    place-items: center;
}

.login-logo-mark img {
    max-width: 100%;
    height: auto;
    border-radius: 50%;
}

.login-brand,
.sidebar-brand {
    display: flex;
    gap: .875rem;
    align-items: center;
}

.login-brand h1 {
    margin: 0;
    color: var(--navy);
    font-size: 1.6rem;
    font-weight: 700;
}

.login-brand-text h1 {
    margin: 0;
    color: var(--navy);
    font-size: 1.6rem;
    font-weight: 700;
}

.login-brand-text {
    text-align: center;
}

.login-brand p,
.login-brand-text p,
.content-card-header p {
    margin: 0;
    color: var(--muted);
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--green);
    color: #fff;
    font-size: 1.35rem;
}

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

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    width: 280px;
    /* Original sidebar background: var(--navy); */
    background: linear-gradient(180deg, #1E3A5F 0%, #162D49 58%, #2E7D5B 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform .2s ease;
}

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

.sidebar-brand {
    padding: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.brand-title {
    font-weight: 700;
}

.brand-subtitle {
    color: #CBD5E1;
    font-size: .85rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem .75rem;
}

.sidebar-footer {
    padding: .75rem;
    border-top: 1px solid rgba(255, 255, 255, .12);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .72rem .9rem;
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
    margin-bottom: .2rem;
}

.sidebar-link:hover {
    /* Original hover background: rgba(255, 255, 255, .10); */
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.sidebar-link.active {
    /* Original active background: var(--green); */
    background: rgba(46, 125, 91, .95);
}

.sidebar-toggle {
    border: 0;
    width: 100%;
    background: transparent;
    text-align: left;
}

.sidebar-sub {
    margin-left: 1.7rem;
    padding-top: .55rem;
    padding-bottom: .55rem;
    font-size: .92rem;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1030;
    background: rgba(15, 23, 42, .45);
}

.app-main {
    min-width: 0;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: 76px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
}

.app-topbar h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
}

.content-wrap {
    position: relative;
    isolation: isolate;
    flex: 1;
    padding: 1rem;
    overflow: hidden;
}

.content-wrap::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
    filter: blur(5px);
    pointer-events: none;
}

.content-wrap > * {
    position: relative;
}

.non-admin-shell .content-wrap::before {
    background-image: url('/assets/images/bg3_clean_ledger_light.svg');
}

.system-admin-shell .content-wrap::before {
    background-image: url('/assets/images/bg2_automation_grid_light.svg');
}

.app-footer {
    padding: 1rem;
    color: var(--muted);
    font-size: .875rem;
}

.icon-btn {
    border: 1px solid var(--border);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: .65rem;
    border: 1px solid var(--border);
}

.user-menu small {
    display: block;
    color: var(--muted);
    text-align: left;
}

.user-avatar,
.profile-avatar {
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    font-weight: 700;
}

.user-avatar {
    width: 34px;
    height: 34px;
}

.profile-avatar {
    width: 84px;
    height: 84px;
    font-size: 2rem;
}

.card,
.content-card,
.stat-card,
.access-denied-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .04);
}

.content-card {
    padding: 1.25rem;
}

.narrow-card {
    max-width: 920px;
}

.content-card-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.content-card-header h2,
.section-title,
.profile-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.stat-card {
    padding: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dashboard-card-link {
    color: inherit;
    text-decoration: none;
    min-height: 128px;
}

.dashboard-card-link:hover {
    color: inherit;
    border-color: rgba(30, 58, 95, .28);
    transform: translateY(-1px);
}

.stat-card span {
    color: var(--muted);
    font-size: .9rem;
}

.stat-card strong {
    display: block;
    font-size: 1.85rem;
}

.stat-card small {
    display: block;
    color: var(--muted);
}

.stat-icon {
    font-size: 1.7rem;
}

.stat-icon.navy { color: var(--navy); }
.stat-icon.green { color: var(--green); }
.stat-icon.gray { color: var(--muted); }
.stat-icon.red { color: var(--red); }
.stat-icon.blue { color: var(--blue); }
.stat-icon.purple { color: var(--purple); }

.text-bg-purple {
    color: #fff;
    background: var(--purple);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .25rem .65rem;
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
}

.status-active { background: var(--green); }
.status-inactive { background: var(--muted); }
.status-suspended { background: var(--red); }
.doc-status-pending { background: var(--amber); }
.doc-status-approved { background: var(--green); }
.doc-status-rejected { background: var(--red); }
.doc-status-archived { background: var(--dark-gray); }

.conf-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .25rem .65rem;
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
}

.conf-public { background: var(--green); }
.conf-internal { background: var(--blue); }
.conf-departmental { background: var(--amber); }
.conf-restricted { background: var(--red); }
.conf-owner_only { background: var(--purple); }

.conf-text {
    font-weight: 700;
}

.conf-text-public { color: var(--green); }
.conf-text-internal { color: var(--blue); }
.conf-text-departmental { color: #B45309; }
.conf-text-restricted { color: var(--red); }
.conf-text-owner_only { color: var(--purple); }

.action-cell {
    white-space: nowrap;
}

.audit-user-agent {
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audit-json {
    padding: .85rem;
    border-radius: 8px;
    background: #F8FAFC;
    border: 1px solid var(--border);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: .85rem;
}

.audit-value-key {
    width: 34%;
    color: var(--muted);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
    margin-top: 1.25rem;
}

[x-cloak] {
    display: none !important;
}

.swal2-popup.app-toast {
    align-items: flex-start;
    max-width: min(28rem, calc(100vw - 2rem));
}

.swal2-popup.app-toast-warning {
    background: #FFF7E6;
    border: 1px solid rgba(245, 158, 11, .45);
    color: var(--text);
}

.swal2-popup.app-toast-warning .swal2-timer-progress-bar {
    background: var(--amber);
}

.swal2-title.app-toast-title {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: left;
    line-height: 1.35;
}

.upload-submit-indicator {
    margin-top: 1.25rem;
}

.batch-file-list {
    display: grid;
    gap: .85rem;
}

.batch-upload-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #F8FAFC;
}

.batch-upload-summary div {
    display: grid;
    gap: .15rem;
}

.batch-upload-summary.warning {
    border-color: rgba(220, 53, 69, .4);
    background: rgba(220, 53, 69, .08);
}

.batch-file-item {
    padding: .85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #F8FAFC;
}

.batch-file-item strong {
    display: block;
    margin-bottom: .6rem;
    color: var(--navy);
    word-break: break-word;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.profile-header p {
    margin: .25rem 0 .5rem;
    color: var(--muted);
}

.detail-grid {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: .75rem 1rem;
}

.detail-grid dt {
    color: var(--muted);
}

.detail-grid dd {
    margin: 0;
}

.file-detail-grid {
    grid-template-columns: 125px 1fr;
    word-break: break-word;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .25rem .6rem;
    background: #EEF2F7;
    color: var(--dark-gray);
    font-size: .8rem;
    font-weight: 700;
}

.filename-tag-panel,
.quick-tag-create {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.filename-tag-panel {
    display: grid;
    gap: .75rem;
}

.suggestion-label {
    margin-bottom: .4rem;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}

.tag-suggestion-list {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
}

.tag-suggestion {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    min-height: 32px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--dark-gray);
    padding: .25rem .7rem;
    font-size: .82rem;
    font-weight: 700;
}

.tag-suggestion:hover,
.tag-suggestion.selected {
    border-color: var(--green);
    background: rgba(46, 125, 91, .1);
    color: var(--green);
}

.tag-suggestion.muted {
    color: var(--navy);
}

.compact-tags {
    max-width: 220px;
}

.filepond--root {
    margin-bottom: 0;
}

.filepond--panel-root {
    background: #F8FAFC;
    border: 1px dashed var(--border);
}

.token-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.route-preview {
    display: grid;
    gap: .5rem;
}

.route-preview code {
    display: block;
    padding: .85rem;
    border-radius: 8px;
    background: #F8FAFC;
    border: 1px solid var(--border);
    color: var(--navy);
    word-break: break-word;
}

.chart-card canvas {
    width: 100% !important;
    height: 300px !important;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
}

.access-denied-card {
    max-width: 560px;
    margin: 4rem auto;
    padding: 2rem;
    text-align: center;
}

.access-denied-card i {
    color: var(--red);
    font-size: 3rem;
}

.access-denied-card h2 {
    margin-top: 1rem;
    font-weight: 700;
}

table.dataTable {
    width: 100% !important;
}

@media (min-width: 992px) {
    .app-sidebar {
        position: sticky;
        transform: none;
        flex: 0 0 280px;
    }

    .app-main {
        width: calc(100% - 280px);
    }

    .content-wrap {
        padding: 1.5rem;
    }
}

@media (max-width: 767.98px) {
    .content-card-header,
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}
