:root {
    --bg: #f3f7fb;
    --panel: #ffffff;
    --text: #182536;
    --muted: #657386;
    --line: #dbe5ef;
    --accent: #084783;
    --accent-dark: #063a6c;
    --accent-soft: #e8f1fa;
    --danger: #a33a3a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 230px;
    background: var(--accent);
    padding: 24px 16px;
    color: #fff;
}

.brand {
    margin-bottom: 28px;
}

.brand img {
    display: block;
    width: min(100%, 200px);
    max-width: 100%;
    height: auto;
    max-height: 100px;
    object-fit: contain;
}

.sidebar a {
    display: block;
    color: #d7e8f8;
    text-decoration: none;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 4px;
}

.sidebar a.active,
.sidebar a:hover {
    background: #0b5aa3;
    color: #fff;
}

.content {
    margin-left: 230px;
    padding: 32px;
}

.login-main {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-box {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
}

.login-logo {
    display: block;
    width: min(100%, 200px);
    max-width: 100%;
    height: auto;
    max-height: 100px;
    object-fit: contain;
    margin: 0 auto 22px;
    border-radius: 8px;
}

h1 {
    margin: 0 0 22px;
    font-size: 30px;
}

h2 {
    margin: 28px 0 14px;
    font-size: 20px;
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page-title h1 {
    margin: 0;
}

.panel,
.metrics > div {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

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

.metrics span,
.invoice-head span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.metrics strong {
    font-size: 28px;
}

.metrics small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.premium-metrics > div {
    border-top: 4px solid var(--accent);
    box-shadow: 0 14px 30px rgba(8, 71, 131, 0.08);
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    align-items: end;
}

.grid-form .wide {
    grid-column: span 2;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

input,
select,
textarea,
button {
    width: 100%;
    border-radius: 7px;
    border: 1px solid var(--line);
    font: inherit;
    padding: 10px 11px;
}

textarea {
    min-height: 42px;
    resize: vertical;
}

button {
    cursor: pointer;
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

button:hover {
    background: var(--accent-dark);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

th,
td {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    background: var(--accent-soft);
}

td a {
    color: var(--accent);
    font-weight: 700;
}

.auth-link {
    margin: 14px 0 0;
    text-align: center;
    font-size: 14px;
}

.auth-link a {
    color: var(--accent);
    font-weight: 700;
}

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 18px;
    background: var(--accent-soft);
    border: 1px solid #bdd3e8;
}

.flash.error {
    background: #fae9e9;
    border-color: #e5b5b5;
    color: var(--danger);
}

.invoice-head {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.status {
    display: inline-block;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 8px;
    background: #f7faf9;
}

.finalize-form {
    max-width: 340px;
    margin-top: 18px;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.actions form {
    margin: 0;
}

.actions button {
    min-width: 92px;
    padding: 8px 10px;
}

.icon-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-actions form {
    margin: 0;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.icon-button:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.icon-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.danger-icon {
    color: var(--danger);
    border-color: #e5b5b5;
}

.danger-icon:hover {
    border-color: var(--danger);
    background: #fae9e9;
}

.secondary-button {
    background: #fff;
    color: var(--danger);
    border-color: #e5b5b5;
}

.secondary-button:hover {
    background: #fae9e9;
}

.suggested-price {
    color: var(--accent-dark);
    font-weight: 700;
}

.hint {
    color: var(--muted);
    font-size: 13px;
    margin: 10px 0 0;
}

.notice {
    margin: 0 0 14px;
    padding: 12px 14px;
    border: 1px solid #bdd3e8;
    border-radius: 8px;
    background: var(--accent-soft);
}

.notice.warning {
    border-color: #e5d49a;
    background: #fff6d8;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 16px;
    color: var(--text);
}

.checkline input {
    width: auto;
}

.confirm-button {
    max-width: 340px;
    margin-top: 18px;
}

.app-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 22px;
    margin-bottom: 22px;
}

.app-header span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.app-header h1 {
    margin: 6px 0 0;
}

.filter-bar,
.search-bar {
    display: flex;
    align-items: end;
    gap: 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.filter-bar label {
    min-width: 130px;
}

.filter-bar button,
.search-bar button {
    min-width: 100px;
}

.search-bar input {
    min-width: min(360px, 44vw);
}

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

.chart-card,
.table-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 14px 30px rgba(8, 71, 131, 0.06);
}

.chart-head,
.table-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-head h2,
.table-card-head h2 {
    margin: 0;
}

.chart-head span,
.table-card-head span {
    color: var(--muted);
    font-size: 13px;
}

.bar-row {
    display: grid;
    grid-template-columns: 52px minmax(120px, 1fr) 110px;
    align-items: center;
    gap: 12px;
    min-height: 34px;
    margin-bottom: 10px;
}

.bar-row span,
.bar-row strong,
.rank-row em {
    font-size: 13px;
}

.bar-track {
    height: 10px;
    background: var(--accent-soft);
    border-radius: 999px;
    overflow: hidden;
}

.bar-track > div {
    height: 100%;
    background: var(--accent);
    border-radius: inherit;
}

.bar-row.due .bar-track > div {
    background: #f0c400;
}

.rank-row {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 110px;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.rank-row > span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
}

.rank-row strong {
    display: block;
    margin-bottom: 7px;
}

.rank-row em {
    font-style: normal;
    font-weight: 700;
    text-align: right;
}

.empty-state {
    color: var(--muted);
    margin: 0;
    padding: 18px;
    background: #f8fbfd;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.modern-panel h2 {
    margin-top: 0;
}

.table-card {
    margin-top: 18px;
    padding: 0;
    overflow: hidden;
}

.table-card-head {
    margin: 0;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.table-card-head a {
    color: var(--accent);
    font-weight: 700;
}

.modern-table {
    margin-top: 0;
    border: 0;
    border-radius: 0;
}

.modern-table td strong {
    display: block;
}

.modern-table td small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.reference-pill,
.stock-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
}

.stock-badge {
    color: #12633d;
    background: #e9f7ef;
}

.stock-badge.empty {
    color: var(--danger);
    background: #fae9e9;
}

.compact-card {
    margin-top: 28px;
}

@media (max-width: 900px) {
    .sidebar {
        position: static;
        width: auto;
    }

    .content {
        margin-left: 0;
        padding: 20px;
    }

    .app-header,
    .filter-bar,
    .search-bar {
        display: grid;
        grid-template-columns: 1fr;
    }

    .metrics,
    .grid-form,
    .invoice-head,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .search-bar input {
        min-width: 0;
    }

    .bar-row,
    .rank-row {
        grid-template-columns: 1fr;
    }

    .rank-row em {
        text-align: left;
    }

    .grid-form .wide {
        grid-column: auto;
    }

    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}
