:root {
    --red: #9b1b1b;
    --red-dark: #6e1212;
    --red-soft: #c0392b;
    --charcoal: #1c1c1e;
    --slate: #2c2c2e;
    --muted: #6b6b6b;
    --line: #e6e2de;
    --bg: #f4f1ee;
    --white: #ffffff;
    --shadow: 0 12px 40px rgba(28, 28, 30, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--charcoal);
    background: var(--bg);
}

a { color: var(--red); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .4rem; }

.guest-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        linear-gradient(160deg, rgba(110, 18, 18, .92), rgba(28, 28, 30, .95)),
        radial-gradient(circle at top left, #c0392b, transparent 40%);
}

.guest-shell { width: min(440px, calc(100% - 32px)); }

.auth-card {
    background: var(--white);
    border-radius: 18px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
}

.auth-header { text-align: center; margin-bottom: 24px; }
.auth-header h1 { font-size: 1.6rem; }
.auth-header p, .topbar p, .page-head p, .menu-label { color: var(--muted); }

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 10px;
    border-radius: 12px;
    background: var(--red);
    color: #fff;
    font-weight: 700;
    letter-spacing: .04em;
}

.form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: .92rem; font-weight: 600; }
input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    font: inherit;
    background: #fafafa;
}
textarea { min-height: 90px; resize: vertical; }
select { min-height: 44px; }
input:focus, textarea:focus {
    outline: 2px solid rgba(155, 27, 27, .25);
    border-color: var(--red);
    background: #fff;
}
input:disabled { background: #eee; color: var(--muted); }

.field-error { color: var(--red); font-weight: 500; }

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 12px 16px;
    font: inherit;
    font-weight: 700;
    letter-spacing: .04em;
    cursor: pointer;
    text-transform: uppercase;
}
.btn-primary { width: 100%; background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost {
    width: 100%;
    margin-top: 10px;
    background: transparent;
    color: var(--charcoal);
    border: 1px solid var(--line);
}
.btn-sm { padding: 7px 10px; font-size: .75rem; width: auto; }
.btn-success { background: #1f7a4d; color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-warning { background: #8a5a12; color: #fff; }

.alert {
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: .95rem;
}
.alert-error { background: #fdecea; color: var(--red-dark); }
.alert-success { background: #e9f7ef; color: #1f7a4d; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px;
    background: var(--charcoal);
    color: #fff;
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    min-height: 100vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #4a4a4d transparent;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand small { display: block; color: #b8b8b8; font-size: .7rem; }
.menu { display: grid; gap: 3px; }
.menu a {
    color: #d9d9d9;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: .9rem;
    line-height: 1.25;
}
.menu a.active, .menu a:hover { background: var(--red); color: #fff; }
.menu-label {
    margin: 11px 0 2px;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: #8f8f8f;
}
.logout-form { margin-top: auto; }
.logout-form button {
    width: 100%;
    background: transparent;
    color: #fff;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-transform: uppercase;
}

@media (min-width: 961px) {
    .sidebar {
        width: 248px;
        padding: 18px 14px;
    }
    .brand {
        margin-bottom: 18px;
    }
    .menu a {
        padding: 6px 10px;
        font-size: .85rem;
    }
    .menu-label {
        margin-top: 8px;
        font-size: .68rem;
    }
    .logout-form {
        padding-top: 14px;
    }
    .logout-form button {
        padding: 8px;
        font-size: .85rem;
    }
}

.main { flex: 1; min-width: 0; }
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.topbar-user { text-align: right; }
.topbar-user em { display: block; color: var(--red); font-style: normal; font-size: .75rem; font-weight: 700; }
.notification-menu { position: relative; }
.notification-menu summary { list-style: none; cursor: pointer; font-size: .85rem; font-weight: 700; }
.notification-menu summary::-webkit-details-marker { display: none; }
.notification-menu summary b { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 5px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: .7rem; }
.notification-dropdown { position: absolute; z-index: 5; top: 30px; right: 0; width: 320px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.notification-dropdown a { display: block; padding: 10px; border-radius: 8px; color: var(--charcoal); font-size: .82rem; }
.notification-dropdown a:hover, .notification-dropdown a.unread { background: #fff4f1; }
.notification-dropdown strong, .notification-dropdown span { display: block; }
.notification-dropdown span { margin-top: 3px; color: var(--muted); }
.notification-dropdown .notification-all { margin-top: 5px; border-top: 1px solid var(--line); color: var(--red-dark); font-weight: 700; }
.notification-empty { display: block; padding: 12px; color: var(--muted); font-size: .85rem; }
.nav-toggle { display: none; }

.content { padding: 24px; }
.page-head { margin-bottom: 20px; }
.page-actions { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--charcoal); font-size: .85rem; }
.tabs a.active { background: var(--charcoal); color: #fff; border-color: var(--charcoal); }
.notification-list { overflow: hidden; }
.notification-item { display: flex; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); color: var(--charcoal); }
.notification-item:last-child { border-bottom: 0; }
.notification-item.unread { background: #fff8f5; }
.notification-item strong, .notification-item span, .notification-item small { display: block; }
.notification-item > span:last-child { flex: 1; }
.notification-item span { margin-top: 4px; color: var(--muted); }
.notification-item small { margin-top: 8px; color: var(--muted); font-size: .75rem; }
.notification-dot { width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: transparent; }
.notification-item.unread .notification-dot { background: var(--red); }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stat-card {
    background: #fff;
    border-radius: 16px;
    padding: 22px;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--charcoal);
}
.stat-card.accent { border-top-color: var(--red); }
.stat-card span { color: var(--muted); }
.stat-card strong { display: block; font-size: 2rem; margin-top: 8px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-bar input { flex: 1 1 260px; }
.filter-bar select { flex: 0 1 180px; }
.filter-bar .btn { width: auto; }
.chip {
    background: #fff;
    color: var(--charcoal);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: .85rem;
}
.chip em { color: var(--muted); font-style: normal; }
.chip.active { background: var(--charcoal); color: #fff; border-color: var(--charcoal); }

.table-wrap {
    overflow: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; min-width: 920px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: .92rem; }
th { background: #faf8f6; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; }
.actions form { margin: 0; }

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: .75rem;
    font-weight: 700;
}
.badge-pending { background: #fff4d6; color: #8a5a12; }
.badge-active { background: #e9f7ef; color: #1f7a4d; }
.badge-rejected { background: #fdecea; color: var(--red-dark); }
.badge-inactive { background: #ececec; color: #555; }

.profile-card, .profile-form {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    max-width: 720px;
}
.profile-card dl { display: grid; gap: 16px; margin: 0 0 20px; }
.profile-card dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; }
.profile-card dd { margin: 4px 0 0; font-weight: 600; }
.status-line { margin-bottom: 16px; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
    width: min(460px, 100%);
    background: #fff;
    border-radius: 16px;
    padding: 22px;
}
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions .btn { width: auto; flex: 1; }

.overlay { display: none; }

.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-head-row .btn { width: auto; }
.split-grid { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 20px; align-items: start; }
.wide-form { max-width: 960px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid label { min-width: 0; }
.compact-form { min-width: 220px; padding: 10px; margin-top: 8px; }
.compact-form textarea { min-height: 60px; }
.detail-grid { display: grid; grid-template-columns: minmax(240px, 360px) 1fr; gap: 20px; align-items: start; }
.section-gap, .dashboard-section { margin-top: 24px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.product-card { background: #fff; border-radius: 16px; padding: 20px; box-shadow: var(--shadow); border-top: 4px solid var(--red); }
.product-card-top { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .8rem; }
.product-card h3 { margin-top: 20px; min-height: 2.6em; }
.product-card p { color: var(--muted); min-height: 2.4em; }
.product-card strong { display: block; color: var(--red-dark); font-size: 1.15rem; margin: 18px 0 8px; }
.product-card small { color: var(--muted); }
.po-form h3 { margin-top: 24px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.customer-preview { background: #faf8f6; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--muted); min-height: 44px; }
.po-add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.po-add-row select { flex: 1; }
.po-add-row .btn { width: auto; }
.po-items-table { min-width: 980px; }
.po-items-table input { min-width: 90px; padding: 8px; }
.po-summary, .po-total-card { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; align-items: end; margin: 16px 0; }
.po-summary > div, .po-total-card > div { background: #faf8f6; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.po-summary span, .po-total-card span { display: block; color: var(--muted); font-size: .8rem; }
.po-summary strong, .po-total-card strong { display: block; margin-top: 6px; color: var(--red-dark); }
.grand-total { border-color: var(--red) !important; }
.grand-total strong { font-size: 1.25rem; }
.print-body { background: #fff; color: #111; }
.print-sheet { max-width: 1100px; margin: 24px auto; padding: 24px; }
.print-header, .print-meta { display: flex; justify-content: space-between; gap: 24px; border-bottom: 2px solid #111; padding-bottom: 16px; }
.print-header small { display: block; margin-top: 6px; }
.print-title { font-size: 1.5rem; font-weight: 800; }
.print-meta { border-bottom: 1px solid #999; padding: 18px 0; }
.print-table { width: 100%; border-collapse: collapse; margin-top: 22px; min-width: 0; }
.print-table th, .print-table td { border: 1px solid #999; padding: 8px; font-size: .8rem; }
.print-table th { background: #eee; color: #111; }
.print-total { width: min(360px, 100%); margin: 20px 0 0 auto; }
.print-total div { display: flex; justify-content: space-between; padding: 6px 0; }
.print-notes { border-top: 1px solid #999; margin-top: 20px; padding-top: 12px; }
.print-button { width: auto; margin-top: 20px; }
.approval-card { background: #fff8e6; border: 1px solid #e4c36a; border-left: 5px solid #8a5a12; border-radius: 12px; padding: 18px; margin-bottom: 20px; }
.approval-card .actions { margin-top: 12px; }
.approval-card .btn { width: auto; }
.reject-form { min-width: 280px; padding: 12px; margin-top: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.timeline { background: #fff; border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.timeline-item { border-left: 3px solid var(--red); padding: 0 0 16px 14px; margin: 12px 0; }
.timeline-item span { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.timeline-item p { margin: 6px 0 0; color: var(--muted); }
.progress-card { background: #fff; border-radius: 16px; padding: 20px; box-shadow: var(--shadow); margin-top: 20px; }
.progress-card h3 { margin: 0; }
.progress-track { height: 12px; background: #ececec; border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress-track span { display: block; height: 100%; background: var(--red); border-radius: inherit; }
.signature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 100px; margin-top: 60px; text-align: center; }
.dashboard-report-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-top: 20px; }
.dashboard-hero { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 24px 28px; margin-bottom: 20px; border-radius: 18px; color: #fff; background: linear-gradient(120deg, var(--red-dark), var(--red)); box-shadow: var(--shadow); }
.dashboard-hero h2 { margin: 5px 0 6px; font-size: 1.45rem; }
.dashboard-hero p { margin: 0; color: rgba(255,255,255,.78); }
.dashboard-hero .eyebrow { color: rgba(255,255,255,.7); }
.dashboard-hero .btn-primary { width: auto; background: #fff; color: var(--red-dark); }
.eyebrow { display: block; color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.dashboard-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.dashboard-kpi { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.dashboard-kpi-alert { border-left: 4px solid var(--red); }
.kpi-icon { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px; background: #f9e9e7; color: var(--red); font-weight: 800; font-size: .78rem; }
.dashboard-kpi small, .dashboard-kpi em { display: block; color: var(--muted); font-size: .75rem; font-style: normal; }
.dashboard-kpi strong { display: block; margin: 3px 0; overflow: hidden; color: var(--charcoal); font-size: 1.2rem; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-grid { display: grid; gap: 20px; margin-bottom: 20px; }
.dashboard-grid-main { grid-template-columns: 1.45fr .85fr; }
.dashboard-grid-secondary { grid-template-columns: 1fr 1fr; }
.dashboard-panel { min-width: 0; padding: 20px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.panel-heading h3 { margin: 4px 0 0; font-size: 1rem; }
.panel-heading a { color: var(--red); font-size: .78rem; font-weight: 700; white-space: nowrap; }
.panel-value { color: var(--red-dark); font-size: 1.05rem; font-weight: 800; white-space: nowrap; }
.panel-value small { color: var(--muted); font-size: .7rem; font-weight: 400; }
.dashboard-chart { display: flex; align-items: end; gap: 10px; height: 220px; padding: 22px 4px 0; border-bottom: 1px solid var(--line); }
.chart-column { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: end; gap: 6px; height: 100%; min-width: 0; }
.chart-column span { overflow: hidden; width: 100%; color: var(--muted); font-size: .62rem; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.chart-column i { display: block; width: min(28px, 70%); min-height: 3px; border-radius: 7px 7px 0 0; background: linear-gradient(180deg, var(--red-soft), var(--red-dark)); }
.chart-column small { color: var(--muted); font-size: .7rem; }
.metric-list { display: grid; gap: 3px; }
.metric-list > div, .simple-row, .profile-summary-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.metric-list > div:last-child, .simple-row:last-child, .profile-summary-row:last-child { border-bottom: 0; }
.metric-list span, .simple-row span, .profile-summary-row span { color: var(--muted); font-size: .83rem; }
.metric-list strong, .simple-row strong, .profile-summary-row strong { color: var(--charcoal); font-size: .88rem; text-align: right; }
.text-danger { color: var(--red) !important; }
.text-success { color: #1f7a4d !important; }
.performance-list { display: grid; gap: 15px; }
.performance-row { display: grid; grid-template-columns: minmax(130px, 1fr) auto; gap: 5px 12px; align-items: center; }
.performance-name strong, .performance-name span { display: block; }
.performance-name strong { font-size: .85rem; }
.performance-name span { margin-top: 3px; color: var(--muted); font-size: .7rem; }
.performance-row > strong { font-size: .8rem; }
.performance-bar { grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 99px; background: #f0e8e5; }
.performance-bar i { display: block; height: 100%; border-radius: inherit; background: var(--red); }
.compact-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.compact-stats > div { padding: 12px; border-radius: 10px; background: #faf8f6; }
.compact-stats span, .compact-stats strong { display: block; }
.compact-stats span { color: var(--muted); font-size: .7rem; }
.compact-stats strong { margin-top: 6px; font-size: 1.15rem; }
.empty-state { color: var(--muted); font-size: .85rem; }
.bar-chart { height: 220px; display: flex; align-items: end; gap: 8px; padding-top: 24px; }
.bar-column { height: 100%; flex: 1; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 5px; min-width: 0; }
.bar-column span { color: var(--muted); font-size: .65rem; white-space: nowrap; transform: rotate(-35deg); transform-origin: bottom right; }
.bar-column i { display: block; width: 70%; min-height: 2px; background: var(--red); border-radius: 5px 5px 0 0; }
.bar-column small { color: var(--muted); font-size: .7rem; }
.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
.pagination a.active { background: var(--charcoal); color: #fff; }

@media (max-width: 960px) {
    .cards { grid-template-columns: 1fr; }
    .dashboard-kpis { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid-main, .dashboard-grid-secondary { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-105%);
        transition: transform .2s ease;
        z-index: 40;
    }
    body.nav-open .sidebar { transform: none; }
    .nav-toggle {
        display: inline-flex;
        border: 0;
        background: var(--charcoal);
        color: #fff;
        width: 40px;
        height: 40px;
        border-radius: 10px;
        cursor: pointer;
    }
    .overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 30;
    }
    body.nav-open .overlay { display: block; }
}

@media (max-width: 720px) {
    .content { padding: 16px; }
    .dashboard-hero { display: block; padding: 20px; }
    .dashboard-hero .btn { margin-top: 16px; }
    .dashboard-kpis { grid-template-columns: 1fr; }
    .dashboard-chart { gap: 5px; }
    .chart-column span { font-size: .55rem; }
    .compact-stats { grid-template-columns: repeat(2, 1fr); }
    .split-grid, .detail-grid, .form-grid { grid-template-columns: 1fr; }
    .page-head-row { display: block; }
    .page-head-row .btn { margin-top: 12px; }
    .po-summary, .po-total-card { grid-template-columns: repeat(2, 1fr); }
    .po-add-row { display: grid; }
    .po-add-row .btn { width: 100%; }
    .approval-card .actions { display: grid; }
    .dashboard-report-grid { grid-template-columns: 1fr; }
    .signature-grid { gap: 20px; }
}

@media print {
    .print-button { display: none; }
    .print-sheet { margin: 0; max-width: none; }
}
