:root {
    color-scheme: light;
    --color-primary: #0b5cad;
    --color-primary-hover: #084a8d;
    --color-secondary: #128142;
    --color-bg: #eef3f8;
    --color-bg-soft: #e2eaf3;
    --color-surface: #ffffff;
    --color-surface-raised: #f7fafd;
    --color-sidebar: #ffffff;
    --color-border: #c5d1df;
    --color-border-strong: #8fa3b8;
    --color-text: #0f172a;
    --color-text-muted: #475569;
    --color-danger: #b91c1c;
    --color-warning: #a16207;
    --color-success: #15803d;
    --shadow-card: 0 12px 32px rgb(15 23 42 / 0.12);
    --radius-card: 1rem;
    --topbar-height: 4.5rem;
}

:root.dark {
    color-scheme: dark;
    --color-primary: #38bdf8;
    --color-primary-hover: #7dd3fc;
    --color-secondary: #34d399;
    --color-bg: #0b1120;
    --color-bg-soft: #111827;
    --color-surface: #111827;
    --color-surface-raised: #172033;
    --color-sidebar: #0f172a;
    --color-border: #263449;
    --color-border-strong: #334155;
    --color-text: #f8fafc;
    --color-text-muted: #a7b3c6;
    --color-danger: #fb7185;
    --color-warning: #fbbf24;
    --color-success: #34d399;
    --shadow-card: 0 18px 45px rgb(0 0 0 / 0.22);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) transparent;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top right, color-mix(in srgb, var(--color-primary) 10%, transparent), transparent 28%),
        linear-gradient(180deg, var(--color-bg) 0%, var(--color-bg-soft) 100%);
    color: var(--color-text);
    font-feature-settings: "tnum";
}

a,
button,
input,
select,
textarea,
summary {
    outline: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 28%, transparent);
}

.password-toggle-field input {
    padding-left: 3rem !important;
}

.password-toggle-button {
    align-items: center;
    background: transparent;
    border: 0;
    color: var(--color-text-muted);
    cursor: pointer;
    display: inline-flex;
    height: 2.25rem;
    justify-content: center;
    left: .45rem;
    padding: 0;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2.25rem;
}

.password-toggle-button:hover,
.password-toggle-button:focus-visible {
    color: var(--color-text);
}

.password-toggle-button svg {
    height: 1.15rem;
    width: 1.15rem;
}

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

.app-sidebar {
    position: fixed;
    inset-block: 0;
    right: 0;
    z-index: 70;
    display: flex;
    width: min(88vw, 22rem);
    max-width: calc(100vw - 1rem);
    flex-direction: column;
    border-left: 1px solid var(--color-border);
    background: color-mix(in srgb, var(--color-sidebar) 96%, transparent);
    padding: 1.25rem;
    box-shadow: var(--shadow-card);
    transform: translateX(105%);
    transition: transform .22s ease;
}

.sidebar-open,
.mobile-sidebar-open {
    overflow: hidden;
}

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

.app-sidebar-scroll {
    min-height: 0;
    overflow-y: auto;
    padding-left: .25rem;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: .85rem;
    border-radius: 1rem;
    border: 1px solid transparent;
    padding: .65rem;
    transition: background .2s ease, border-color .2s ease;
}

.brand-link:hover {
    border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.brand-logo {
    height: 3.25rem;
    width: 3.25rem;
    flex: none;
    border-radius: .9rem;
    object-fit: contain;
}

.brand-mark {
    display: grid;
    height: 3.25rem;
    width: 3.25rem;
    flex: none;
    place-items: center;
    border-radius: .9rem;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
    font-weight: 800;
}

.brand-eyebrow {
    color: var(--color-secondary);
    font-size: .82rem;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.brand-title {
    margin-top: .15rem;
    color: var(--color-text);
    font-size: 1.08rem;
    font-weight: 800;
}

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

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: var(--topbar-height);
    border-bottom: 1px solid var(--color-border);
    background: color-mix(in srgb, var(--color-surface) 88%, transparent);
    padding: 1rem clamp(1rem, 3vw, 2rem);
    backdrop-filter: blur(14px);
}

.app-content {
    padding: clamp(1rem, 3vw, 2rem);
}

.nav-section {
    border: 1px solid var(--color-border);
    background: color-mix(in srgb, var(--color-surface-raised) 88%, transparent);
    border-radius: 1rem;
    padding: .65rem;
}

.nav-section > summary {
    display: flex;
    cursor: pointer;
    list-style: none;
    align-items: center;
    justify-content: space-between;
    border-radius: .8rem;
    padding: .65rem .75rem;
    color: var(--color-text-muted);
    font-size: .94rem;
    font-weight: 800;
    letter-spacing: 0;
}

.nav-section > summary::-webkit-details-marker {
    display: none;
}

.nav-link {
    display: block;
    border-radius: .8rem;
    border: 1px solid transparent;
    padding: .78rem .9rem;
    color: var(--color-text);
    font-size: .98rem;
    font-weight: 700;
    transition: all .18s ease;
}

.nav-link:hover,
.nav-link:focus-visible {
    border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
    background: color-mix(in srgb, var(--color-primary) 8%, transparent);
    color: var(--color-primary);
}

.nav-link[aria-current="page"] {
    background: color-mix(in srgb, var(--color-primary) 12%, transparent);
    color: var(--color-primary);
}

.icon-button,
.theme-button,
.topbar-button {
    display: inline-grid;
    min-height: 2.5rem;
    min-width: 2.5rem;
    place-items: center;
    border-radius: .8rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface-raised);
    color: var(--color-text);
    padding: .5rem;
    font-size: .85rem;
    font-weight: 700;
    transition: border-color .2s ease, color .2s ease, background .2s ease;
}

.icon-button svg,
.theme-button svg,
.topbar-button svg {
    height: 1.15rem;
    width: 1.15rem;
}

.dark .theme-icon-moon,
.theme-icon-sun {
    display: none;
}

.dark .theme-icon-sun {
    display: block;
}

.icon-button:hover,
.theme-button:hover,
.topbar-button:hover {
    border-color: color-mix(in srgb, var(--color-primary) 45%, transparent);
    color: var(--color-primary);
}

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
    display: inline-flex;
    min-height: 2.5rem;
    align-items: center;
    justify-content: center;
    border-radius: .85rem;
    padding: .65rem 1rem;
    font-weight: 750;
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-secondary {
    background: var(--color-secondary);
    color: white;
}

.btn-danger {
    border: 1px solid color-mix(in srgb, var(--color-danger) 45%, transparent);
    color: var(--color-danger);
}

.btn-ghost {
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.ui-card,
.card,
article,
section.rounded-2xl,
section.rounded-3xl,
div.rounded-2xl,
div.rounded-3xl {
    border-color: var(--color-border);
}

.ui-input,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
input[type="file"],
select,
textarea {
    border-color: var(--color-border) !important;
    background: var(--color-surface) !important;
    color: var(--color-text) !important;
    min-height: 2.75rem;
}

input[type="file"] {
    direction: rtl;
    padding: .55rem .75rem;
}

input[type="file"]::file-selector-button {
    margin-left: .75rem;
    border: 0;
    border-radius: .7rem;
    background: var(--color-primary);
    color: white;
    padding: .55rem .85rem;
    font-weight: 800;
}

input:disabled,
select:disabled,
textarea:disabled,
input[readonly],
textarea[readonly] {
    background: color-mix(in srgb, var(--color-surface-raised) 80%, var(--color-border)) !important;
    color: var(--color-text-muted) !important;
    opacity: 1;
}

input::placeholder,
textarea::placeholder {
    color: var(--color-text-muted);
    opacity: 1;
}

label {
    color: var(--color-text);
}

.message {
    border-radius: 1rem;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    padding: .85rem 1rem;
}

.message-success {
    border-color: color-mix(in srgb, var(--color-success) 35%, transparent);
    background: color-mix(in srgb, var(--color-success) 10%, var(--color-surface));
}

.message-error {
    border-color: color-mix(in srgb, var(--color-danger) 35%, transparent);
    background: color-mix(in srgb, var(--color-danger) 10%, var(--color-surface));
}

.message-warning {
    border-color: color-mix(in srgb, var(--color-warning) 35%, transparent);
    background: color-mix(in srgb, var(--color-warning) 12%, var(--color-surface));
}

.notification-menu {
    background: var(--color-surface);
    border-color: var(--color-border);
    box-shadow: var(--shadow-card);
    color: var(--color-text);
}

.notification-item {
    border-color: var(--color-border);
}

.notification-unread {
    background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    background: rgb(15 23 42 / .55);
    backdrop-filter: blur(2px);
}

.sidebar-open .sidebar-backdrop,
.mobile-sidebar-open .sidebar-backdrop {
    display: block;
}

.table-card {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.responsive-table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    touch-action: pan-x pan-y;
}

.responsive-table-scroll table {
    width: max-content;
    min-width: var(--table-min-width, 52rem);
    max-width: none;
}

.responsive-table-scroll table.table-compact {
    --table-min-width: 44rem;
}

.responsive-table-scroll table.table-medium {
    --table-min-width: 64rem;
}

.responsive-table-scroll table.table-wide {
    --table-min-width: 86rem;
}

/* Supplier ledger: preserve its mobile scrolling layout while allowing the
   notes cell to absorb the available desktop card width. */
.supplier-ledger-table {
    min-width: 760px;
}

@media (min-width: 1200px) {
    .supplier-ledger-wrap {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .supplier-ledger-table {
        width: 100%;
        min-width: 100%;
        table-layout: auto;
    }

    .supplier-ledger-table .supplier-ledger-date,
    .supplier-ledger-table .supplier-ledger-reference,
    .supplier-ledger-table .supplier-ledger-amount,
    .supplier-ledger-table .supplier-ledger-action {
        width: 1%;
        white-space: nowrap;
    }

    .supplier-ledger-table .supplier-ledger-amount {
        direction: ltr;
        unicode-bidi: plaintext;
    }

    .supplier-ledger-table .supplier-ledger-notes {
        width: 100%;
        min-width: 16rem;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .supplier-ledger-table .supplier-ledger-action-links {
        white-space: nowrap;
    }
}

.form-page-container {
    width: 100%;
    max-width: 1280px;
    margin-inline: auto;
}

.form-page-container-narrow {
    width: 100%;
    max-width: 1024px;
    margin-inline: auto;
}

@media (min-width: 1024px) {
    .responsive-table-scroll table,
    .responsive-table-scroll table.table-compact,
    .responsive-table-scroll table.table-medium,
    .responsive-table-scroll table.table-wide {
        width: 100%;
        min-width: 100%;
    }
}

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

    .app-content {
        padding: 1rem;
    }

    .app-topbar {
        padding: .85rem 1rem;
    }

    table {
        font-size: .82rem;
    }

    th,
    td {
        white-space: nowrap;
    }
}

@media (max-width: 640px) {
    .app-topbar h2 {
        font-size: 1rem;
    }

    .app-topbar form {
        margin: 0;
    }

    .notification-menu {
        position: fixed !important;
        top: calc(var(--topbar-height) + .5rem) !important;
        right: .75rem !important;
        left: .75rem !important;
        width: auto !important;
        max-width: none !important;
        max-height: calc(100vh - var(--topbar-height) - 1.5rem);
        overflow: hidden;
    }

    .notification-menu-body {
        max-height: calc(100vh - var(--topbar-height) - 8rem);
        overflow-y: auto;
    }
}

@media (max-width: 639px) {
    .mobile-stack {
        min-width: 0 !important;
    }

    .mobile-stack thead {
        display: none;
    }

    .mobile-stack tbody {
        display: block;
    }

    .mobile-stack tr {
        display: grid;
        gap: .55rem;
        border-bottom: 1px solid var(--color-border);
        padding: .9rem;
    }

    .mobile-stack tr:last-child {
        border-bottom: 0;
    }

    .mobile-stack td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        white-space: normal;
        padding: 0 !important;
        text-align: start;
    }

    .mobile-stack td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 7.5rem;
        color: var(--color-text-muted);
        font-size: .78rem;
        font-weight: 800;
    }

    .mobile-stack td[colspan] {
        display: block;
        text-align: center;
    }

    .mobile-stack td[colspan]::before {
        content: "";
        display: none;
    }

    .mobile-stack input,
    .mobile-stack select,
    .mobile-stack button,
    .mobile-stack a {
        max-width: 100%;
    }
}

@media screen {
    html:not(.dark) body [class*="bg-slate-950"],
    html:not(.dark) body [class*="bg-slate-900"],
    html:not(.dark) body [class*="bg-slate-800"] {
        background-color: var(--color-surface) !important;
    }

    html:not(.dark) body [class*="border-slate-800"],
    html:not(.dark) body [class*="border-slate-700"],
    html:not(.dark) body [class*="border-slate-600"] {
        border-color: var(--color-border) !important;
    }

    html:not(.dark) body .text-white,
    html:not(.dark) body [class*="text-slate-100"],
    html:not(.dark) body [class*="text-slate-200"],
    html:not(.dark) body [class*="text-slate-300"] {
        color: var(--color-text) !important;
    }

    html:not(.dark) body [class*="text-slate-400"],
    html:not(.dark) body [class*="text-slate-500"],
    html:not(.dark) body [class*="text-slate-600"] {
        color: var(--color-text-muted) !important;
    }

    html:not(.dark) body thead[class*="bg-slate"] {
        background-color: var(--color-surface-raised) !important;
    }

    html:not(.dark) body [class*="text-emerald-200"],
    html:not(.dark) body [class*="text-emerald-300"] {
        color: #047857 !important;
    }

    html:not(.dark) body [class*="text-amber-200"],
    html:not(.dark) body [class*="text-amber-300"] {
        color: #92400e !important;
    }

    html:not(.dark) body [class*="text-rose-200"],
    html:not(.dark) body [class*="text-rose-300"] {
        color: #be123c !important;
    }
}

.statement-table-wrap {
    overflow-x: auto;
}

.statement-ledger-table th,
.statement-date,
.statement-value,
.statement-effect,
.statement-balance,
.statement-reference {
    white-space: nowrap;
}

.statement-notes {
    min-width: 15rem;
    white-space: normal;
}

.statement-branch {
    min-width: 8rem;
    white-space: normal;
}

@media print {
    :root {
        color-scheme: light;
    }

    body {
        background: white !important;
        color: #111827 !important;
    }

    .app-sidebar,
    .app-topbar,
    .sidebar-backdrop {
        display: none !important;
    }
}
