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

/* ══════════════════════════════════════════
   CSS VARIABLES
══════════════════════════════════════════ */
:root {
    --primary:        #4F46E5;
    --primary-hover:  #4338CA;
    --secondary:      #10B981;
    --danger:         #EF4444;
    --warning:        #F59E0B;
    --background:     #0F172A;
    --surface:        #1E293B;
    --surface-light:  #334155;
    --text:           #F8FAFC;
    --text-muted:     #94A3B8;
    --border:         #334155;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --touch-min: 44px;
}

/* ══════════════════════════════════════════
   RESET & BASE
══════════════════════════════════════════ */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--background);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

/* ══════════════════════════════════════════
   HEADER & NAV
══════════════════════════════════════════ */
header {
    background: rgba(30,41,59,.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: .85rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.logo {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: .4rem;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.nav-links {
    display: flex;
    gap: .25rem;
    flex-wrap: wrap;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    padding: .45rem .75rem;
    border-radius: var(--radius-sm);
    transition: color .2s, background .2s;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
    background: var(--surface-light);
}

/* ══════════════════════════════════════════
   MAIN LAYOUT
══════════════════════════════════════════ */
main {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1.25rem;
    flex: 1;
    width: 100%;
}

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

h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.025em; }
h2 { font-size: 1.2rem; margin-bottom: .75rem; }

.section-title {
    margin: 1.5rem 0 .75rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.section-title h2 { font-size: 1.1rem; margin-bottom: 0; }

/* ══════════════════════════════════════════
   STATS GRID
══════════════════════════════════════════ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    transition: transform .2s, box-shadow .2s;
}

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

/* Highlight card — e.g. remaining income */
.highlight-card {
    border-color: var(--warning);
    box-shadow: 0 0 0 1px rgba(245,158,11,.2);
}

.stat-label {
    color: var(--text-muted);
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .35rem;
    display: flex;
    align-items: center;
    gap: .3rem;
}

.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-value.danger  { color: var(--danger);    }
.stat-value.success { color: var(--secondary); }
.stat-value.warning { color: var(--warning);   }

/* ══════════════════════════════════════════
   FORM CARDS
══════════════════════════════════════════ */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.1rem;
    flex: 1;
    min-width: 130px;
}
.form-group:last-child { margin-bottom: 0; }

label {
    display: block;
    margin-bottom: .4rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: .82rem;
}

.form-row   { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: .85rem; }
.form-inline { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.form-inline > * { flex: 1; min-width: 180px; }
.form-inline .btn { flex: 0 0 auto; }

.log-form .form-row { margin-bottom: .75rem; }

/* ══════════════════════════════════════════
   INPUTS & SELECTS
══════════════════════════════════════════ */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: .72rem 1rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    transition: border-color .2s, box-shadow .2s;
    min-height: var(--touch-min);
    -webkit-appearance: none;
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.2);
}

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    padding: .72rem 1.4rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all .2s;
    min-height: var(--touch-min);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

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

.btn-success { background: var(--secondary); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-sm {
    padding: .45rem .9rem;
    font-size: .875rem;
    min-height: var(--touch-min);
}

.action-group {
    display: flex;
    gap: .4rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ══════════════════════════════════════════
   TABLES (desktop)
══════════════════════════════════════════ */
.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

table { width: 100%; border-collapse: collapse; text-align: left; }

th {
    background: rgba(0,0,0,.25);
    padding: .8rem 1rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    white-space: nowrap;
}

td {
    padding: .85rem 1rem;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

tr:hover td { background: rgba(255,255,255,.025); }

/* ══════════════════════════════════════════
   BADGES
══════════════════════════════════════════ */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    line-height: 1.4;
}

.badge-danger   { background: rgba(239,68,68,.12);   color: var(--danger);    }
.badge-success  { background: rgba(16,185,129,.12);  color: var(--secondary); }
.badge-project  { background: rgba(79,70,229,.15);   color: #a5b4fc;          }
.badge-warning  { background: rgba(245,158,11,.15);  color: var(--warning);   }

/* Colour helpers */
.danger  { color: var(--danger);    }
.success { color: var(--secondary); }
.warning { color: var(--warning);   }

/* ══════════════════════════════════════════
   SEARCH BAR
══════════════════════════════════════════ */
.search-bar { position: relative; max-width: 300px; width: 100%; }
.search-bar input { padding-left: 2.5rem; border-radius: 999px; }
.search-icon {
    position: absolute;
    left: .9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* ══════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════ */
.flex            { display: flex; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4           { gap: 1rem; }
.mt-4            { margin-top: 1rem; }
.mb-4            { margin-bottom: 1rem; }
.text-right      { text-align: right; }

/* ══════════════════════════════════════════
   MOBILE-FIRST  ≤ 768px
══════════════════════════════════════════ */
@media (max-width: 768px) {

    /* Nav hamburger */
    .nav-toggle { display: flex; }
    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 0;
        padding: .4rem 0;
        border-top: 1px solid var(--border);
        margin-top: .2rem;
    }
    .nav-links.open { display: flex; }
    .nav-links a {
        padding: .75rem .5rem;
        border-radius: 0;
        border-bottom: 1px solid var(--border);
        min-height: 48px;
    }
    .nav-links a:last-child { border-bottom: none; }

    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.05rem; }

    .page-header { flex-direction: column; align-items: flex-start; }
    .search-bar  { max-width: 100%; }

    /* Stats: 2 cols */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
    .stat-value { font-size: 1.3rem; }

    /* Forms */
    .form-card { padding: 1rem; }
    .form-row, .form-inline, .log-form .form-row { flex-direction: column; gap: 0; }
    .form-group { min-width: 100%; margin-bottom: .9rem; }

    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px; /* stop iOS zoom */
        min-height: 48px;
    }

    .btn { width: 100%; margin-bottom: .2rem; }
    .btn-sm { min-height: 44px; }
    .form-inline .btn { width: auto; }

    /* ── Card-style tables ── */
    .table-container {
        border-radius: var(--radius-sm);
        overflow-x: visible;
        background: transparent;
        border: none;
        box-shadow: none;
    }
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { display: none; }

    tbody tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-bottom: .85rem;
        overflow: hidden;
    }
    tbody tr:hover { background: var(--surface); }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: .65rem 1rem;
        border-top: 1px solid var(--border);
        font-size: .9rem;
        flex-wrap: wrap;
        gap: .35rem;
    }
    td:first-child { border-top: none; }

    td[data-label]::before {
        content: attr(data-label);
        font-size: .7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .06em;
        color: var(--text-muted);
        flex-shrink: 0;
        margin-right: .4rem;
    }

    td.text-right  { justify-content: flex-start; }
    .action-group  { justify-content: flex-start; width: 100%; }
    .action-group .btn { flex: 1; width: auto; margin-bottom: 0; }

    /* Pay inline form */
    td form { flex-wrap: wrap; gap: .35rem; width: 100%; }
    td form input[type="number"] { flex: 1; min-width: 80px; }

    /* Project panel header on mobile */
    .project-kpi-row { gap: .4rem; }
    .kpi-chip { min-width: 90px; }

    /* Sub-forms */
    .sub-form { flex-direction: column; }
    .sub-form .btn { width: 100%; }

    /* Tabs scroll */
    .tabs { overflow-x: auto; }
}

/* ══════════════════════════════════════════
   EXTRA-SMALL  ≤ 420px
══════════════════════════════════════════ */
@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.55rem; }
}
