/* ============================================================
   Core Variables & Tokens
   ============================================================ */
:root {
    --primary: #0A2342;
    --primary-light: #1a3a5c;
    --accent: #C9A84C;
    --accent-hover: #b0913f;
    --bg-color: #f0f3f8;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;

    --font-heading: 'Playfair Display', serif;
    --font-body: 'Inter', 'Source Sans Pro', sans-serif;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.15);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-body);
    background: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--primary);
    margin-bottom: 0.5rem;
}

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

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #0A2342 0%, #0d2d55 100%);
    color: white;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.sidebar-logo {
    padding: 2rem 1.5rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo-name {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 0.02em;
    display: block;
    line-height: 1.3;
}

.sidebar-logo-sub {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.45);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    display: block;
    margin-top: 0.2rem;
}

.sidebar nav {
    padding: 1.25rem 1rem;
    flex: 1;
}

.nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.3);
    padding: 0 0.75rem;
    margin: 1rem 0 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    color: rgba(255,255,255,0.72);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    margin-bottom: 0.15rem;
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
}

.nav-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.8;
}

.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,0.1);
    color: white;
}

.nav-link:hover svg, .nav-link.active svg {
    opacity: 1;
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(201,168,76,0.25), rgba(201,168,76,0.12));
    color: var(--accent);
    border-left: 3px solid var(--accent);
}

/* ============================================================
   Main Content
   ============================================================ */
.main-content {
    flex: 1;
    padding: 2rem 2.5rem;
    min-width: 0;
    overflow-x: hidden;
}

/* ============================================================
   Page Header
   ============================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-header-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.15rem;
}

/* ============================================================
   Stats Grid
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1.25rem;
    margin-bottom: 2rem;
}

@media (max-width: 1400px) { .stats-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px)  { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 580px)  { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
    border-radius: var(--radius);
    padding: 1.5rem 1.5rem 1.25rem;
    cursor: default;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
    color: white;
    user-select: none;
    min-height: 210px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: rgba(255,255,255,0.07);
    transition: var(--transition);
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: -50px;
    right: 30px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.stat-card:hover::before { transform: scale(1.15); }

.stat-card-sales      { background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); }
.stat-card-invoices   { background: linear-gradient(135deg, #581c87 0%, #9333ea 100%); }
.stat-card-cost       { background: linear-gradient(135deg, #7f1d1d 0%, #dc2626 100%); }
.stat-card-investment { background: linear-gradient(135deg, #064e3b 0%, #10b981 100%); }
.stat-card-profit     { background: linear-gradient(135deg, #78350f 0%, #d97706 100%); }

.stat-icon-wrap {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    backdrop-filter: blur(4px);
}

.stat-icon-wrap svg {
    width: 24px;
    height: 24px;
    color: white;
    stroke: white;
}

.stat-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.75;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.55rem;
    font-weight: 800;
    font-family: var(--font-heading);
    line-height: 1.2;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.stat-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0;
}

.stat-badge {
    font-size: 0.72rem;
    background: rgba(255,255,255,0.18);
    border-radius: 20px;
    padding: 0.2rem 0.6rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.stat-action-btns {
    display: flex;
    gap: 0.35rem;
    margin-top: auto;
    padding-top: 0.85rem;
    flex-wrap: nowrap;
    align-items: center;
}

.stat-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.28rem 0.55rem;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    background: rgba(255,255,255,0.22);
    color: white;
    transition: var(--transition);
    backdrop-filter: blur(4px);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    flex: 1;
}

.stat-btn:hover {
    background: rgba(255,255,255,0.38);
    transform: scale(1.03);
}

.stat-btn svg {
    width: 11px;
    height: 11px;
    stroke: white;
    flex-shrink: 0;
}

/* Full-width View button on its own row */
.stat-btn-view {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.32rem 0.75rem;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 700;
    border: 1px solid rgba(255,255,255,0.35);
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.9);
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.stat-btn-view:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.6);
    color: white;
}

/* ============================================================
   Cards & Surfaces
   ============================================================ */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(0,0,0,0.04);
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-title svg {
    width: 18px;
    height: 18px;
    color: var(--accent);
    stroke: var(--accent);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    font-family: var(--font-body);
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-size: 0.875rem;
    letter-spacing: 0.01em;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #d4a843);
    color: white;
    box-shadow: 0 4px 12px rgba(201,168,76,0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover), #c09830);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(201,168,76,0.45);
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-color);
    border-color: #cbd5e1;
}

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

.btn-danger:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.btn-icon {
    padding: 0.45rem;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: rgba(0,0,0,0.06);
    color: var(--danger);
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
}

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 1rem; }

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-main);
    transition: var(--transition);
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(201,168,76,0.12);
}

/* ============================================================
   Tables
   ============================================================ */
.table-responsive { overflow-x: auto; border-radius: var(--radius-sm); }

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

.table th, .table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.table th {
    background: #f8fafc;
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-top: 1px solid var(--border);
}

.table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

.table tbody tr:hover { background: rgba(0,0,0,0.018); }
.table tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   Pagination
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding-top: 1.25rem;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text-main);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.pagination-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

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

.pagination-btn svg { width: 14px; height: 14px; }

.pagination-info {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
    padding: 0 0.5rem;
}

/* ============================================================
   Modal / Popup
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10,35,66,0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeInOverlay 0.2s ease;
}

.modal-overlay.active { display: flex; }

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

.modal-box {
    background: white;
    border-radius: 18px;
    width: 100%;
    max-width: 820px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUpModal 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUpModal {
    from { opacity: 0; transform: translateY(30px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
    border-radius: 18px 18px 0 0;
}

.modal-header-left {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.modal-icon-wrap {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-icon-wrap svg { width: 20px; height: 20px; stroke: white; }

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
    font-family: var(--font-heading);
}

.modal-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: var(--transition);
}

.modal-close:hover {
    background: #fee2e2;
    border-color: #fecaca;
    color: var(--danger);
}

.modal-close svg { width: 16px; height: 16px; }

.modal-body { padding: 1.5rem 1.75rem; }

/* Add Entry Panel */
.entry-panel {
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.entry-panel-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.entry-panel-title svg { width: 14px; height: 14px; }

.entry-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.75rem;
    align-items: end;
}

@media (max-width: 600px) { .entry-form-row { grid-template-columns: 1fr; } }

.action-toggle {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: white;
}

.action-toggle-btn {
    flex: 1;
    padding: 0.55rem 0.85rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: var(--transition);
    color: var(--text-muted);
}

.action-toggle-btn svg { width: 13px; height: 13px; }

.action-toggle-btn.active-add {
    background: #dcfce7;
    color: #166534;
}

.action-toggle-btn.active-subtract {
    background: #fee2e2;
    color: #991b1b;
}

/* Amount badge inside table */
.amount-add      { color: #16a34a; font-weight: 700; }
.amount-subtract { color: #dc2626; font-weight: 700; }
.action-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.pill-add      { background: #dcfce7; color: #166534; }
.pill-subtract { background: #fee2e2; color: #991b1b; }

/* ============================================================
   Grid Layouts
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }

/* ============================================================
   Utilities
   ============================================================ */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-4 { margin-top: 2rem; }
.mb-2 { margin-bottom: 1rem; }

/* ============================================================
   Badge / Status
   ============================================================ */
.badge {
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    background: var(--border);
    letter-spacing: 0.04em;
}

/* ============================================================
   Flash Messages
   ============================================================ */
.flash-message {
    padding: 0.9rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    display: none;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.flash-success { background: #dcfce7; color: #166534; border-left: 4px solid #16a34a; }
.flash-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid #dc2626; }

/* ============================================================
   Search Bar Wrapper
   ============================================================ */
.search-wrapper {
    position: relative;
    max-width: 320px;
    margin-bottom: 1.25rem;
}

.search-wrapper svg {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-wrapper .form-control {
    padding-left: 2.5rem;
}

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    opacity: 0.3;
    margin-bottom: 1rem;
}

.empty-state p { font-size: 0.9rem; }

/* ============================================================
   Scrollbar Styling
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
