:root {
    --sidebar-width: 260px;

    /* Light theme (default) - match sample UI */
    /* Logo colors (Softnomic) */
    --primary: #278ffe;        /* main blue */
    --primary-dark: #0b6bd6;   /* darker blue */
    --accent: #0bb1ff;         /* cyan-ish */
    --primary-rgb: 39, 143, 254;

    /* Bootstrap primary mapping (so bg-primary + bg-opacity-* works) */
    --bs-primary: var(--primary);
    --bs-primary-rgb: var(--primary-rgb);

    --surface: #f5f6ff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e7e9f5;
    --card-bg: #ffffff;
    --table-head-bg: #f4f6ff;
    --card-shadow: 0 18px 40px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.05);

    --sidebar-bg: #ffffff;
    --sidebar-border: rgba(15, 23, 42, 0.08);
    --sidebar-text: #334155;
    --sidebar-muted: #94a3b8;
    --sidebar-hover-bg: rgba(39, 143, 254, 0.10);
    --sidebar-active-bg: rgba(39, 143, 254, 0.14);
    --sidebar-active-pill: var(--primary);

    --topbar-bg: rgba(255, 255, 255, 0.9);

    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;

    --radius: 0.95rem;

    /* Global spacing (reduce extra padding) */
    --page-padding: 1.25rem;
    --topbar-padding-y: 0.85rem;
    --topbar-padding-x: 1.25rem;
    --card-header-padding-y: 1rem;
    --card-header-padding-x: 1.25rem;
    --card-body-padding: 1.25rem;
    --table-cell-y: 0.72rem;
    --table-cell-x: 0.95rem;
}

/* Dark theme variables */
[data-theme="dark"] {
    --surface: #0b1220;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.18);
    --card-bg: #0f172a;
    --table-head-bg: rgba(148, 163, 184, 0.08);
    --card-shadow: 0 18px 40px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.2);

    --sidebar-bg: linear-gradient(180deg, #0b1220 0%, #111c33 100%);
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-text: #e2e8f0;
    --sidebar-muted: #64748b;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.07);
    --sidebar-active-bg: rgba(39, 143, 254, 0.30);
    --sidebar-active-pill: var(--primary);

    --topbar-bg: rgba(15, 23, 42, 0.72);
    --bs-primary: var(--primary);
    --bs-primary-rgb: var(--primary-rgb);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--surface);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
}

/* Sidebar collapse state (desktop) */
body.sidebar-collapsed {
    --sidebar-width: 78px;
}

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease, width 0.2s ease;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.brand-text {
    line-height: 1.1;
}
.brand-client {
    font-weight: 800;
    letter-spacing: -0.02em;
    font-size: 1.05rem;
}
.brand-sub {
    margin-top: 0.15rem;
    font-size: 0.75rem;
    color: var(--sidebar-muted);
    font-weight: 500;
}

.sidebar-brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    color: var(--sidebar-text);
    letter-spacing: -0.02em;
}

.sidebar-brand span {
    font-size: 0.75rem;
    color: var(--sidebar-muted);
    display: block;
    margin-top: 0.25rem;
}

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

.nav-section {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-muted);
    padding: 0.75rem 0.75rem 0.35rem;
    font-weight: 600;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.15rem;
    transition: all 0.15s ease;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text);
}

.sidebar-nav a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text);
    position: relative;
    overflow: hidden;
}

.sidebar-nav a.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 4px;
    border-radius: 999px;
    background: var(--sidebar-active-pill);
}

.sidebar-nav a i {
    font-size: 1.1rem;
    width: 1.25rem;
    text-align: center;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    transition: margin-left 0.2s ease;
}

body.sidebar-collapsed .sidebar-brand {
    padding: 1.25rem 0.75rem;
    text-align: center;
}
body.sidebar-collapsed .sidebar-brand h1 {
    font-size: 0;
}
body.sidebar-collapsed .brand-logo {
    justify-content: center;
}
body.sidebar-collapsed .brand-text {
    display: none;
}
body.sidebar-collapsed .sidebar-brand span {
    display: none;
}
body.sidebar-collapsed .nav-section {
    display: none;
}
body.sidebar-collapsed .sidebar-nav {
    padding: 1rem 0.5rem;
}
body.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    gap: 0;
    padding: 0.75rem;
    font-size: 0; /* hides text nodes */
}
body.sidebar-collapsed .sidebar-nav a i {
    width: auto;
    font-size: 1.15rem;
}

.topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    padding: var(--topbar-padding-y) var(--topbar-padding-x);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.topbar-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.page-body {
    padding: var(--page-padding);
}

.app-footer {
    padding: 0 0 var(--page-padding);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.app-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.app-footer a:hover {
    text-decoration: underline;
}

.card-panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.card-panel .card-header {
    padding: var(--card-header-padding-y) var(--card-header-padding-x);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    background: linear-gradient(180deg, rgba(39,143,254,0.08) 0%, rgba(255,255,255,0) 100%);
}

.card-panel .card-body {
    padding: var(--card-body-padding);
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--card-shadow);
    height: 100%;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 22px 55px rgba(15, 23, 42, 0.10), 0 6px 18px rgba(15, 23, 42, 0.08);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    margin-bottom: 1rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Dashboard category quick cards */
.category-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    padding: 1rem 1.15rem;
    position: relative;
    overflow: hidden;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.category-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--cat-color, var(--primary));
}
.category-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 22px 55px rgba(15, 23, 42, 0.10), 0 6px 18px rgba(15, 23, 42, 0.08);
}
.category-card-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}
.category-icon {
    width: 38px;
    height: 38px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(148, 163, 184, 0.12);
}
.category-icon i {
    font-size: 1.05rem;
    color: var(--cat-color, var(--primary));
}
.category-name {
    font-weight: 700;
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.2;
}
.category-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.category-pill {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 999px;
    padding: 0.25rem 0.55rem;
}

.table-modern {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.table-modern thead th {
    background: var(--table-head-bg);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    padding: calc(var(--table-cell-y) * 0.9) var(--table-cell-x);
    border-bottom: 1px solid var(--border);
}

.table-modern tbody td {
    padding: var(--table-cell-y) var(--table-cell-x);
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.9rem;
}

.table-modern thead th:first-child { border-top-left-radius: 0.85rem; }
.table-modern thead th:last-child { border-top-right-radius: 0.85rem; }
.table-modern tbody tr:last-child td:first-child { border-bottom-left-radius: 0.85rem; }
.table-modern tbody tr:last-child td:last-child { border-bottom-right-radius: 0.85rem; }
.table-modern tbody tr:last-child td { border-bottom: 0; }

.table-modern tbody tr:hover {
    background: rgba(148, 163, 184, 0.10);
}

.badge-status {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.35em 0.65em;
    border-radius: 999px;
    text-transform: capitalize;
}

.badge-draft { background: #f1f5f9; color: #475569; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dbeafe; color: #1e40af; }
.badge-received { background: #d1fae5; color: #065f46; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }

.btn-primary-custom {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 90%);
    border: none;
    color: #fff;
    font-weight: 500;
    padding: 0.5rem 1.1rem;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    box-shadow: 0 10px 22px rgba(39, 143, 254, 0.26);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn-primary-custom:hover {
    filter: brightness(0.98);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(39, 143, 254, 0.34);
}

/* Better default Bootstrap button to match palette */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-light {
    border-color: var(--border);
}

/* Dark theme tweaks for bootstrap button styles */
[data-theme="dark"] .btn-light,
[data-theme="dark"] .btn-outline-secondary,
[data-theme="dark"] .btn-outline-custom {
    background: rgba(148, 163, 184, 0.08);
    color: var(--text);
    border-color: rgba(148, 163, 184, 0.22);
}
[data-theme="dark"] .btn-light:hover,
[data-theme="dark"] .btn-outline-secondary:hover,
[data-theme="dark"] .btn-outline-custom:hover {
    background: rgba(148, 163, 184, 0.14);
    color: var(--text);
}

/* Small icon button */
.btn-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.6rem;
    padding: 0;
}

/* Slightly denser form controls for filter bars */
.form-control, .form-select {
    padding: 0.48rem 0.78rem;
}

/* Denser button sizing */
.btn-primary-custom,
.btn-outline-custom {
    padding: 0.48rem 0.95rem;
}

/* Compact card header buttons */
.card-panel .card-header .btn,
.card-panel .card-header .btn-primary-custom,
.card-panel .card-header .btn-outline-custom {
    border-radius: 0.6rem;
}

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Login background image + dark overlay for readability */
    background-image:
        linear-gradient(180deg, rgba(11,18,32,0.88) 0%, rgba(15,23,42,0.88) 100%),
        url('../images/login-bg.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    padding: 24px;
}
.auth-page > .container {
    /* Bootstrap .container is width:100% which can break flex centering */
    width: 100%;
    display: flex;
    justify-content: center;
}
.auth-card {
    background: rgba(255,255,255,0.96);
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: calc(var(--radius) + 0.3rem);
    box-shadow: 0 25px 60px rgba(0,0,0,0.35);
    overflow: hidden;
    max-width: 980px;
    width: 100%;
    margin: 0 auto;
}
.auth-side {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: #fff;
    padding: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.auth-form {
    padding: 44px;
}
.auth-brand {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.auth-muted {
    opacity: 0.9;
    font-size: 0.95rem;
}

.btn-outline-custom {
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn-outline-custom:hover {
    background: rgba(39, 143, 254, 0.10);
    color: var(--text);
    transform: translateY(-1px);
    box-shadow: 0 10px 18px rgba(15, 23, 42, 0.08);
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: #334155;
}

.form-control, .form-select {
    border-radius: 0.5rem;
    border-color: var(--border);
    padding: 0.55rem 0.85rem;
    background: rgba(255,255,255,0.9);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(39, 143, 254, 0.18);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background: rgba(148, 163, 184, 0.08);
    color: var(--text);
}

.search-bar {
    max-width: 320px;
}

/* Table filter bars (index pages) */
.table-filters {
    flex: 1 1 auto;
    min-width: 0;
}
.table-filters .table-filter-select {
    width: auto;
    min-width: 180px;
}
.table-filters .table-filter-select-sm {
    width: auto;
    min-width: 140px;
}
.table-filters .table-filter-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.alert-toast {
    border-radius: 0.5rem;
    border: none;
    font-size: 0.9rem;
}

.line-items-table {
    table-layout: fixed;
}

.line-items-table input, .line-items-table select {
    font-size: 0.875rem;
}

.po-totals {
    max-width: 360px;
    margin-left: auto;
}

.po-totals .row-total {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.9rem;
}

.po-totals .grand-total {
    font-size: 1.15rem;
    font-weight: 700;
    border-top: 2px solid var(--border);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
}
