/* =========================================================================
   InvoiceFlow — Design System
   A warm, professional invoicing aesthetic with sharp details.
   ========================================================================= */

:root {
    /* Brand palette */
    --ink:        #1a1a2e;
    --ink-light:  #2d2d44;
    --ink-muted:  #6b6b8a;
    --surface:    #f8f7f4;
    --surface-alt:#efeee9;
    --white:      #ffffff;
    --accent:     #e85d3a;
    --accent-hover:#d14e2d;
    --accent-soft: rgba(232, 93, 58, 0.08);
    --green:      #2d9d78;
    --green-soft: rgba(45, 157, 120, 0.08);
    --yellow:     #e0a526;
    --yellow-soft:rgba(224, 165, 38, 0.08);
    --red:        #d94052;
    --red-soft:   rgba(217, 64, 82, 0.08);
    --blue:       #4a7fd4;
    --blue-soft:  rgba(74, 127, 212, 0.08);

    /* Type */
    --font-body:  'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono:  'JetBrains Mono', monospace;

    /* Spacing */
    --sidebar-w: 240px;
    --radius: 10px;
    --radius-sm: 6px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(26, 26, 46, 0.06);
    --shadow-md: 0 4px 16px rgba(26, 26, 46, 0.08);
    --shadow-lg: 0 8px 32px rgba(26, 26, 46, 0.12);
}

/* ---- Spinner ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid var(--surface-alt); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; vertical-align: middle; }
.spinner-lg { width: 32px; height: 32px; border-width: 4px; }
.loading-spinner { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 40px 20px; color: var(--ink-muted); font-size: .9rem; }

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: var(--font-body);
    background: var(--surface);
    color: var(--ink);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
}

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

/* =========================================================================
   Sidebar
   ========================================================================= */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--ink);
    color: #c5c5d8;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 24px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 16px;
}

.sidebar-logo {
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    background: rgba(255,255,255,.1);
    padding: 2px;
}

.sidebar-logo-placeholder {
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .75rem;
    letter-spacing: .5px;
}

.brand-name {
    font-weight: 600;
    font-size: .95rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #a0a0be;
    font-weight: 500;
    font-size: .9rem;
    transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #e0e0f0; }
.nav-item.active { background: rgba(232, 93, 58, .15); color: var(--accent); }
.nav-item.active svg { stroke: var(--accent); }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }

/* =========================================================================
   Main content area
   ========================================================================= */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
    padding: 32px 40px;
}

.main-full {
    flex: 1;
    min-height: 100vh;
}

/* =========================================================================
   Flash messages
   ========================================================================= */
.flash-container { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.flash {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-weight: 500;
    animation: slideDown .25s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } }

.flash-success { background: var(--green-soft); color: #1a6b52; border-left: 3px solid var(--green); }
.flash-error   { background: var(--red-soft); color: #a0293a; border-left: 3px solid var(--red); }
.flash-warning { background: var(--yellow-soft); color: #8a6a10; border-left: 3px solid var(--yellow); }
.flash-info    { background: var(--blue-soft); color: #2d5a9e; border-left: 3px solid var(--blue); }
.flash-close   { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; }

/* =========================================================================
   Page header
   ========================================================================= */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -.02em;
}
.page-header p {
    color: var(--ink-muted);
    font-size: .95rem;
    margin-top: 2px;
}

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    line-height: 1;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--ink); color: #fff; }
.btn-secondary:hover { background: var(--ink-light); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--ink); color: var(--ink); }
.btn-outline:hover { background: var(--ink); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--ink); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #c0384a; color: #fff; }
.btn-sm { padding: 7px 14px; font-size: .82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #268a69; color: #fff; }

/* =========================================================================
   Cards
   ========================================================================= */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(26, 26, 46, .05);
    padding: 24px;
}

/* =========================================================================
   Stat cards
   ========================================================================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(26,26,46,.05);
    padding: 20px 24px;
}
.stat-card .stat-label {
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-muted);
    margin-bottom: 6px;
}
.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -.03em;
    color: var(--ink);
}
.stat-card .stat-value.green { color: var(--green); }
.stat-card .stat-value.red { color: var(--red); }
.stat-card .stat-value.yellow { color: var(--yellow); }

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(26,26,46,.05);
    overflow: hidden;
}
table {
    width: 100%; border-collapse: collapse;
}
thead th {
    text-align: left;
    padding: 14px 20px;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-muted);
    background: var(--surface);
    border-bottom: 1px solid rgba(26,26,46,.06);
}
tbody td {
    padding: 14px 20px;
    font-size: .92rem;
    border-bottom: 1px solid rgba(26,26,46,.04);
    vertical-align: middle;
}
tbody tr:hover { background: rgba(26,26,46,.015); }
tbody tr:last-child td { border-bottom: none; }

/* =========================================================================
   Badges / Status
   ========================================================================= */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: capitalize;
}
.badge-draft    { background: var(--surface-alt); color: var(--ink-muted); }
.badge-sent     { background: var(--blue-soft); color: #2d5a9e; }
.badge-viewed   { background: var(--yellow-soft); color: #8a6a10; }
.badge-paid     { background: var(--green-soft); color: #1a6b52; }
.badge-overdue  { background: var(--red-soft); color: #a0293a; }
.badge-cancelled{ background: var(--surface-alt); color: var(--ink-muted); }

/* =========================================================================
   Forms
   ========================================================================= */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid rgba(26,26,46,.12);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: .92rem;
    color: var(--ink);
    background: var(--white);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* =========================================================================
   Invoice detail
   ========================================================================= */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 20px;
}
.invoice-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}
.invoice-brand img {
    height: 52px;
    width: auto;
    border-radius: var(--radius-sm);
}
.invoice-brand-placeholder {
    width: 52px; height: 52px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem;
}
.invoice-meta { text-align: right; }
.invoice-meta .inv-number {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
}
.invoice-meta .inv-date {
    font-size: .85rem;
    color: var(--ink-muted);
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 32px;
}
.party-label {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ink-muted);
    margin-bottom: 6px;
}
.party-name { font-weight: 600; font-size: 1.05rem; }
.party-detail { font-size: .88rem; color: var(--ink-muted); }

.invoice-line-items { margin-bottom: 24px; }

.invoice-totals {
    display: flex;
    justify-content: flex-end;
}
.totals-table {
    width: 280px;
}
.totals-table .totals-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: .92rem;
}
.totals-row.total-final {
    font-weight: 700;
    font-size: 1.15rem;
    border-top: 2px solid var(--ink);
    padding-top: 12px;
    margin-top: 4px;
}

/* =========================================================================
   Messages / Chat thread
   ========================================================================= */
.messages-thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
    padding: 16px;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.msg-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: .9rem;
    line-height: 1.5;
}
.msg-company {
    align-self: flex-end;
    background: var(--ink);
    color: #e0e0f0;
    border-bottom-right-radius: 4px;
}
.msg-customer {
    align-self: flex-start;
    background: var(--white);
    color: var(--ink);
    border: 1px solid rgba(26,26,46,.08);
    border-bottom-left-radius: 4px;
}
.msg-meta {
    font-size: .72rem;
    color: var(--ink-muted);
    margin-top: 4px;
}
.msg-company .msg-meta { color: #a0a0be; }

.msg-form {
    display: flex;
    gap: 8px;
}
.msg-form input[type="text"],
.msg-form textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid rgba(26,26,46,.12);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: .9rem;
    resize: none;
}
.msg-form input:focus,
.msg-form textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* =========================================================================
   Line item builder (JS-driven)
   ========================================================================= */
.line-item-row {
    display: grid;
    grid-template-columns: 2fr 100px 120px 100px 40px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.line-item-row input {
    padding: 9px 12px;
    border: 1.5px solid rgba(26,26,46,.12);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: .88rem;
}
.line-item-row input:focus { outline: none; border-color: var(--accent); }
.line-item-row .item-total {
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: .88rem;
    text-align: right;
    padding-right: 8px;
}
.remove-item {
    width: 32px; height: 32px;
    border: none; background: transparent;
    color: var(--red); cursor: pointer;
    font-size: 1.1rem;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.remove-item:hover { background: var(--red-soft); }

.line-item-headers {
    display: grid;
    grid-template-columns: 2fr 100px 120px 100px 40px;
    gap: 8px;
    padding-bottom: 6px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(26,26,46,.08);
}
.line-item-headers span {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ink-muted);
}

/* =========================================================================
   Landing / Auth pages
   ========================================================================= */
.landing {
    display: flex;
    min-height: 100vh;
}
.landing-left {
    flex: 1;
    background: var(--ink);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 60px;
    color: #c5c5d8;
}
.landing-left h1 {
    font-size: 3rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.04em;
    line-height: 1.1;
    margin-bottom: 20px;
}
.landing-left h1 span { color: var(--accent); }
.landing-left p {
    font-size: 1.15rem;
    line-height: 1.7;
    max-width: 440px;
    margin-bottom: 32px;
}
.landing-features {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 12px;
}
.landing-feature {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: .95rem;
}
.landing-feature .check {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: rgba(232,93,58,.15);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: .7rem;
    flex-shrink: 0;
}

.landing-right {
    width: 480px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    background: var(--surface);
}

.auth-card {
    width: 100%;
    max-width: 380px;
}
.auth-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 6px;
}
.auth-card .subtitle {
    color: var(--ink-muted);
    font-size: .92rem;
    margin-bottom: 28px;
}
.auth-card .form-group { margin-bottom: 16px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 12px; }
.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: .88rem;
    color: var(--ink-muted);
}

/* =========================================================================
   Customer-facing invoice (public page)
   ========================================================================= */
.public-invoice {
    max-width: 800px;
    margin: 40px auto;
    padding: 0 20px;
}
.public-invoice .card {
    padding: 40px;
}

.pay-section {
    background: var(--green-soft);
    border: 1.5px solid rgba(45,157,120,.2);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin-top: 32px;
}
.pay-section .pay-amount {
    font-size: 2rem;
    font-weight: 700;
    color: var(--green);
    margin: 8px 0 16px;
}
.pay-section p { color: var(--ink-muted); font-size: .9rem; margin-bottom: 16px; }

.paid-banner {
    background: var(--green-soft);
    border: 1.5px solid rgba(45,157,120,.2);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin-top: 32px;
}
.paid-banner .paid-icon { font-size: 2.5rem; margin-bottom: 8px; }
.paid-banner h3 { color: var(--green); font-size: 1.3rem; }

/* =========================================================================
   Payment success page
   ========================================================================= */
.success-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 40px;
}
.success-card {
    max-width: 460px;
}
.success-icon {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--green-soft);
    color: var(--green);
    display: flex; align-items: center; justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto 20px;
}

/* =========================================================================
   Filter tabs
   ========================================================================= */
.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
    width: fit-content;
}
.filter-tab {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-muted);
    transition: all .15s;
}
.filter-tab:hover { color: var(--ink); }
.filter-tab.active {
    background: var(--white);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

/* =========================================================================
   Empty states
   ========================================================================= */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--ink-muted);
}
.empty-state svg {
    margin-bottom: 16px;
    opacity: .4;
}
.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}
.empty-state p {
    font-size: .9rem;
    margin-bottom: 20px;
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 20px; }
    .landing { flex-direction: column; }
    .landing-left { padding: 40px 24px; }
    .landing-right { width: 100%; padding: 40px 24px; }
    .invoice-parties { grid-template-columns: 1fr; gap: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .line-item-row { grid-template-columns: 1fr; }
    .line-item-headers { display: none; }
}

/* =========================================================================
   Utilities
   ========================================================================= */
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 32px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 32px; }
.text-muted { color: var(--ink-muted); }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: .85rem; }
.text-right { text-align: right; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.inline-flex { display: inline-flex; align-items: center; }
