@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap');

/* ===== OpenDesign Design System ===== */
:root {
    /* Base palette — warm earth tones (OpenDesign default) */
    --bg: #F4EFE6;
    --bg-panel: #FFFFFF;
    --bg-subtle: #F2EDE4;
    --bg-muted: #EBE5DA;
    --bg-elevated: #FFFFFF;

    /* Text hierarchy */
    --text: #2C241A;
    --text-strong: #1A1510;
    --text-muted: #8C8275;
    --text-faint: #BFB8AD;
    --text-soft: #6B6257;

    /* Borders */
    --border: #D9D1C5;
    --border-strong: #B8AFA0;
    --border-soft: #EBE5DA;

    /* Accent — terracotta (OpenDesign default) */
    --accent: #c96442;
    --accent-strong: #b55332;
    --accent-soft: #FDF3EF;
    --accent-tint: #FFF7F4;
    --accent-on: #FFFFFF;

    /* Semantic colors */
    --green: #3B8C5A;
    --green-bg: #EEF8F2;
    --green-soft: #D4EDDE;
    --red: #C0392B;
    --red-bg: #FDF1EF;
    --red-soft: #F5D6D4;
    --amber: #D9912E;
    --amber-bg: #FEF6EC;
    --amber-soft: #FBE8CB;

    /* Radii */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.09);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.12);

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    /* Font */
    --font: 'Cairo', 'Instrument Sans', ui-sans-serif, system-ui, sans-serif;
    --font-mono: 'SF Mono', ui-monospace, monospace;

    /* Sidebar */
    --sidebar-width: 240px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }

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

/* --- Sidebar --- */
.app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: var(--space-5) var(--space-4);
    z-index: 30;
    overflow-y: auto;
}

.sidebar-brand {
    margin-bottom: var(--space-8);
}

.sidebar-brand h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.01em;
}

.sidebar-brand p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

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

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    transition: background-color 0.12s, color 0.12s;
    text-decoration: none;
}

.sidebar-link:hover {
    background: var(--accent-tint);
    color: var(--text-strong);
}

.sidebar-link.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
}

.sidebar-link .icon {
    font-size: 18px;
    width: 24px;
    display: inline-flex;
    justify-content: center;
}

.sidebar-footer {
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-soft);
    font-size: 11px;
    color: var(--text-faint);
}

/* --- Main content --- */
.app-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    padding: var(--space-8);
}

/* --- Mobile header --- */
.mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    z-index: 20;
    align-items: center;
    justify-content: space-between;
}

.mobile-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.mobile-menu-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
}

/* --- Mobile overlay --- */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 25;
}

.mobile-overlay.open {
    display: block;
}

.mobile-drawer {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-panel);
    z-index: 26;
    padding: var(--space-5) var(--space-4);
    transform: translateX(-100%);
    transition: transform 0.2s cubic-bezier(0.23,1,0.32,1);
    display: flex;
    flex-direction: column;
}

.mobile-drawer.open {
    transform: translateX(0);
}

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 2px;
}

/* ===== Container widths ===== */
.container {
    width: 100%;
    max-width: 960px;
}

.container-sm {
    width: 100%;
    max-width: 560px;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-xs);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.card-title {
    font-size: 15px;
    font-weight: 650;
    color: var(--text-strong);
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-grid {
    display: grid;
    gap: var(--space-5);
}

.card-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.card-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* ===== Stat cards ===== */
.stat-grid {
    display: grid;
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}

.stat-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-xs);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-strong);
}

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

.stat-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.12s, border-color 0.12s, color 0.12s;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-on);
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-success {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}
.btn-success:hover { background: #2E7050; border-color: #2E7050; }

.btn-danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}
.btn-danger:hover { background: #A02D24; border-color: #A02D24; }

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-muted); border-color: var(--border-strong); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text); }

.btn-sm {
    font-size: 12px;
    padding: 5px 12px;
    border-radius: var(--radius-sm);
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    font-family: var(--font);
    font-size: 13.5px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
    color: var(--text);
    transition: border-color 0.12s, box-shadow 0.12s;
    outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                      linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: calc(100% - 14px) 50%, calc(100% - 10px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 32px;
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table thead {
    border-bottom: 1px solid var(--border-soft);
}

.table th {
    text-align: left;
    padding: 10px 12px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.table td {
    padding: 10px 12px;
    border-top: 1px solid var(--border-soft);
    vertical-align: middle;
}

.table tr:hover td {
    background: var(--bg-subtle);
}

.table-title {
    font-weight: 600;
    color: var(--text-strong);
    font-size: 13px;
}

.table-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.table-amount {
    font-weight: 700;
    font-size: 13px;
}

.table-amount.positive { color: var(--green); }
.table-amount.negative { color: var(--red); }

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

/* ===== Action links ===== */
.action-links {
    display: flex;
    align-items: center;
    gap: 8px;
}
.action-links.justify-end { justify-content: flex-end; }

.action-link {
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background-color 0.12s;
    cursor: pointer;
}

.action-link-edit {
    color: var(--accent);
}
.action-link-edit:hover { background: var(--accent-tint); }

.action-link-delete {
    color: var(--red);
}
.action-link-delete:hover { background: var(--red-bg); }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-accent {
    background: var(--accent-tint);
    color: var(--accent);
}

.badge-green {
    background: var(--green-bg);
    color: var(--green);
}

.badge-amber {
    background: var(--amber-bg);
    color: var(--amber);
}

/* ===== Category grid ===== */
.category-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.category-card {
    background: var(--bg-subtle);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    min-width: 120px;
}

.category-name {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.category-amount {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-strong);
    margin-top: 2px;
}

/* ===== Transaction list ===== */
.txn-list {
    display: flex;
    flex-direction: column;
}

.txn-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-top: 1px solid var(--border-soft);
    gap: var(--space-3);
}

.txn-item:first-child { border-top: none; }

.txn-info { min-width: 0; flex: 1; }

.txn-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.txn-meta {
    font-size: 11.5px;
    color: var(--text-muted);
}

.txn-amount {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
}

.txn-amount.positive { color: var(--green); }
.txn-amount.negative { color: var(--red); }

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
}

.empty-icon {
    font-size: 40px;
    color: var(--text-faint);
    margin-bottom: var(--space-3);
}

.empty-title {
    font-size: 15px;
    font-weight: 650;
    color: var(--text-strong);
}

.empty-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    margin: 4px 0 var(--space-4);
}

/* ===== Quick actions ===== */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

/* ===== Dividers ===== */
.divider {
    height: 1px;
    background: var(--border-soft);
    margin: var(--space-4) 0;
}

/* ===== Salary layout ===== */
.salary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
}

.salary-detail-label {
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 2px;
}

.salary-detail-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-strong);
}

.salary-detail-value.small {
    font-size: 14px;
}

.salary-detail-value.capitalize {
    text-transform: capitalize;
}

.salary-breakdown {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-3);
}

.breakdown-card {
    background: var(--bg-subtle);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    text-align: center;
}

.breakdown-label {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.breakdown-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-strong);
}

/* ===== Advice cards ===== */
.advice-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
}

.advice-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.advice-title {
    font-size: 14px;
    font-weight: 650;
    color: var(--text-strong);
}

.advice-body {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.6;
    flex: 1;
}

.advice-footer {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-soft);
}

/* ===== Utility classes ===== */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-3 { gap: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mt-1 { margin-top: var(--space-1); }
.text-lg { font-size: 17px; }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ===== Flash messages ===== */
.flash-success {
    background: var(--green-bg);
    border: 1px solid var(--green-soft);
    color: var(--green);
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    font-size: 13px;
}

.flash-error {
    background: var(--red-bg);
    border: 1px solid var(--red-soft);
    color: var(--red);
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    font-size: 13px;
}

.flash-error ul {
    list-style: disc;
    padding-left: 20px;
    margin: 4px 0 0;
}

/* ===== Hide on mobile ===== */
.hide-mobile {}

/* ===== Responsive (mobile-first) ===== */
@media (max-width: 1023px) {
    .app-sidebar { display: none; }
    .app-main { margin-left: 0; padding: var(--space-4); padding-top: 72px; }
    .mobile-header { display: flex; }

    .stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .card-grid-2 { grid-template-columns: 1fr; }
    .card-grid-3 { grid-template-columns: 1fr; }
    .salary-grid { grid-template-columns: repeat(2, 1fr); }
    .salary-breakdown { grid-template-columns: repeat(2, 1fr); }

    .page-header { flex-direction: column; align-items: flex-start; }

    .hide-mobile { display: none; }

    .container, .container-sm { max-width: 100%; }
}

@media (max-width: 639px) {
    .stat-grid-4 { grid-template-columns: 1fr; }
    .salary-grid { grid-template-columns: 1fr; }
    .salary-breakdown { grid-template-columns: 1fr 1fr; }
    .quick-actions { flex-direction: column; }
    .quick-actions .btn { width: 100%; justify-content: center; }
    .table th, .table td { padding: 8px; }
    .form-actions { flex-direction: column; }
}
