@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2234;
    --bg-card-hover: #1f2a40;
    --bg-input: #0f1625;
    --border-color: #2a3654;
    --border-focus: #3b82f6;
    --text-primary: #e8edf5;
    --text-secondary: #8899b4;
    --text-muted: #5a6d8a;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #10b981;
    --accent-green-dim: rgba(16, 185, 129, 0.15);
    --accent-red: #ef4444;
    --accent-red-dim: rgba(239, 68, 68, 0.15);
    --accent-amber: #f59e0b;
    --accent-amber-dim: rgba(245, 158, 11, 0.15);
    --accent-purple: #8b5cf6;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font-body: 'DM Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

html, body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 62px 0 24px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.sidebar-brand {
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
}

.sidebar-brand h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.sidebar-brand span {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: block;
    margin-top: 4px;
}

.nav-section {
    padding: 12px 12px 4px;
}

.nav-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 0 8px;
    margin-bottom: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    user-select: none;
}

.nav-item:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-blue);
    color: white;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 28px 32px;
    min-height: 100vh;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Auth Screen ── */
.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.auth-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}

.auth-box h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.auth-box p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 8px;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.03em;
    flex-shrink: 0;
    padding-top: 6px;
}

.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color var(--transition);
}

.card:hover {
    border-color: var(--border-focus);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-family: var(--font-mono);
}

.stat-value.positive { color: var(--accent-green); }
.stat-value.negative { color: var(--accent-red); }
.stat-value.neutral { color: var(--accent-blue); }

.stat-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Table ── */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
}

.table-title {
    font-size: 14px;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    white-space: nowrap;
}

thead th.right, tbody td.right {
    text-align: right;
}

tbody td {
    padding: 11px 16px;
    border-bottom: 1px solid rgba(42, 54, 84, 0.5);
    font-size: 13.5px;
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-green { background: var(--accent-green-dim); color: var(--accent-green); }
.badge-red { background: var(--accent-red-dim); color: var(--accent-red); }
.badge-amber { background: var(--accent-amber-dim); color: var(--accent-amber); }
.badge-blue { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }

/* ── Forms ── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input, .form-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color var(--transition);
    outline: none;
}

.form-input:focus, .form-select:focus {
    border-color: var(--border-focus);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235a6d8a' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

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

.form-inline {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.form-inline .form-group {
    flex: 1;
    margin-bottom: 0;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--accent-blue-hover);
}

.btn-success {
    background: var(--accent-green);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: transparent;
    color: var(--accent-red);
    border-color: var(--accent-red);
}

.btn-danger:hover {
    background: var(--accent-red-dim);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.15s ease;
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.2s ease;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 18px;
    letter-spacing: -0.02em;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Chart ── */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.chart-container canvas {
    max-height: 340px;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    animation: slideInRight 0.25s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 260px;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-blue); }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Loading ── */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
    gap: 10px;
    font-size: 13px;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 14px;
}

/* ── Recipe Builder ── */
.recipe-line {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(42, 54, 84, 0.4);
}

.recipe-line:last-child {
    border-bottom: none;
}

.recipe-line .ingredient-name {
    flex: 2;
    font-size: 13.5px;
}

.recipe-line .quantity-input {
    width: 100px;
}

.recipe-line .unit-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 30px;
}

.recipe-cost {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--accent-green);
    min-width: 80px;
    text-align: right;
}

/* ── Hamburger toggle button — always visible ── */
.mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 300;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color var(--transition), background var(--transition), border-color var(--transition);
    flex-shrink: 0;
}
.mobile-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

/* Desktop: sidebar collapsed state */
.app-container.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}
.app-container.sidebar-collapsed .main-content {
    margin-left: 0;
    padding-top: 64px;
}
.app-container.sidebar-collapsed .mobile-toggle {
    background: var(--bg-card);
    border-color: var(--border-color);
}

/* Mobile backdrop overlay */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    animation: fadeIn 0.15s ease;
    cursor: pointer;
}
.sidebar-backdrop.visible {
    display: block;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 200;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
        padding: 64px 14px 20px;
        transition: none;
    }
    .mobile-toggle {
        background: var(--bg-card);
        border-color: var(--border-color);
    }
    .app-container.sidebar-collapsed .main-content {
        padding-top: 64px;
    }
    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .page-header {
        gap: 6px;
    }
    .page-header h2 {
        flex-basis: 100%;
        padding-top: 0;
    }
    .page-header-actions {
        width: 100%;
        justify-content: flex-start;
    }
    .modal-box {
        padding: 18px;
    }
    thead th, tbody td {
        padding: 8px 10px;
        font-size: 12px;
    }
    .btn-sm {
        padding: 4px 7px;
        font-size: 11px;
    }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* ── Misc ── */
.mono {
    font-family: var(--font-mono);
}

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

.text-right {
    text-align: right;
}

.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.hidden {
    display: none !important;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

/* ── Expandable rows ── */
.row-summary { cursor: pointer; }
.row-summary:hover { background: var(--bg-card-hover); }
.expand-icon { font-size: 10px; color: var(--text-muted); transition: transform 0.2s; }
.expand-icon.expanded { transform: rotate(90deg); }
.row-detail td { padding: 0 !important; }

/* ── Search bar ── */
.form-input[type="search"], .form-input#main-search, [id$="-search"].form-input {
    background: var(--bg-input);
}

/* ── Negative / positive text in tables ── */
td.negative, .negative { color: var(--accent-red); }
td.positive, .positive { color: var(--accent-green); }
