:root {
    --blue: #405a86;
    --blue-dark: #182338;
    --green: #008b0d;
    --line: #d8dce4;
    --header: #4a5d8a;
    --bg: #f5f6fb;
    --text: #141821;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 16px;
}
a { color: inherit; }
input, select, textarea, button {
    font: inherit;
}
input, select, textarea {
    width: 100%;
    min-height: 33px;
    border: 1px solid #cfd4dd;
    background: white;
    padding: 6px 8px;
}
textarea { min-height: 72px; resize: vertical; }
label { display: block; color: #111; }
label + label { margin-top: 10px; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 256px;
    background: var(--blue);
    color: #fff;
    display: flex;
    flex-direction: column;
}
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    background: #0aa6d6;
    color: white;
    font-weight: 700;
    border-radius: 3px;
}
.sidebar nav {
    padding-top: 4px;
}
.sidebar nav a {
    display: block;
    padding: 12px 16px;
    text-decoration: none;
}
.sidebar nav a.child { padding-left: 48px; }
.sidebar nav a.active {
    background: #fff;
    color: #333;
}
.sidebar-foot {
    margin-top: auto;
    padding: 16px;
    display: grid;
    gap: 6px;
}
.main {
    margin-left: 256px;
    padding: 48px;
    min-height: 100vh;
}
h1 {
    margin: 0 0 24px;
    color: var(--header);
    font-size: 42px;
    font-weight: 400;
}
h2 { color: #3d4050; }
.dark-title { color: #000; font-weight: 700; font-size: 32px; }
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 33px;
    padding: 7px 16px;
    border: 1px solid #d6d9df;
    background: #fff;
    color: #333;
    text-decoration: none;
    cursor: pointer;
    border-radius: 0;
}
.btn.primary {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}
.btn.blue {
    background: #1976d2;
    border-color: #1976d2;
    color: #fff;
    margin: 10px 3px 10px 0;
}
.link {
    border: 0;
    background: transparent;
    color: #07116f;
    padding: 0;
    cursor: pointer;
}
.link.danger {
    color: #b42318;
}
.inline-delete {
    display: inline;
    margin: 0;
}
.doc-link {
    color: #001ee6;
    text-decoration: none;
}
.doc-link:hover {
    text-decoration: underline;
}
.status-badge {
    display: inline-block;
    min-width: 56px;
    padding: 2px 8px;
    color: #fff;
    background: #6b7280;
    text-align: center;
    font-size: 13px;
}
.status-unpaid {
    background: #f2a900;
}
.status-paid {
    background: #008b0d;
}
.status-draft {
    background: #6b7280;
}
.sent-icon {
    font-size: 18px;
    line-height: 1;
}
.view-filter {
    margin: -2px 0 4px;
}
.view-filter label {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 150px;
}
.action-menu {
    position: relative;
    display: inline-block;
}
.action-menu summary {
    list-style: none;
    cursor: pointer;
    background: var(--green);
    color: #fff;
    min-height: 33px;
    padding: 8px 34px 8px 14px;
    position: relative;
}
.action-menu summary::-webkit-details-marker {
    display: none;
}
.action-menu summary::after {
    content: "v";
    position: absolute;
    right: 12px;
    top: 8px;
    font-size: 12px;
}
.action-menu-list {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 5;
    min-width: 175px;
    max-height: min(72vh, 520px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 10px 24px rgba(0,0,0,.14);
}
.action-menu-list a,
.action-menu-list button {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    background: #fff;
    color: #243041;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.action-menu-list a:hover,
.action-menu-list button:hover {
    background: #eaf2ff;
}
.action-menu-list button.danger {
    color: #b42318;
}
.action-menu-list form {
    margin: 0;
}
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 12px;
    margin-bottom: 10px;
}
.toolbar label {
    display: flex;
    align-items: center;
    gap: 6px;
}
.toolbar input, .toolbar select { min-width: 130px; }
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e3e6ed;
}
th {
    background: #cfcfcf;
    font-weight: 400;
    text-align: left;
    padding: 8px;
    border-right: 1px solid #ddd;
}
td {
    padding: 9px;
    border-top: 1px solid #e9ebf0;
}
.empty {
    height: 140px;
    text-align: center;
}
.empty h2 { margin: 0 0 16px; }
.alert {
    padding: 10px 14px;
    margin-bottom: 16px;
    border: 1px solid #d6d9df;
    background: #fff8b8;
}
.alert.success { background: #e9f9ed; border-color: #b8e4c2; }
.alert.error { background: #ffe9e9; border-color: #f0b7b7; }

.quick-create {
    border: 1px solid #d5d9e2;
    background: #f8f9fc;
    padding: 10px 30px 22px;
    text-align: center;
    margin-bottom: 10px;
}
.quick-create h1 { margin-bottom: 12px; }
.quick-grid {
    display: flex;
    justify-content: center;
    gap: 34px;
    flex-wrap: wrap;
}
.quick-grid a {
    width: 92px;
    min-height: 64px;
    display: grid;
    place-items: end center;
    text-decoration: none;
    color: #111;
}
.dashboard-lower {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin-top: 28px;
}
.chart-bars {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    align-items: end;
    min-height: 170px;
    border-bottom: 1px solid #cfd4dd;
}
.chart-bars span {
    display: flex;
    align-items: end;
    justify-content: center;
    min-height: 140px;
    border-left: 1px solid #d8dce4;
    color: #555;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.58);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 20px;
}
.modal.open { display: flex; }
.modal-box {
    position: relative;
    background: #fff;
    width: min(520px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    padding: 18px;
}
.modal-box.wide { width: min(760px, 100%); }
.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    border: 0;
    background: transparent;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
}
.grid-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px 12px;
}
.grid-form .span-2 { grid-column: span 2; }
.grid-form .form-actions { grid-column: 1 / -1; }
.check {
    display: flex;
    align-items: center;
    gap: 7px;
}
.check input { width: auto; min-height: auto; }
.inline {
    display: grid;
    grid-template-columns: 1fr 64px;
    gap: 6px;
}
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}
.muted-table {
    background: #cfcfcf;
    padding: 10px;
}
.align-right { text-align: right; }

.document-form {
    display: block;
}
.doc-top {
    display: grid;
    grid-template-columns: 160px 1fr 1fr;
    gap: 72px;
    align-items: start;
}
.logo-box {
    width: 122px;
    height: 122px;
    border: 2px dashed #aaa;
    display: grid;
    place-items: center;
    color: #666;
    margin-bottom: 20px;
    overflow: hidden;
    background: #fff;
    text-align: center;
}
.logo-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.logo-upload {
    cursor: pointer;
    margin-bottom: 6px;
}
.logo-upload input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.logo-upload-row {
    margin: 12px 0 18px 210px;
}
.logo-help {
    display: block;
    color: #666;
    margin-bottom: 12px;
}
.doc-addresses {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    align-items: start;
    margin: 18px 0 10px;
}
.line-table input, .line-table select { border: 0; }
.line-table td { padding: 3px; }
.line-table tr.discount-line td {
    background: #fff7f7;
}
.line-table tr.shipping-line td {
    background: #f7fbff;
}
.line-table th:first-child { width: 74px; }
.line-table th:nth-child(3) { width: 130px; }
.line-table th:nth-child(4) { width: 130px; }
.line-table th:nth-child(5) { width: 130px; }
.line-total { text-align: right; }
.doc-bottom {
    display: grid;
    grid-template-columns: 1fr minmax(320px, 42%);
    gap: 70px;
    margin-top: 8px;
}
.tabs {
    display: flex;
}
.tabs span {
    padding: 11px 16px;
    border: 1px solid #e1e4ea;
    background: #f3f3f3;
}
.tabs span:first-child {
    background: #fff;
    border-top: 2px solid #1b75bb;
}
.doc-bottom textarea { min-height: 86px; }
.totals {
    padding-top: 24px;
}
.totals p {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #aaa;
    padding: 0 18px 12px;
}
.totals .total {
    border: 0;
    font-size: 22px;
}
.document-preview {
    background: #fff;
    border: 1px solid #e2e5ec;
    padding: 28px;
}
.document-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 18px;
}
.document-header h2 {
    margin: 0 0 12px;
    text-align: right;
    color: #222;
}
.document-header > div:last-child {
    text-align: right;
}
.totals.standalone {
    width: min(420px, 100%);
    margin-left: auto;
}
.document-actions > div {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.print-page {
    background: #dfe3eb;
    margin: 0;
}
.print-toolbar {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-bottom: 1px solid #d6dbe5;
    z-index: 2;
}
.a4-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 18px auto;
    background: #fff;
    box-shadow: 0 12px 32px rgba(0,0,0,.18);
    padding: 14mm;
}
.a4-sheet .document-preview {
    border: 0;
    padding: 0;
}
.shipping-label-preview {
    padding: 18mm;
}
.shipping-label-preview h1 {
    color: #111;
    font-size: 28px;
    margin-bottom: 18px;
}
.shipping-label-box {
    border: 2px solid #111;
    min-height: 95mm;
    padding: 14mm;
    margin-bottom: 18px;
}
.shipping-label-box h2 {
    color: #111;
    margin-top: 0;
    font-size: 26px;
}
.shipping-label-box p {
    font-size: 20px;
    line-height: 1.5;
}

.settings-wrap {
    display: grid;
    grid-template-columns: 260px minmax(420px, 740px);
    gap: 48px;
    align-items: start;
}
.settings-nav {
    background: #fff;
    padding: 34px 0;
}
.settings-nav a {
    display: block;
    padding: 12px 30px;
    text-decoration: none;
}
.settings-nav a.active {
    background: var(--blue);
    color: #fff;
}
.settings-panel {
    background: #fff;
    padding: 28px 34px;
    box-shadow: 0 12px 28px rgba(0,0,0,.13);
}
.settings-panel form {
    max-width: 680px;
}
.settings-panel label {
    display: grid;
    grid-template-columns: 210px 1fr;
    align-items: center;
    margin-bottom: 10px;
    color: #666;
}
.settings-panel label.check {
    grid-template-columns: auto 1fr;
    color: #111;
}
.settings-panel label.logo-upload {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    color: #666;
}
.settings-panel .user-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    max-width: none;
    margin-top: 12px;
}
.settings-panel .user-form label {
    display: block;
    margin-bottom: 0;
    color: #555;
}
.settings-panel .user-form label input,
.settings-panel .user-form label select {
    display: block;
    width: 100%;
    margin-top: 6px;
}
.settings-panel .user-form label.check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 31px;
}
.settings-panel .user-form label.check input {
    width: auto;
    margin-top: 0;
}
.settings-panel .user-form .form-actions {
    justify-content: flex-end;
}
.inline-form {
    display: flex;
    gap: 10px;
    margin: 16px 0;
}
.tax-settings-form table {
    margin-bottom: 18px;
}
.tax-entry-row td {
    vertical-align: middle;
}
.tax-entry-row input {
    width: 100%;
}
.tax-entry-row .btn {
    width: 100%;
    min-height: 33px;
    white-space: normal;
}
.tax-settings-form label.check {
    margin: 8px 0 12px;
}
.reports-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 42px;
}
.reports-grid h2 { color: var(--header); font-weight: 400; }
.reports-grid h3 { margin-bottom: 4px; }
.reports-grid p { color: #555; font-size: 14px; margin-top: 0; }

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: #eef2f7;
}
.auth-card {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    padding: 32px;
    box-shadow: 0 12px 28px rgba(0,0,0,.14);
}
.auth-logo {
    width: 140px;
    min-height: 48px;
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}
.auth-logo img {
    max-width: 140px;
    max-height: 72px;
    object-fit: contain;
}
.auth-card h1 { font-size: 34px; }
.auth-card .btn { width: 100%; margin-top: 14px; }

@media (max-width: 900px) {
    .sidebar {
        position: static;
        width: 100%;
        min-height: auto;
    }
    .sidebar nav {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }
    .sidebar-foot { display: none; }
    .main {
        margin-left: 0;
        padding: 24px 14px;
    }
    h1 { font-size: 34px; }
    .doc-top, .doc-addresses, .doc-bottom, .dashboard-lower, .settings-wrap, .reports-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }
    .grid-form {
        grid-template-columns: 1fr;
    }
    .settings-panel .user-form {
        grid-template-columns: 1fr;
    }
    .settings-panel .user-form label.check {
        padding-top: 0;
    }
    .grid-form .span-2 { grid-column: auto; }
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@page {
    size: A4;
    margin: 14mm;
}

@media print {
    body {
        background: #fff;
    }
    .print-toolbar,
    .sidebar,
    .document-actions,
    .alert {
        display: none !important;
    }
    .main {
        margin-left: 0;
        padding: 0;
    }
    .a4-sheet,
    .document-preview {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border: 0;
    }
    table {
        display: table;
        white-space: normal;
    }
}
