:root {
    --navy: #1d2c57;
    --navy-2: #142141;
    --orange: #f4511e;
    --orange-dark: #d94315;
    --ink: #182033;
    --muted: #6b7280;
    --line: #e6e8ef;
    --surface: #ffffff;
    --canvas: #f4f6fa;
    --success: #15803d;
    --success-bg: #ecfdf3;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --warning: #b54708;
    --warning-bg: #fffaeb;
    --info: #0e7490;
    --info-bg: #ecfeff;
    --shadow: 0 10px 30px rgba(20, 33, 65, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--orange); }
img { max-width: 100%; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 256px;
    color: #fff;
    background: linear-gradient(180deg, var(--navy-2), var(--navy));
    z-index: 40;
    display: flex;
    flex-direction: column;
    box-shadow: 12px 0 30px rgba(20, 33, 65, .08);
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 86px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,.11);
}
.sidebar-brand img {
    display: block;
    width: 44px;
    height: 44px;
    object-fit: contain;
    background: #fff;
    border-radius: 11px;
    padding: 5px;
}
.sidebar-brand strong { display: block; font-size: 18px; letter-spacing: .4px; }
.sidebar-brand span { display: block; opacity: .72; font-size: 11px; }
.sidebar-nav { padding: 16px 12px; overflow-y: auto; flex: 1; }
.sidebar-label {
    margin: 14px 12px 8px;
    color: rgba(255,255,255,.5);
    text-transform: uppercase;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.1px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    margin: 3px 0;
    color: rgba(255,255,255,.8);
    border-radius: 10px;
    font-weight: 600;
    transition: .18s ease;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-link.active { color: #fff; background: linear-gradient(90deg, var(--orange), #ff7445); box-shadow: 0 8px 20px rgba(244,81,30,.28); }
.nav-icon {
    width: 24px;
    height: 24px;
    display: inline-grid;
    place-items: center;
    border-radius: 7px;
    background: rgba(255,255,255,.1);
    font-size: 11px;
    font-weight: 900;
}
.nav-link.active .nav-icon { background: rgba(255,255,255,.2); }
.sidebar-footer { padding: 14px 18px 18px; border-top: 1px solid rgba(255,255,255,.11); color: rgba(255,255,255,.6); font-size: 11px; }

.main-area { min-height: 100vh; margin-left: 256px; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 72px;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar h1 { margin: 0; font-size: 20px; color: var(--navy); }
.topbar-subtitle { color: var(--muted); font-size: 12px; }
.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--navy), var(--orange));
    font-weight: 800;
}
.user-meta strong { display: block; font-size: 13px; }
.user-meta span { display: block; font-size: 11px; color: var(--muted); }
.content { padding: 28px 30px 44px; max-width: 1640px; margin: 0 auto; }

.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 22px; }
.page-heading h2 { margin: 0 0 4px; font-size: 24px; color: var(--navy); }
.page-heading p { margin: 0; color: var(--muted); }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.card-header h3 { margin: 0; color: var(--navy); font-size: 16px; }
.card-body { padding: 20px; }
.card-footer { padding: 15px 20px; border-top: 1px solid var(--line); background: #fbfcfe; border-radius: 0 0 var(--radius) var(--radius); }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.stat-card { position: relative; overflow: hidden; padding: 20px; min-height: 132px; }
.stat-card::after {
    content: "";
    position: absolute;
    width: 105px;
    height: 105px;
    right: -28px;
    bottom: -35px;
    border-radius: 50%;
    background: rgba(29,44,87,.05);
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .45px; }
.stat-value { margin-top: 8px; color: var(--navy); font-size: 27px; font-weight: 800; line-height: 1.1; }
.stat-note { margin-top: 9px; color: var(--muted); font-size: 12px; }
.stat-accent { width: 42px; height: 4px; border-radius: 99px; background: var(--orange); margin-bottom: 14px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 39px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    transition: .16s ease;
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--navy); border-color: var(--navy); }
.btn-primary:hover { color: #fff; background: var(--navy-2); }
.btn-accent { color: #fff; background: var(--orange); border-color: var(--orange); }
.btn-accent:hover { color: #fff; background: var(--orange-dark); }
.btn-light { color: var(--navy); background: #fff; border-color: var(--line); }
.btn-light:hover { color: var(--navy); background: #f8fafc; border-color: #ccd2df; }
.btn-success { color: #fff; background: var(--success); border-color: var(--success); }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-warning { color: #fff; background: var(--warning); border-color: var(--warning); }
.btn-sm { min-height: 32px; padding: 6px 10px; border-radius: 7px; font-size: 12px; }
.btn-icon { width: 38px; padding: 0; }
.inline-form { display: inline; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px 20px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-group { min-width: 0; }
.form-group.full { grid-column: 1 / -1; }
label { display: block; margin-bottom: 6px; color: #344054; font-weight: 700; font-size: 12px; }
.required::after { content: " *"; color: var(--danger); }
.form-control, .form-select {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #d5d9e2;
    border-radius: 9px;
    outline: none;
    transition: border .15s, box-shadow .15s;
}
textarea.form-control { min-height: 96px; resize: vertical; }
.form-control:focus, .form-select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(244,81,30,.12); }
.form-control[readonly] { background: #f8fafc; color: var(--muted); }
.form-help { margin-top: 5px; color: var(--muted); font-size: 11px; }
.form-error { margin-top: 5px; color: var(--danger); font-size: 11px; }
.input-group { display: flex; }
.input-group > * { border-radius: 0; }
.input-group > *:first-child { border-radius: 9px 0 0 9px; }
.input-group > *:last-child { border-radius: 0 9px 9px 0; }
.input-addon { display: grid; place-items: center; padding: 0 12px; background: #f8fafc; border: 1px solid #d5d9e2; color: var(--muted); font-weight: 700; }
.checkbox-line { display: flex; align-items: center; gap: 8px; }
.checkbox-line input { width: 17px; height: 17px; accent-color: var(--orange); }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 20px; }

.filter-bar { display: grid; grid-template-columns: 2fr repeat(3, minmax(140px, 1fr)) auto; gap: 10px; align-items: end; }
.filter-bar.compact { grid-template-columns: 2fr repeat(2, minmax(140px, 1fr)) auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #475467; background: #f8fafc; font-size: 11px; text-transform: uppercase; letter-spacing: .45px; white-space: nowrap; }
tbody tr:hover { background: #fcfcfd; }
tbody tr:last-child td { border-bottom: 0; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }
.text-muted { color: var(--muted) !important; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.fw-bold { font-weight: 800; }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}
.badge-primary { color: var(--navy); background: #edf1fb; }
.badge-success { color: var(--success); background: var(--success-bg); }
.badge-danger { color: var(--danger); background: var(--danger-bg); }
.badge-warning { color: var(--warning); background: var(--warning-bg); }
.badge-info { color: var(--info); background: var(--info-bg); }
.badge-muted { color: #475467; background: #f2f4f7; }

.alert { position: relative; padding: 13px 42px 13px 15px; margin-bottom: 14px; border: 1px solid transparent; border-radius: 10px; font-weight: 600; }
.alert-success { color: var(--success); background: var(--success-bg); border-color: #abefc6; }
.alert-danger { color: var(--danger); background: var(--danger-bg); border-color: #fecdca; }
.alert-warning { color: var(--warning); background: var(--warning-bg); border-color: #fedf89; }
.alert-info { color: var(--info); background: var(--info-bg); border-color: #a5f3fc; }
.alert-close { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; cursor: pointer; font-size: 18px; color: inherit; }

.empty-state { padding: 48px 22px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--navy); font-size: 16px; }
.empty-icon { width: 58px; height: 58px; margin: 0 auto 13px; display: grid; place-items: center; border-radius: 18px; background: #eef2f8; color: var(--navy); font-weight: 900; }

.detail-list { display: grid; gap: 0; }
.detail-row { display: grid; grid-template-columns: 165px 1fr; gap: 16px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.detail-row:last-child { border-bottom: 0; }
.detail-row dt { color: var(--muted); font-weight: 700; }
.detail-row dd { margin: 0; font-weight: 600; }

.invoice-summary { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; }
.invoice-paper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.invoice-paper-header { padding: 24px; display: flex; justify-content: space-between; gap: 25px; border-bottom: 4px solid var(--orange); }
.invoice-logo { max-width: 270px; }
.invoice-title { text-align: right; }
.invoice-title h2 { margin: 0; color: var(--navy); font-size: 32px; letter-spacing: 1px; }
.invoice-paper-body { padding: 24px; }
.bill-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-bottom: 22px; }
.bill-box h4 { margin: 0 0 7px; color: var(--orange); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
.bill-box p { margin: 2px 0; }
.totals-table { width: 360px; margin: 20px 0 0 auto; }
.totals-table td { padding: 7px 10px; border-bottom: 0; }
.totals-table tr.total td { padding-top: 12px; border-top: 2px solid var(--navy); color: var(--navy); font-size: 16px; font-weight: 900; }
.totals-table tr.balance td { color: var(--danger); font-size: 15px; font-weight: 900; }
.note-box { padding: 14px; margin-top: 18px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--line); }
.note-box h4 { margin: 0 0 6px; color: var(--navy); font-size: 12px; }
.note-box p { margin: 0; white-space: pre-line; }

.chart-bars { display: grid; gap: 12px; }
.chart-row { display: grid; grid-template-columns: 82px 1fr 110px; align-items: center; gap: 12px; }
.chart-track { height: 10px; background: #edf0f5; border-radius: 99px; overflow: hidden; }
.chart-fill { height: 100%; min-width: 2px; background: linear-gradient(90deg, var(--navy), var(--orange)); border-radius: 99px; }

.pagination { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px; margin-top: 18px; }
.pagination a { min-width: 34px; height: 34px; padding: 0 9px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--navy); font-weight: 700; }
.pagination a.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.invoice-items-table input, .invoice-items-table select, .invoice-items-table textarea { min-width: 76px; }
.invoice-items-table .description-cell { min-width: 280px; }
.invoice-items-table textarea { min-height: 62px; }
.invoice-items-table .line-total { font-weight: 800; color: var(--navy); white-space: nowrap; }
.invoice-calculation { max-width: 480px; margin-left: auto; display: grid; gap: 9px; }
.calc-row { display: grid; grid-template-columns: 1fr 190px; align-items: center; gap: 12px; }
.calc-row.output { padding: 9px 0; border-top: 1px solid var(--line); }
.calc-row.grand { color: var(--navy); font-size: 17px; font-weight: 900; border-top: 2px solid var(--navy); }
.calc-control { display: grid; grid-template-columns: 95px 1fr; }
.calc-control select { border-radius: 9px 0 0 9px; }
.calc-control input { border-radius: 0 9px 9px 0; }

.tabs { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); font-weight: 700; }
.tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(380px, 46%) 1fr;
    background: #fff;
}
.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-card { width: 100%; max-width: 430px; }
.login-logo { width: 285px; margin-bottom: 28px; }
.login-card h1 { margin: 0 0 7px; color: var(--navy); font-size: 29px; }
.login-card > p { margin: 0 0 26px; color: var(--muted); }
.login-visual {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    padding: 64px;
    color: #fff;
    background: linear-gradient(145deg, rgba(20,33,65,.96), rgba(29,44,87,.91)), url('../letterhead/OVALFOX-Letterhead.jpg') center/cover;
}
.login-visual::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 85% 15%, rgba(244,81,30,.32), transparent 34%); }
.login-copy { position: relative; max-width: 600px; }
.login-copy h2 { margin: 0 0 12px; font-size: clamp(34px, 5vw, 62px); line-height: 1.05; }
.login-copy p { margin: 0; color: rgba(255,255,255,.78); font-size: 17px; }

.install-page { min-height: 100vh; padding: 36px 18px; background: linear-gradient(145deg, #f5f7fb, #fff); }
.install-card { max-width: 940px; margin: 0 auto; }
.install-head { text-align: center; margin-bottom: 24px; }
.install-head img { width: 300px; }
.install-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.install-step { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; text-align: center; }
.install-step span { width: 28px; height: 28px; margin: 0 auto 6px; display: grid; place-items: center; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 800; }

.overlay { display: none; position: fixed; inset: 0; background: rgba(16,24,40,.5); z-index: 35; }

@media (max-width: 1200px) {
    .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-bar .filter-actions { grid-column: 1 / -1; }
    .invoice-summary { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .overlay { display: block; }
    .main-area { margin-left: 0; }
    .menu-toggle { display: grid; place-items: center; }
    .topbar { padding: 0 18px; }
    .content { padding: 22px 18px 38px; }
    .login-page { grid-template-columns: 1fr; }
    .login-visual { display: none; }
    .grid-3, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .page-heading { flex-direction: column; }
    .page-actions { justify-content: flex-start; }
    .grid-2, .grid-3, .grid-4, .grid-5, .form-grid, .form-grid-3, .filter-bar, .filter-bar.compact, .bill-grid { grid-template-columns: 1fr; }
    .user-meta { display: none; }
    .content { padding-left: 12px; padding-right: 12px; }
    .topbar { padding: 0 12px; }
    .card-body { padding: 16px; }
    .detail-row { grid-template-columns: 1fr; gap: 2px; }
    .invoice-paper-header { flex-direction: column; }
    .invoice-title { text-align: left; }
    .totals-table { width: 100%; }
    .calc-row { grid-template-columns: 1fr; }
    .form-actions { justify-content: stretch; flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .login-panel { padding: 30px 20px; }
    .login-logo { width: 240px; }
    .install-steps { grid-template-columns: 1fr; }
}

@media print {
    .sidebar, .topbar, .page-heading, .no-print, .overlay { display: none !important; }
    .main-area { margin: 0; }
    .content { padding: 0; max-width: none; }
    .card, .invoice-paper { box-shadow: none; border: 0; }
    body { background: #fff; }
}
