:root {
    --bg: #f5efe6;
    --surface: #ffffff;
    --surface-soft: #fbf8f3;
    --ink: #1f2430;
    --muted: #6a7280;
    --accent: #c26a2e;
    --accent-dark: #9c4f1e;
    --line: #ddd6cc;
    --success: #2f7d5f;
    --error: #b5422f;
    --shadow: 0 18px 40px rgba(31, 36, 48, 0.08);
}

* { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    background:
        radial-gradient(circle at top left, rgba(255, 248, 238, 0.96) 0%, rgba(245, 239, 230, 0.98) 38%, rgba(239, 231, 221, 1) 100%),
        linear-gradient(180deg, #fbf6ef 0%, #f2ebe2 100%);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }

a:hover { color: var(--accent-dark); }

.container {
    padding: 28px 24px 36px;
    max-width: 1380px;
    margin: 0 auto;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(221, 214, 204, 0.9);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 8px 30px rgba(31, 36, 48, 0.05);
}

.brand-wrap {
    display: grid;
    gap: 2px;
}

.brand {
    font-weight: 800;
    font-size: 22px;
    letter-spacing: 0.02em;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.nav-link {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 10px 14px;
    border-radius: 999px;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-link:hover,
.nav-link.active {
    color: var(--ink);
    background: rgba(194, 106, 46, 0.12);
}

.nav-link.danger { color: var(--error); }

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.tab {
    padding: 11px 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.8);
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(31, 36, 48, 0.04);
}

.tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.grid {
    display: grid;
    gap: 22px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.card {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 22px;
    box-shadow: var(--shadow);
    min-width: 0;
}

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

.card h1,
.card h2,
.card h3 {
    margin-top: 0;
    color: #18202d;
}

.card h2 {
    font-size: 28px;
    line-height: 1.15;
    margin-bottom: 10px;
}

.card h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.card-head h2,
.card-head h3,
.card-head p {
    margin: 0;
}

.export-actions .btn {
    padding: 8px 12px;
    font-size: 12px;
}

.btn {
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff 0%, #f7f3ee 100%);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(31, 36, 48, 0.08);
}

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

.btn.danger {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

.btn.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
    box-shadow: none;
}

.danger-text {
    color: var(--error);
}

.muted { color: var(--muted); }

.small { font-size: 12px; }

.alert {
    padding: 12px 15px;
    border-radius: 14px;
    background: #fff2d9;
    border: 1px solid #f0d8b0;
    margin-bottom: 18px;
    box-shadow: 0 8px 18px rgba(31, 36, 48, 0.04);
}

.alert.success {
    background: #e9f6ef;
    border-color: #b6e2c9;
    color: var(--success);
}

.alert.error {
    background: #fdeceb;
    border-color: #f1b3aa;
    color: var(--error);
}

.form {
    display: grid;
    gap: 16px;
}

.form-row {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #313847;
}

input, select, textarea {
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    font-size: 14px;
    background: #fffdfa;
    color: var(--ink);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(194, 106, 46, 0.75);
    box-shadow: 0 0 0 4px rgba(194, 106, 46, 0.12);
}

.table {
    display: grid;
    gap: 10px;
}

.row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid rgba(221, 214, 204, 0.92);
    border-radius: 16px;
    background: #fffdfa;
    align-items: start;
}

.row.cols-2 { grid-template-columns: 1fr auto; }
.row.cols-3 { grid-template-columns: 2fr 1fr 1fr; }
.row.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row.cols-6 { grid-template-columns: minmax(70px, 0.7fr) minmax(120px, 1fr) minmax(170px, 1.3fr) minmax(170px, 1.3fr) minmax(120px, 0.9fr) minmax(120px, 0.9fr); }

.row > div {
    min-width: 0;
}

.row form {
    margin: 0;
}

.row.head {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 11px;
    color: var(--muted);
    background: var(--surface-soft);
    letter-spacing: 0.06em;
}

.row.empty {
    grid-template-columns: 1fr;
    color: var(--muted);
}

.items {
    display: grid;
    gap: 8px;
    overflow-x: auto;
}

.item-row {
    display: grid;
    grid-template-columns: minmax(140px, 2fr) minmax(70px, 0.8fr) minmax(95px, 1fr) minmax(95px, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.item-row > * {
    min-width: 0;
}

.item-row.head {
    font-weight: 700;
    font-size: 11px;
    color: var(--muted);
}

.invoice-grid {
    grid-template-columns: minmax(0, 2.2fr) minmax(280px, 1fr);
    gap: 14px;
}

.invoice-grid .card {
    border-radius: 18px;
    padding: 18px;
}

.invoice-grid h2 {
    font-size: 30px;
    margin-bottom: 12px;
    font-weight: 700;
}

#invoice-form label {
    font-size: 13px;
}

#invoice-form input,
#invoice-form select,
#invoice-form textarea {
    font-size: 13px;
}

#invoice-form textarea[name="notes"] {
    min-height: 70px;
}

.totals {
    margin-left: auto;
    font-weight: 600;
    font-size: 13px;
}

.invoice-section {
    display: grid;
    gap: 10px;
}

.invoice-section-soft {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fcf8f2;
}

.invoice-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.invoice-section-head h3 {
    margin: 0;
    font-size: 16px;
}

.invoice-summary {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.summary-pill {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fffdfa;
    font-weight: 600;
    font-size: 13px;
    box-shadow: 0 8px 18px rgba(31, 36, 48, 0.04);
}

.summary-pill span {
    margin-left: 6px;
}

.total-pill {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.84);
    box-shadow: 0 8px 18px rgba(31, 36, 48, 0.04);
}

.seg {
    padding: 10px 16px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.seg.active {
    background: var(--accent);
    color: white;
}

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background: var(--surface);
    padding: 30px;
    border-radius: 18px;
    border: 1px solid var(--line);
    width: min(440px, 90vw);
    text-align: left;
    box-shadow: var(--shadow);
}

.plain { list-style: none; padding: 0; margin: 0; }

.plain li + li {
    margin-top: 10px;
}

.print-body {
    background: white;
    padding: 24px;
}

.print-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.invoice {
    background: white;
    border: 1px solid var(--line);
    padding: 24px;
    border-radius: 12px;
}

.invoice header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.invoice-table th,
.invoice-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.invoice-total {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
    justify-items: end;
}

.invoice-total .total {
    font-size: 18px;
    font-weight: 700;
}

.table-scroll {
    overflow-x: auto;
    border-radius: 16px;
}

.recent-invoices-card {
    width: 100%;
}

.recent-invoices-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 980px;
}

.recent-invoices-table th,
.recent-invoices-table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px dashed var(--line);
    font-size: 13px;
    white-space: nowrap;
    vertical-align: middle;
}

.recent-invoices-table th {
    text-transform: uppercase;
    font-size: 11px;
    color: var(--muted);
    border-bottom: 2px solid var(--line);
    letter-spacing: 0.03em;
    font-weight: 700;
    background: var(--surface-soft);
}

.recent-invoices-table td:nth-child(5) {
    white-space: normal;
    min-width: 180px;
}

.recent-invoices-table td:last-child .actions {
    gap: 6px;
    justify-content: flex-start;
}

.pagination {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    margin-top: 14px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.page-link.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.empty-cell {
    color: var(--muted);
}

.status-badge {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid transparent;
}

.status-badge.open {
    background: #e9f6ef;
    border-color: #b6e2c9;
    color: var(--success);
}

.status-badge.overdue {
    background: #fdeceb;
    border-color: #f1b3aa;
    color: var(--error);
}

.status-badge.nodue {
    background: #fff2d9;
    border-color: #f0d8b0;
    color: #8a6a2a;
}

.footer {
    padding: 18px 0 28px;
    color: var(--muted);
    font-size: 13px;
}

.expenses-table .row.cols-6 > div:last-child {
    display: flex;
    justify-content: flex-start;
}

@media (max-width: 900px) {
    .card.wide { grid-column: span 1; }
    .item-row { grid-template-columns: 1fr; }
    .row { grid-template-columns: 1fr; }
    .row.cols-2,
    .row.cols-3,
    .row.cols-4,
    .row.cols-6 { grid-template-columns: 1fr; }
    .invoice-grid { grid-template-columns: 1fr; }
    nav { gap: 8px; }
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }
    .container {
        padding: 20px 16px 28px;
    }
    .card {
        padding: 18px;
    }
    .invoice-summary,
    .pagination {
        justify-content: flex-start;
    }
}
