:root {
    --sidebar-width: 250px;
    --surface: #ffffff;
    --line: #d8dee8;
    --ink: #1f2937;
    --muted: #667085;
    --sidebar: #182230;
    --sidebar-active: #27364a;
}

body {
    background: #f4f6f9;
    color: var(--ink);
    font-size: 13px;
}

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

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: #fff;
    padding: 14px 12px;
    position: fixed;
    top: 0;
    bottom: 0;
    overflow-y: auto;
}

.brand-block {
    padding: 4px 8px 14px;
    border-bottom: 1px solid rgba(255,255,255,.12);
    margin-bottom: 14px;
}

.brand-title {
    font-weight: 700;
    line-height: 1.15;
}

.brand-subtitle {
    color: #b9c4d4;
    font-size: 12px;
    margin-top: 4px;
}

.app-sidebar .nav-link {
    color: #d7deea;
    border-radius: 6px;
    padding: 7px 9px;
    font-size: 13px;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

.app-main {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
}

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    font-size: 20px;
    margin: 0;
    letter-spacing: 0;
}

.content-wrap {
    padding: 18px;
}

.metric-card,
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.metric-value {
    font-size: 22px;
    line-height: 1.2;
    font-weight: 700;
    margin-top: 4px;
}

.table-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.table-card .table {
    margin: 0;
}

.search-hero {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.search-hero .form-control {
    font-size: 15px;
    padding: 9px 12px;
}

.table {
    font-size: 12px;
}

.table > :not(caption) > * > * {
    padding: .42rem .5rem;
}

.form-label {
    font-size: 12px;
    margin-bottom: 3px;
}

.form-control,
.form-select,
.btn {
    font-size: 12px;
}

.btn {
    padding: .32rem .58rem;
}

.btn-sm,
.form-control-sm,
.form-select-sm {
    font-size: 12px;
}

.permissions-compact {
    max-height: 300px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px;
    background: #f8fafc;
}

.permissions-table .form-check-input {
    margin-top: 0;
}

.invoice-assignment-box {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    background: #f8fafc;
}

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #eef2f7;
}

.login-card {
    width: 100%;
    max-width: 430px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 18px 45px rgba(20, 30, 45, .08);
}

.form-section-title {
    font-size: 16px;
    font-weight: 700;
    margin: 22px 0 12px;
}

.serial-input.accepted {
    border-color: #198754;
    box-shadow: 0 0 0 .2rem rgba(25,135,84,.12);
}

.serial-input.duplicate,
.serial-input.invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 .2rem rgba(220,53,69,.12);
}

.progress {
    height: 9px;
}

.nowrap {
    white-space: nowrap;
}

.invoice-review-layout {
    display: grid;
    grid-template-columns: minmax(430px, 40%) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.invoice-preview-panel,
.invoice-verification-panel {
    min-width: 0;
}

.invoice-preview-panel {
    position: sticky;
    top: 88px;
    height: calc(100vh - 128px);
    min-height: 720px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.invoice-preview-panel > .d-flex {
    flex: 0 0 auto;
}

.invoice-canvas-viewer {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #e9edf3;
}

.invoice-canvas-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.invoice-canvas-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.invoice-canvas-loading {
    margin: auto;
    color: var(--muted);
}

.invoice-canvas-page {
    max-width: 100%;
    background: #fff;
    border: 1px solid #cfd7e3;
    box-shadow: 0 10px 28px rgba(24, 34, 48, .16);
}

.invoice-canvas-page-label {
    padding: 4px 8px;
    border-bottom: 1px solid #e5eaf1;
    color: var(--muted);
    font-size: 11px;
    background: #f8fafc;
}

.invoice-canvas-page canvas {
    display: block;
    max-width: 100%;
    height: auto;
    background: #fff;
}

.invoice-pdf-frame {
    width: 100%;
    flex: 1 1 auto;
    min-height: 620px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}

.invoice-pdf-fallback[hidden] {
    display: none;
}

.invoice-preview-empty {
    flex: 1 1 auto;
    min-height: 420px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--line);
    border-radius: 6px;
    color: var(--muted);
    background: #f8fafc;
}

.invoice-verification-panel .form-label {
    margin-bottom: 4px;
}

.invoice-items-wrap {
    max-height: 42vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.invoice-items-table {
    min-width: 1530px;
    margin: 0;
}

.invoice-items-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
    }

    .app-sidebar {
        position: static;
        width: 100%;
        height: auto;
    }

    .app-main {
        width: 100%;
        margin-left: 0;
    }

    .app-header {
        position: static;
        padding: 14px 16px;
    }

    .content-wrap {
        padding: 16px;
    }

    .invoice-review-layout {
        grid-template-columns: 1fr;
    }

    .invoice-preview-panel {
        position: static;
        height: auto;
        min-height: 0;
    }

    .invoice-canvas-viewer {
        height: 560px;
        min-height: 420px;
    }

    .invoice-pdf-frame {
        height: 520px;
        min-height: 420px;
    }

    .invoice-items-wrap {
        max-height: none;
    }
}
