:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #334155;
    --line: #475569;
    --text: #f8fafc;
    --muted: #94a3b8;
    --accent: #14b8a6;
    --accent-hover: #0d9488;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --sidebar: 240px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar);
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 1.25rem 1rem;
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: var(--accent);
}

.brand-sub { font-size: 0.75rem; color: var(--muted); margin-bottom: 1.5rem; }

.nav-link {
    display: block;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.nav-link:hover, .nav-link.active {
    background: rgba(20, 184, 166, 0.12);
    color: var(--text);
}

.main {
    flex: 1;
    margin-left: var(--sidebar);
    padding: 1.5rem;
    max-width: 1200px;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.grid-3 {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1.25rem;
}

.stat-card .label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-card-highlight { border-color: rgba(20, 184, 166, 0.35); background: rgba(20, 184, 166, 0.06); }
.stat-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.35rem; }
.value-warning { color: var(--warning); }
.value-danger { color: var(--danger); }
.trend-up { color: var(--success); font-weight: 600; }
.trend-down { color: var(--danger); font-weight: 600; }

.section-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
}

.card-title {
    font-size: 1rem;
    margin-bottom: 0.35rem;
}

.card-intro {
    margin-bottom: 1rem;
}

.revenue-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    min-height: 220px;
    padding-top: 1rem;
}

.revenue-chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.revenue-chart-value {
    font-size: 0.72rem;
    color: var(--muted);
    text-align: center;
    min-height: 1rem;
}

.revenue-chart-track {
    width: 100%;
    max-width: 48px;
    height: 140px;
    display: flex;
    align-items: flex-end;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px 8px 4px 4px;
    overflow: hidden;
}

.revenue-chart-fill {
    width: 100%;
    background: linear-gradient(180deg, var(--accent), var(--accent-hover));
    border-radius: 6px 6px 0 0;
    min-height: 4px;
}

.revenue-chart-label {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 600;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

.btn:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
.btn-danger { background: #dc2626; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success { background: rgba(74, 222, 128, 0.15); border: 1px solid var(--success); color: var(--success); }
.alert-error { background: rgba(248, 113, 113, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.alert-info { background: rgba(20, 184, 166, 0.15); border: 1px solid var(--accent); color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.75rem; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-draft { background: #475569; color: #fff; }
.badge-sent { background: #2563eb; color: #fff; }
.badge-accepted, .badge-paid { background: #16a34a; color: #fff; }
.badge-rejected, .badge-cancelled { background: #dc2626; color: #fff; }
.badge-overdue, .badge-expired { background: #d97706; color: #fff; }

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

label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--muted); }

input, select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

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

.form-group { margin-bottom: 1rem; }
.form-group.full { grid-column: 1 / -1; }

.line-items-table input { font-size: 0.875rem; }
.line-items-table .col-desc { min-width: 220px; }
.line-items-table .col-num { width: 100px; }

.totals-box {
    max-width: 320px;
    margin-left: auto;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--line);
}

.totals-row { display: flex; justify-content: space-between; margin-bottom: 0.35rem; font-size: 0.9rem; }
.totals-row.grand { font-weight: 700; font-size: 1.05rem; color: var(--accent); border-top: 1px solid var(--line); padding-top: 0.5rem; margin-top: 0.5rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 2rem;
}

.login-card h1 { font-size: 1.35rem; margin-bottom: 0.25rem; }
.login-card p { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

.detail-grid { display: grid; gap: 1.5rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 768px) {
    .sidebar { position: static; width: 100%; border-right: none; border-bottom: 1px solid var(--line); }
    .main { margin-left: 0; padding: 1rem; }
    .app-shell { flex-direction: column; }
    .detail-grid { grid-template-columns: 1fr; }
}

.pagination { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--line);
    font-size: 0.85rem;
    color: var(--muted);
}
.pagination .active span { background: var(--accent); color: #fff; border-color: var(--accent); }

.text-muted { color: var(--muted); font-size: 0.875rem; }
.text-right { text-align: right; }

.logo-preview-card {
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
    color: #111;
}

.logo-preview-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin-bottom: 0.75rem;
}

.logo-preview-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.logo-preview-image-wrap img {
    display: block;
    max-width: 120px;
    max-height: 200px;
    object-fit: contain;
}

.logo-preview-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0d9488;
    margin-bottom: 0.25rem;
}

.logo-preview-meta {
    font-size: 0.85rem;
    color: #334155;
}

.logo-preview-hint {
    margin-top: 0.75rem;
    color: #64748b !important;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.checkbox-field input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.checkbox-field label {
    margin: 0;
    font-weight: normal;
    color: var(--text);
    cursor: pointer;
    line-height: 1.5;
}

/* Tom Select — dark theme */
.ts-wrapper.single,
.ts-wrapper.multi {
    width: 100%;
}

.ts-wrapper .ts-control {
    background: var(--bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--line) !important;
    border-radius: 8px;
    min-height: 42px;
    padding: 0.45rem 0.65rem;
    box-shadow: none !important;
}

.ts-wrapper.focus .ts-control {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.15) !important;
}

.ts-wrapper .ts-control input,
.ts-wrapper .ts-control input[type="text"],
.ts-wrapper .ts-dropdown input,
.ts-wrapper .ts-dropdown input[type="text"],
.ts-wrapper .dropdown-input,
.ts-wrapper .dropdown-input input {
    background: transparent !important;
    color: var(--text) !important;
    -webkit-text-fill-color: var(--text) !important;
    caret-color: var(--text) !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

.ts-wrapper .ts-control input::placeholder,
.ts-wrapper .ts-dropdown input::placeholder {
    color: var(--muted) !important;
    opacity: 1;
}

.ts-wrapper.multi .ts-control > div.item {
    background: rgba(20, 184, 166, 0.18) !important;
    color: var(--text) !important;
    border: 0 !important;
    border-radius: 6px;
}

.ts-wrapper .ts-dropdown {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--line) !important;
    border-radius: 8px;
    margin-top: 4px;
    box-shadow: none;
}

.ts-wrapper .ts-dropdown .dropdown-input {
    background: var(--bg) !important;
    border: 1px solid var(--line) !important;
    border-radius: 6px;
    margin: 0.5rem;
    padding: 0.35rem 0.5rem;
}

.ts-wrapper .ts-dropdown .option {
    color: var(--text) !important;
}

.ts-wrapper .ts-dropdown .option.active {
    background: rgba(20, 184, 166, 0.15) !important;
    color: var(--text) !important;
}

.ts-wrapper .ts-dropdown .option:hover,
.ts-wrapper .ts-dropdown .option.selected {
    background: rgba(20, 184, 166, 0.1) !important;
    color: var(--text) !important;
}

.ts-wrapper .ts-dropdown .no-results {
    color: var(--muted) !important;
}

.ts-wrapper .item .remove {
    border-color: var(--line) !important;
    color: var(--muted) !important;
}

.ts-wrapper .item .remove:hover {
    background: transparent !important;
    color: var(--text) !important;
}

.logo-remove-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
    margin-bottom: 0.75rem;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
}

.filter-bar input[type="search"],
.filter-bar select {
    width: auto;
    min-width: 180px;
    flex: 1;
    max-width: 280px;
}

.product-picker {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
}

.product-picker-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.product-picker select {
    flex: 1;
    min-width: 220px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.table-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: center;
}

.table-actions form {
    display: flex;
    margin: 0;
}

.send-card {
    margin-top: 1rem;
}

.line-items-table .col-sub { width: 44px; text-align: center; }
.line-items-table .price-suffix { display: block; font-size: 0.75rem; margin-top: 0.15rem; }
