:root {
    --primary: #1e9a3e;
    --primary-dark: #157a2f;
    --accent: #e11d2a;
    --accent-dark: #b3151f;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --green: #1e9a3e;
    --orange: #f59e0b;
    --red: #ef4444;
    --radius: 16px;
    --nav-h: 64px;
    --app-w: 480px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #e2e8f0;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-weight: 400; }

/* App shell: phone-width column, centered on larger screens */
.app {
    max-width: var(--app-w);
    min-height: 100vh;
    margin: 0 auto;
    background: var(--bg);
    position: relative;
    box-shadow: 0 0 40px rgba(15, 23, 42, .08);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
    background: linear-gradient(135deg, var(--primary-dark), var(--primary) 60%, #3fb55a);
    color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
    width: 42px; height: 42px; border-radius: 12px;
    background: #fff;
    padding: 3px;
    object-fit: contain;
}
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; opacity: .85; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: #fff; color: var(--primary);
    display: grid; place-items: center; font-family: inherit; font-weight: 700; font-size: 14px;
    border: 2px solid rgba(255, 255, 255, .7); padding: 0; cursor: pointer; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.content {
    padding: 16px;
    padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
.greet { margin: 0 0 14px; font-weight: 600; }
.greet .muted { display: block; font-size: 13px; margin-top: 2px; }

/* Bottom navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--app-w);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, .06);
    z-index: 20;
}
.bottom-nav a, .bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    position: relative;
}
.bottom-nav svg { width: 24px; height: 24px; fill: currentColor; }
.bottom-nav .active { color: var(--primary); }
.bottom-nav button { background: none; border: 0; padding: 0; font-family: inherit; cursor: pointer; }
.bottom-nav .active::before {
    /* red accent bar, like the "C" in the logo */
    content: "";
    position: absolute;
    top: 0; left: 30%; right: 30%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
}

/* Stat boxes */
.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}
.stat {
    border-radius: var(--radius);
    padding: 14px;
    color: #fff;
    min-width: 0;
}
.stat-wide { grid-column: 1 / -1; }
.stat-blue { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.stat-green { background: linear-gradient(135deg, var(--accent-dark), var(--accent)); }
.stat-orange { background: linear-gradient(135deg, #0f5132, #2f7d4f); }
.stat-label { font-size: 12px; opacity: .9; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: clamp(17px, 5.2vw, 22px); font-weight: 800; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value small { font-size: 13px; font-weight: 600; opacity: .9; }
.stat-sub { font-size: 12px; opacity: .9; margin-top: 4px; }

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}
.card h2 { font-size: 15px; margin-bottom: 12px; }
.chart-box { position: relative; height: 230px; }

/* Forms */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date] {
    width: 100%;
    padding: 13px 14px;
    font-size: 16px; /* avoids iOS zoom */
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30, 154, 62, .18); }

.btn {
    box-shadow: 0 4px 14px rgba(30, 154, 62, .3);
    display: block;
    width: 100%;
    padding: 14px;
    border: 0;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    font-family: inherit;
}
.btn:active { background: var(--primary-dark); transform: scale(.99); }
.btn-sm { width: auto; padding: 0 18px; font-size: 15px; }

.alert {
    background: #fef2f2; color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 10px 12px; border-radius: 10px;
    font-size: 14px; margin-bottom: 14px;
}
.note {
    background: #ecfdf5; color: #047857;
    border: 1px solid #a7f3d0;
    padding: 10px 12px; border-radius: 10px;
    font-size: 14px; margin: 0 0 10px;
}

/* Login */
.auth {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(160deg, var(--primary-dark) 0%, var(--primary) 43%, var(--accent) 43%, var(--accent) 45%, var(--bg) 45%);
}
.auth-card {
    width: 100%;
    background: var(--surface);
    border-radius: 20px;
    padding: 28px 20px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, .15);
}
/* The logo image already contains the name, so the login heading is kept for screen readers only */
.auth-card h1 {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.auth-card > .muted { text-align: center; margin: 4px 0 20px; }
.auth-title { text-align: center; font-size: 19px; color: var(--primary-dark); margin: 4px 0 10px; }
.center { text-align: center; }
.auth-card p.muted { font-size: 14px; line-height: 1.45; margin: 0 0 18px; }
.link-right { display: block; text-align: right; font-size: 14px; font-weight: 600; margin: -4px 0 14px; }
.back-link { display: block; text-align: center; margin-top: 18px; font-size: 14px; font-weight: 600; }
.dev-box {
    background: #fffbeb; border: 1px dashed #f59e0b; color: #92400e;
    border-radius: 10px; padding: 10px 12px; font-size: 13px; word-break: break-all;
}
.dev-box a { display: block; margin-top: 6px; }
.hint { font-size: 13px; color: var(--muted); margin: -4px 0 14px; }

/* EN / FR switch on the login pages */
.lang-switch {
    position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px;
    display: flex; background: rgba(255, 255, 255, .2); border-radius: 999px; padding: 3px;
}
.lang-switch button {
    border: 0; background: none; color: #fff; font-family: inherit; font-weight: 700; font-size: 12px; line-height: 1;
    padding: 7px 11px; border-radius: 999px; cursor: pointer;
}
.lang-switch button.active { background: #fff; color: var(--primary-dark); }
.auth-card .btn { margin-top: 6px; }
.auth-logo {
    display: block;
    width: 150px; height: auto; margin: 0 auto 8px;
}

/* Search */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.search-bar input { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text);
    font-weight: 600;
}
.chip small { color: var(--muted); font-weight: 500; }
.list-title { font-size: 14px; color: var(--muted); margin: 4px 0 10px; }

/* Invoices */
.invoice {
    background: var(--surface);
    border-radius: 14px;
    margin-bottom: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
    border-left: 4px solid var(--accent);
}
.invoice-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px dashed var(--border);
}
.invoice-no { font-weight: 800; font-size: 14px; }
.invoice-date { font-size: 12px; color: var(--muted); }
.invoice-body {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    margin: 0;
    padding: 10px 14px 12px;
    font-size: 14px;
}
.invoice-body dt { color: var(--muted); }
.invoice-body dd { margin: 0; text-align: right; font-weight: 600; word-break: break-word; }
.invoice-body dd.amount { color: var(--green); font-size: 16px; font-weight: 800; }

/* Revenue */
.range-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.range-form .btn { grid-column: 1 / -1; }
.quick { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.quick a {
    font-size: 12px; font-weight: 600;
    padding: 6px 10px;
    border-radius: 999px;
    background: #e8f5ec;
}
.total-banner {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    text-align: center;
}
.total-value { font-size: 30px; font-weight: 800; margin: 4px 0; word-break: break-word; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty-icon { font-size: 44px; margin-bottom: 8px; }

@media (max-width: 360px) {
    .stat-value { font-size: 17px; }
    .range-form { grid-template-columns: 1fr; }
}

/* Flash messages */
.toast {
    padding: 11px 14px; border-radius: 12px; margin-bottom: 14px;
    font-size: 14px; font-weight: 600;
    transition: opacity .4s, max-height .4s, margin .4s, padding .4s;
    max-height: 120px; overflow: hidden;
}
.toast-ok { background: #e8f5ec; color: var(--primary-dark); border: 1px solid #b7e1c3; }
.toast-err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.toast.hide { opacity: 0; max-height: 0; margin: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }

/* Profile side menu */
body.no-scroll { overflow: hidden; }
.drawer-layer {
    position: fixed;
    top: 0; bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--app-w);
    z-index: 50;
    overflow: hidden;
    pointer-events: none;
}
.drawer-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, .45);
    opacity: 0;
    transition: opacity .25s;
}
.drawer {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 82%;
    max-width: 340px;
    background: var(--surface);
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 30px rgba(15, 23, 42, .2);
    overflow-y: auto;
}
.drawer-layer.open { pointer-events: auto; }
.drawer-layer.open .drawer-backdrop { opacity: 1; }
.drawer-layer.open .drawer { transform: translateX(0); }

.drawer-close {
    position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px;
    width: 34px; height: 34px; border-radius: 50%;
    border: 0; background: rgba(255, 255, 255, .22); color: #fff;
    font-size: 24px; line-height: 1; cursor: pointer; z-index: 1;
}
.drawer-profile {
    padding: calc(34px + env(safe-area-inset-top)) 20px 22px;
    text-align: center;
    color: #fff;
    background: linear-gradient(160deg, var(--primary-dark), var(--primary) 70%, #3fb55a);
    border-bottom: 3px solid var(--accent);
}
.photo-form { margin: 0; }
.profile-photo {
    position: relative;
    width: 92px; height: 92px; margin: 0 auto 12px;
    border-radius: 50%;
    background: #fff;
    color: var(--primary);
    display: grid; place-items: center;
    font-size: 32px; font-weight: 800;
    border: 3px solid #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .2);
    cursor: pointer;
}
.profile-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-photo input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-edit {
    position: absolute; right: -2px; bottom: -2px;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--accent); border: 2px solid #fff;
    display: grid; place-items: center;
}
.photo-edit svg { width: 15px; height: 15px; fill: #fff; }
.profile-name { font-size: 18px; font-weight: 800; }
.profile-email { font-size: 13px; opacity: .9; margin-top: 2px; word-break: break-all; }

.drawer-menu { padding: 8px 0; }
.drawer-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 20px;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.drawer-item > span { flex: 1; }
.drawer-item svg { width: 22px; height: 22px; fill: var(--primary); flex-shrink: 0; }
a.drawer-item:active { background: var(--bg); }
.drawer-item .chev { font-style: normal; color: var(--muted); font-size: 22px; line-height: 1; }
.drawer-item.danger { color: var(--accent); }
.drawer-item.danger svg { fill: var(--accent); }

.segmented {
    display: flex; margin: 0;
    background: var(--bg); border-radius: 999px; padding: 3px;
}
.segmented button {
    border: 0; background: none; cursor: pointer;
    font-family: inherit; font-weight: 700; font-size: 12px; line-height: 1; color: var(--muted);
    padding: 7px 12px; border-radius: 999px;
}
.segmented button.active { background: var(--primary); color: #fff; }
