:root {
    --accent: #f97316;
    --accent-dark: #ea580c;
    --accent-soft: #fff7ed;
    --accent-ring: rgba(249, 115, 22, .18);
    --sidebar-bg: rgba(255,255,255,.86);
    --body-bg: #f4f6fa;
    --panel: #ffffff;
    --line: #e7ebf2;
    --text: #172033;
    --muted: #6b7280;
}

body.theme-blue { --accent: #0ea5e9; --accent-dark: #0284c7; --accent-soft: #eff6ff; --accent-ring: rgba(14,165,233,.18); }
body.theme-green { --accent: #16a34a; --accent-dark: #15803d; --accent-soft: #f0fdf4; --accent-ring: rgba(22,163,74,.18); }
body.theme-purple { --accent: #7c3aed; --accent-dark: #6d28d9; --accent-soft: #f5f3ff; --accent-ring: rgba(124,58,237,.18); }

* { letter-spacing: 0; }

body {
    background:
        radial-gradient(circle at 82% 8%, var(--accent-soft), transparent 28rem),
        linear-gradient(180deg, #fff 0, var(--body-bg) 18rem);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, sans-serif;
}

body.sidebar-lock {
    overflow: hidden;
}

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

.sidebar {
    width: 270px;
    background: var(--sidebar-bg);
    border-right: 1px solid rgba(231,235,242,.9);
    padding: 18px;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    gap: 22px;
    z-index: 10;
    backdrop-filter: blur(16px);
    box-shadow: 12px 0 32px rgba(15, 23, 42, .04);
    overflow-y: auto;
    overflow-x: hidden;
    transition: width .2s ease, transform .2s ease;
    scrollbar-width: thin;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-system {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255,255,255,.72);
}

.sidebar-nav {
    flex: 1 0 auto;
}

.sidebar-backdrop {
    display: none;
}

.mobile-sidebar-button {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 30;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--accent-dark);
    box-shadow: 0 10px 24px rgba(15, 23, 42, .12);
}

.brand {
    color: var(--text);
    text-decoration: none;
    font-weight: 800;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    box-shadow: 0 10px 22px var(--accent-ring);
}

.sidebar .nav-link {
    color: #566173;
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    font-weight: 600;
    transition: transform .15s ease, background .15s ease, color .15s ease;
}

.sidebar .nav-link i {
    width: 20px;
    text-align: center;
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
    color: var(--accent-dark);
    background: var(--accent-soft);
    transform: translateX(2px);
}

.logout-link {
    margin-top: auto;
    color: #9a3412;
    text-decoration: none;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
}

.logout-link:hover {
    background: #fff1f2;
}

.app-main {
    margin-left: 270px;
    width: calc(100% - 270px);
    min-height: 100vh;
    transition: margin-left .2s ease, width .2s ease;
}

.topbar {
    min-height: 70px;
    background: rgba(255,255,255,.78);
    border-bottom: 1px solid rgba(231,235,242,.9);
    backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 26px;
    position: sticky;
    top: 0;
    z-index: 8;
}

body.sidebar-collapsed .sidebar {
    width: 82px;
    padding: 14px 12px;
}

body.sidebar-collapsed .app-main {
    margin-left: 82px;
    width: calc(100% - 82px);
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .sidebar-system,
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .logout-link span {
    display: none;
}

body.sidebar-collapsed .sidebar-head {
    justify-content: center;
    flex-direction: column;
}

body.sidebar-collapsed .sidebar .nav-link,
body.sidebar-collapsed .logout-link {
    justify-content: center;
}

.topbar-title {
    min-width: 0;
}

.content-wrap {
    padding: 24px;
}

.app-credit {
    margin-top: 24px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--accent-dark);
    background:
        linear-gradient(135deg, rgba(255,255,255,.92), rgba(255,255,255,.78)),
        linear-gradient(135deg, var(--accent-soft), #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700;
    text-align: center;
}

.app-credit i {
    color: var(--accent);
}

.page-hero {
    min-height: 132px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    padding: 24px;
    border-radius: 14px;
    background:
        linear-gradient(135deg, rgba(255,255,255,.96), rgba(255,255,255,.74)),
        linear-gradient(135deg, var(--accent-soft), #fff);
    border: 1px solid rgba(255,255,255,.9);
    box-shadow: 0 16px 40px rgba(15, 23, 42, .08);
}

.page-hero h1 {
    font-size: clamp(1.45rem, 2vw, 2.05rem);
    line-height: 1.25;
    margin: 4px 0 0;
    font-weight: 800;
}

.eyebrow {
    color: var(--accent-dark);
    font-size: .78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.page-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.theme-select {
    width: 132px;
}

.theme-toggle {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.theme-chip {
    height: 32px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border .15s ease, box-shadow .15s ease, transform .15s ease;
}

.theme-chip.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
    transform: translateY(-1px);
}

.theme-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
}

.dot-orange { background: #f97316; }
.dot-blue { background: #0ea5e9; }
.dot-green { background: #16a34a; }
.dot-purple { background: #7c3aed; }

.icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
}

.card-soft {
    border: 1px solid rgba(231,235,242,.86);
    border-radius: 12px;
    box-shadow: 0 14px 34px rgba(15, 23, 42, .07);
    overflow: hidden;
}

.card-soft > .card-header {
    border-bottom: 1px solid var(--line);
    min-height: 50px;
    display: flex;
    align-items: center;
}

.kpi-card {
    position: relative;
    overflow: hidden;
    transition: transform .18s ease, box-shadow .18s ease;
}

.kpi-card:after {
    content: "";
    position: absolute;
    inset: auto -24px -48px auto;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: var(--accent-soft);
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 20px 40px rgba(15, 23, 42, .1);
}

.metric-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.btn-primary,
.btn-primary:focus {
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent-dark);
    --bs-btn-hover-border-color: var(--accent-dark);
    --bs-btn-focus-shadow-rgb: 249, 115, 22;
}

.btn-outline-light {
    color: var(--accent-dark);
    border-color: rgba(234,88,12,.2);
    background: rgba(255,255,255,.65);
}

.btn-outline-light:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.table {
    --bs-table-hover-bg: var(--accent-soft);
}

.table thead th {
    color: #566173;
    font-size: .78rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    background: #fafbfc;
}

.table tbody tr {
    transition: background .15s ease;
}

.table tbody td {
    border-color: #eef1f6;
}

.dataTables_wrapper {
    padding: 14px;
}

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

.tab-pane .dataTables_wrapper {
    width: 100%;
}

.dataTables_wrapper .row:first-child {
    align-items: center;
    row-gap: 10px;
    margin-bottom: 8px;
}

.dataTables_filter input,
.dataTables_length select {
    border-radius: 10px;
    border-color: var(--line);
}

.page-item.active .page-link {
    background: var(--accent);
    border-color: var(--accent);
}

.page-link {
    color: var(--accent-dark);
}

.dtr-details {
    width: 100%;
}

.chart-card {
    min-height: 380px;
}

.donut-wrap {
    position: relative;
    max-width: 300px;
    margin: 0 auto;
    aspect-ratio: 1;
}

.donut-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.donut-percent {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent-dark);
}

.mini-donut-wrap {
    width: 118px;
    min-width: 118px;
    max-width: 118px;
    height: 118px;
    min-height: 118px;
    margin: 0;
}

.mini-donut-wrap .donut-percent {
    font-size: 1rem;
}

.mini-stat {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    background: #fff;
}

.mini-stat strong {
    font-size: 1.4rem;
    color: var(--accent-dark);
}

.bar-chart {
    min-height: 310px;
}

.nav-tabs {
    border-bottom: 0;
    gap: 8px;
}

.nav-tabs .nav-link,
.nav-pills .nav-link {
    border: 1px solid var(--line);
    color: #566173;
    border-radius: 10px;
    font-weight: 700;
    background: #fff;
}

.nav-tabs .nav-link.active,
.nav-pills .nav-link.active {
    color: var(--accent-dark);
    background: var(--accent-soft);
    border-color: transparent;
}

.action-tabs {
    padding: 8px;
    background: rgba(255,255,255,.68);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.text-bg-orange {
    color: #fff !important;
    background: var(--accent) !important;
}

.text-bg-purple {
    color: #fff !important;
    background: #7c3aed !important;
}

.timeline {
    position: relative;
    padding-left: 28px;
}

.timeline:before {
    content: "";
    position: absolute;
    left: 8px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: #e5e7eb;
}

.timeline-item {
    position: relative;
    margin-bottom: 18px;
    padding: 12px 12px 12px 14px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #eef1f6;
}

.timeline-item:before {
    content: "";
    position: absolute;
    left: -25px;
    top: 16px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.timeline-item.timeline-muted {
    color: #374151;
    background: #f8fafc;
    border-color: #d1d5db;
    filter: grayscale(1);
}

.timeline-item.timeline-muted:before {
    background: #6b7280;
    box-shadow: 0 0 0 4px #e5e7eb;
}

.timeline-item.timeline-muted .badge {
    color: #111827 !important;
    background: #e5e7eb !important;
}

.file-link {
    word-break: break-word;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.quick-tile {
    min-height: 92px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #fff;
    font-weight: 700;
}

.quick-tile i {
    font-size: 1.5rem;
    color: var(--accent-dark);
}

.quick-tile:hover {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 20% 20%, var(--accent-soft), transparent 28rem),
        linear-gradient(135deg, #fff, #f7f8fb);
    padding: 24px;
}

.login-card {
    max-width: 420px;
    width: 100%;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 .2rem var(--accent-ring);
}

.smart-suggest-wrap {
    position: relative;
}

.smart-suggest-menu {
    position: absolute;
    z-index: 25;
    inset: calc(100% + 8px) 0 auto 0;
    display: none;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
    border-radius: 12px;
    background: rgba(255,255,255,.96);
    box-shadow: 0 18px 42px rgba(15, 23, 42, .16);
    backdrop-filter: blur(12px);
}

.smart-suggest-menu.open {
    display: grid;
}

.smart-suggest-card {
    width: 100%;
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text);
    background:
        linear-gradient(135deg, rgba(255,255,255,.92), rgba(255,255,255,.76)),
        linear-gradient(135deg, var(--accent-soft), #fff);
    text-align: left;
    transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease;
}

.smart-suggest-card:hover,
.smart-suggest-card:focus {
    border-color: var(--accent);
    box-shadow: 0 10px 22px var(--accent-ring);
    transform: translateY(-1px);
    outline: 0;
}

.smart-suggest-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}

.smart-suggest-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.smart-suggest-title {
    font-weight: 800;
    line-height: 1.25;
    word-break: break-word;
}

.smart-suggest-meta {
    color: var(--accent-dark);
    font-size: .86rem;
    font-weight: 700;
    line-height: 1.25;
    word-break: break-word;
}

.ocr-mini-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.ocr-mini-card .card-header {
    gap: 12px;
    align-items: flex-start;
}

.ocr-result-list {
    padding: 16px;
    background: #f8fafc;
}

.ocr-result-list #ocrMiniRows {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.ocr-result-item {
    display: flex;
    flex-direction: column;
    gap: 9px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .05);
}

.ocr-result-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.ocr-result-label {
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.ocr-result-control {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.ocr-result-item .form-control {
    min-height: 42px;
    font-size: 1rem;
}

.ocr-result-item .btn {
    min-height: 42px;
    white-space: nowrap;
    flex: 0 0 auto;
}

.ocr-applied {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 .22rem var(--accent-ring) !important;
}

.procurement-panel {
    max-width: 920px;
    margin: 0 auto;
}

.procurement-head {
    gap: 12px;
}

.procurement-list {
    display: grid;
    gap: 12px;
}

.procurement-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: stretch;
}

.procurement-check-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 72px;
    padding: 14px;
    border: 1px solid rgba(124, 58, 237, .22);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .05);
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease, transform .15s ease;
}

.procurement-check-card:hover {
    border-color: var(--accent);
    box-shadow: 0 14px 28px rgba(15, 23, 42, .08);
    transform: translateY(-1px);
}

.procurement-check-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.procurement-check-box {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #dbe2ea;
    border-radius: 6px;
    background: #fff;
    color: #fff;
    font-size: 1rem;
    box-shadow: inset 0 0 0 2px #fff;
}

.procurement-check-input:checked + .procurement-check-box {
    background: var(--accent);
    border-color: var(--accent);
}

.procurement-check-input:focus + .procurement-check-box {
    box-shadow: 0 0 0 4px var(--accent-ring);
}

.procurement-check-card:has(.procurement-check-input:checked) {
    border-color: var(--accent);
    background: linear-gradient(180deg, var(--accent-soft), #fff);
}

.procurement-check-card strong {
    display: block;
    font-size: 1.12rem;
    color: #0f172a;
}

.procurement-check-card small {
    display: block;
    color: var(--muted);
    margin-top: 2px;
}

.procurement-check-all {
    min-height: 58px;
}

.procurement-detail-btn {
    min-width: 110px;
    border-radius: 10px;
}

.procurement-sticky-action {
    position: sticky;
    bottom: 0;
    z-index: 2;
    box-shadow: 0 -10px 22px rgba(15, 23, 42, .06);
}

.procurement-mobile-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 82% 8%, var(--accent-soft), transparent 28rem),
        linear-gradient(180deg, #fff 0, var(--body-bg) 18rem);
}

.procurement-mobile-wrap {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 16px;
}

.procurement-mobile-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.procurement-mobile-title h1 {
    font-size: 1.45rem;
    line-height: 1.25;
    margin: 0;
    font-weight: 800;
}

.mini-detail-table th {
    width: 170px;
    color: var(--muted);
    font-weight: 700;
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
    }
    .sidebar {
        width: min(86vw, 320px);
        position: fixed;
        border-right: 1px solid #e9edf3;
        border-bottom: 0;
        transform: translateX(-105%);
        max-height: 100vh;
        padding-top: 18px;
    }
    .sidebar .nav {
        display: flex;
    }
    .logout-link {
        margin-top: 0;
    }
    .app-main {
        margin-left: 0;
        width: 100%;
    }
    .mobile-sidebar-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    body.sidebar-open .mobile-sidebar-button {
        display: none;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    body.sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.38);
        z-index: 9;
    }
    .content-wrap {
        padding: 72px 16px 16px;
    }
    .page-hero {
        align-items: flex-start;
        flex-direction: column;
    }
    .page-hero-actions {
        justify-content: flex-start;
    }
    .ocr-mini-card .card-header {
        align-items: stretch;
        flex-direction: column;
    }
    .ocr-mini-card .card-header .btn {
        width: 100%;
        min-height: 44px;
    }
    .ocr-result-list {
        padding: 10px;
    }
    .ocr-result-list #ocrMiniRows {
        grid-template-columns: 1fr;
    }
    .ocr-result-item {
        padding: 12px;
    }
    .ocr-result-label {
        font-size: 1rem;
    }
    .ocr-result-control {
        flex-direction: column;
    }
    .ocr-result-item .form-control,
    .ocr-result-item .btn {
        width: 100%;
        min-height: 46px;
        font-size: 1rem;
    }
    .procurement-panel {
        border-radius: 10px;
    }
    .procurement-head {
        align-items: flex-start;
    }
    .procurement-item {
        grid-template-columns: 1fr;
    }
    .procurement-check-card {
        min-height: 78px;
        padding: 14px;
    }
    .procurement-detail-btn {
        width: 100%;
        min-height: 44px;
    }
    .mini-detail-table th,
    .mini-detail-table td {
        display: block;
        width: 100%;
    }
    .mini-detail-table th {
        border-bottom: 0;
        padding-bottom: 2px;
    }
    .mini-detail-table td {
        padding-top: 2px;
    }
}
