:root {
    --bg: #f4f7f3;
    --surface: #ffffff;
    --surface-soft: #eef4ed;
    --surface-muted: #f8faf8;
    --text: #173026;
    --text-muted: #62756a;
    --border: rgba(23, 48, 38, 0.12);
    --primary: #0f8c6a;
    --primary-dark: #0b6a50;
    --accent: #d89333;
    --danger: #d14c4c;
    --shadow: 0 18px 36px rgba(13, 30, 24, 0.08);
    --radius: 8px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Manrope', sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(216, 147, 51, 0.14), transparent 24%),
        radial-gradient(circle at top right, rgba(15, 140, 106, 0.16), transparent 28%),
        linear-gradient(180deg, #f9fcfa 0%, var(--bg) 100%);
}

body.page-dashboard {
    background: #eef4ed;
}

a {
    color: inherit;
}

.btn,
.form-control,
.form-select,
.input-group-text,
.modal-content,
.alert,
.surface,
.metric-card,
.auth-panel,
.setup-card,
.sidebar,
.user-badge,
.branch-chip {
    border-radius: var(--radius);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #14a078 100%);
    border-color: transparent;
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    border-color: transparent;
}

.btn-outline-primary {
    color: var(--primary-dark);
    border-color: rgba(15, 140, 106, 0.35);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: rgba(15, 140, 106, 0.1);
    color: var(--primary-dark);
    border-color: rgba(15, 140, 106, 0.45);
}

.btn-light {
    color: #0d2f25;
    border-color: rgba(255, 255, 255, 0.75);
    font-weight: 700;
}

.btn-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.form-control,
.form-select,
.input-group-text {
    min-height: 48px;
    border-color: var(--border);
    background: #fff;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(15, 140, 106, 0.35);
    box-shadow: 0 0 0 0.2rem rgba(15, 140, 106, 0.12);
}

.page-login,
.page-install {
    overflow-x: hidden;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 16px;
}

.auth-panel {
    width: min(100%, 520px);
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: var(--shadow);
    padding: 32px;
}

.install-panel {
    width: min(100%, 980px);
}

.auth-brand {
    margin-bottom: 28px;
}

.auth-brand h1 {
    margin: 8px 0 10px;
    font-size: clamp(2rem, 5vw, 2.6rem);
    font-weight: 800;
    line-height: 1.05;
}

.auth-brand p,
.auth-note,
.form-hint,
.upload-rule,
.section-eyebrow,
.brand-kicker,
.metric-card small,
.setup-step p {
    color: var(--text-muted);
}

.brand-kicker,
.section-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0;
    font-size: 0.76rem;
    font-weight: 800;
}

.auth-form .btn {
    min-height: 52px;
}

.auth-note {
    margin: 16px 0 0;
    font-size: 0.92rem;
}

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

.setup-card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 22px;
}

.setup-step {
    display: flex;
    gap: 16px;
    margin-bottom: 18px;
}

.setup-step h2 {
    margin: 0 0 6px;
    font-size: 1.1rem;
    font-weight: 800;
}

.step-number {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(15, 140, 106, 0.18), rgba(216, 147, 51, 0.18));
    color: var(--primary-dark);
    font-weight: 800;
    border-radius: 50%;
}

.floating-flash,
.toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1080;
}

.toast-stack {
    display: grid;
    gap: 10px;
}

.app-toast {
    width: min(360px, calc(100vw - 32px));
    background: #ffffff;
    border: 1px solid rgba(23, 48, 38, 0.16);
    box-shadow: 0 16px 34px rgba(13, 30, 24, 0.16);
    padding: 14px 16px;
    animation: slideIn 0.25s ease;
}

.app-toast.is-success {
    border-left: 4px solid var(--primary);
}

.app-toast.is-danger {
    border-left: 4px solid var(--danger);
}

.app-toast.is-warning {
    border-left: 4px solid var(--accent);
}

.app-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.app-shell > .sidebar,
.app-shell > .sidebar.offcanvas,
.app-shell > .sidebar.offcanvas-lg {
    --bs-offcanvas-bg: #102e24;
    --bs-offcanvas-color: #ffffff;
    background-color: #102e24 !important;
    background-image: none !important;
    color: #ffffff !important;
    padding: 22px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar .offcanvas-body {
    background: #102e24;
    color: #ffffff;
}

.sidebar .brand-kicker,
.sidebar .sidebar-title,
.sidebar .branch-chip,
.sidebar .branch-chip strong {
    color: #ffffff !important;
}

.sidebar-title {
    font-size: 1.2rem;
    margin: 10px 0 0;
    font-weight: 800;
}

.branch-chip {
    background: #173f32 !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 14px 16px;
    margin: 18px 0 22px;
}

.branch-label {
    display: block;
    font-size: 0.76rem;
    color: #dceee6 !important;
    margin-bottom: 6px;
}

.sidebar-nav {
    gap: 8px;
}

.sidebar-nav .nav-link {
    background: transparent !important;
    color: #dceee6 !important;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    border-radius: var(--radius);
}

.sidebar-nav .nav-link.active,
.sidebar-nav .nav-link:hover {
    background: #ffffff !important;
    color: #102e24 !important;
}

.sidebar-nav .nav-link.active i,
.sidebar-nav .nav-link:hover i {
    color: var(--primary-dark);
}

.sidebar-nav .nav-link:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.main-panel {
    min-width: 0;
    background: #eef4ed;
}

.topbar .brand-kicker {
    color: #fff;
}

.topbar .btn-outline-light {
    border-color: rgba(255, 255, 255, 0.65);
    color: #ffffff;
}

.topbar {
    background: linear-gradient(135deg, #087756 0%, #123c31 100%);
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.topbar h1 {
    margin: 4px 0 0;
    font-size: clamp(1.25rem, 2vw, 1.75rem);
    font-weight: 800;
}

.topbar-left,
.topbar-right,
.surface-header,
.hero-band,
.toolbar,
.metric-card,
.empty-state-cell,
.action-group {
    display: flex;
    align-items: center;
}

.topbar-left,
.topbar-right {
    gap: 14px;
}

.user-badge {
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 10px 14px;
    text-align: right;
    color: #ffffff;
}

.user-badge span {
    display: block;
    font-size: 0.72rem;
    color: #dceee6;
}

.content-area {
    padding: 24px;
}

.hero-band {
    justify-content: space-between;
    gap: 16px;
    padding: 22px 26px;
    margin-bottom: 22px;
    background: #ffffff;
    border: 1px solid rgba(23, 48, 38, 0.08);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}

.hero-band h2 {
    margin: 8px 0 0;
    font-size: clamp(1.25rem, 2vw, 1.8rem);
    font-weight: 800;
    max-width: 720px;
}

.hero-meta {
    display: grid;
    gap: 10px;
    justify-items: end;
    color: var(--text-muted);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.metric-card {
    min-height: 150px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px;
}

.metric-card strong {
    font-size: clamp(2rem, 4vw, 2.8rem);
    line-height: 1;
    font-weight: 800;
}

.metric-card-muted {
    background: linear-gradient(135deg, rgba(216, 147, 51, 0.12), rgba(15, 140, 106, 0.12));
}

.surface {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 22px;
}

.surface-header {
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.surface-header h3 {
    margin: 8px 0 0;
    font-size: 1.2rem;
    font-weight: 800;
}

.surface-actions,
.toolbar,
.action-group {
    gap: 10px;
}

.toolbar {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.toolbar .form-control,
.toolbar .form-select {
    min-width: 240px;
}

.toolbar #invoice-format-filter,
.toolbar #invoice-per-page {
    min-width: 145px;
}

.toolbar #invoice-date-from,
.toolbar #invoice-date-to {
    min-width: 160px;
}

#invoice-search,
#user-search {
    background-color: #ffffff;
    border-color: rgba(15, 140, 106, 0.35);
    color: var(--text);
}

#invoice-search::placeholder,
#user-search::placeholder {
    color: #6f8077;
}

.table-app {
    min-width: 760px;
}

.table-app thead th {
    color: var(--text-muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0;
    font-weight: 800;
    border-bottom-width: 1px;
    padding: 14px 12px;
}

.sort-header {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    text-transform: uppercase;
    font: inherit;
    font-weight: 800;
}

.sort-header:hover,
.sort-header:focus,
.sort-header.is-active {
    color: var(--primary-dark);
}

.sort-header:focus-visible {
    outline: 2px solid rgba(15, 140, 106, 0.3);
    outline-offset: 3px;
}

.sort-indicator {
    color: var(--primary-dark);
    font-size: 0.68rem;
}

.table-app td {
    padding: 14px 12px;
    vertical-align: middle;
}

.table-app tbody tr:hover {
    background: rgba(15, 140, 106, 0.03);
}

.serial-cell {
    width: 64px;
    color: var(--text-muted);
    font-weight: 800;
    white-space: nowrap;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 16px;
}

.pagination-summary,
.page-status {
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 700;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.empty-state-cell {
    justify-content: center;
    color: var(--text-muted);
    min-height: 140px;
    text-align: center;
}

.invoice-title,
.user-title {
    display: grid;
    gap: 4px;
}

.invoice-title strong,
.user-title strong {
    font-weight: 700;
}

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

.badge-soft {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0 12px;
    background: rgba(15, 140, 106, 0.1);
    color: var(--primary-dark);
    font-weight: 700;
    border-radius: 999px;
}

.badge-soft.is-danger {
    background: rgba(209, 76, 76, 0.12);
    color: #8f2d2d;
}

.app-alert {
    margin-bottom: 18px;
}

.modal-content {
    border: 0;
    box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
    border-color: var(--border);
}

code {
    background: rgba(15, 140, 106, 0.08);
    color: var(--primary-dark);
    padding: 2px 6px;
    border-radius: 4px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1199.98px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 991.98px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        padding: 18px;
        width: min(84vw, 300px);
    }

    .topbar,
    .hero-band,
    .surface-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-right,
    .toolbar {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-right {
        align-items: stretch;
    }

    .topbar-right .btn {
        min-height: 48px;
    }

    .hero-meta {
        justify-items: start;
    }
}

@media (max-width: 767.98px) {
    .auth-panel,
    .surface,
    .setup-card {
        padding: 18px;
    }

    .content-area {
        padding: 14px;
    }

    .stats-grid,
    .setup-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .toolbar .form-control,
    .toolbar .form-select,
    .toolbar .btn,
    .surface-actions,
    .surface-actions .btn {
        width: 100%;
    }

    .table-footer,
    .pagination-controls {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .pagination-controls .btn {
        width: 100%;
    }

    .table-app {
        min-width: 680px;
    }

    .topbar {
        padding: 16px;
    }

    .topbar-left,
    .topbar-right {
        width: 100%;
    }

    .topbar-left {
        align-items: flex-start;
    }

    .topbar-right {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .user-badge {
        text-align: left;
        min-width: 0;
    }

    .hero-band {
        padding: 18px;
    }

    .hero-band h2 {
        font-size: 1.28rem;
        line-height: 1.22;
    }

    .toast-stack {
        left: 16px;
        right: 16px;
    }

    .app-toast {
        width: 100%;
    }
}
