/* ============================================================
   Interec Billing — Business App Design System
   Same ledger-dark family as the admin panel, but indigo is the
   primary action color here (vs teal in admin) — a deliberate,
   subtle cue that this is the tenant-facing app, not the back office.
   Status meanings (paid=teal, pending=gold, overdue=coral) stay
   consistent across both, since those meanings are shared concepts.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --bg: #0F172A;
    --surface: #1E293B;
    --surface-alt: #334155;
    --border: #475569;
    --text: #F8FAFC;
    --text-muted: #94A3B8;

    --accent-primary: #0EA5E9;
    --accent-teal: #10B981;
    --accent-gold: #F59E0B;
    --accent-coral: #EF4444;

    --radius: 10px;
    --sidebar-width: 220px;
    --topbar-height: 60px;
}

/* Light theme — same navy/blue family, values chosen for a proper
   light-mode palette (not just an algorithmic inversion of the dark
   values), matching the design-system recommendation this was based on. */
html[data-theme="light"] {
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --surface-alt: #E8ECF1;
    --border: #E2E8F0;
    --text: #020617;
    --text-muted: #334155;

    --accent-primary: #0369A1;
    --accent-teal: #059669;
    --accent-gold: #D97706;
    --accent-coral: #DC2626;
}

.theme-toggle {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
}
.theme-toggle:hover { color: var(--text); }

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Sans', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    width: 100%;
}

h1, h2, h3 { font-family: 'Space Grotesk', sans-serif; font-weight: 600; margin: 0 0 12px; color: var(--text); }
a { color: var(--accent-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 18px 0;
    padding-top: calc(18px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 17px;
    padding: 0 18px 18px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-brand .mark { width: 9px; height: 9px; background: var(--accent-primary); border-radius: 2px; display: inline-block; transform: rotate(45deg); }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1; overflow-y: auto; min-height: 0; }
.sidebar nav a { color: var(--text-muted); padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; }
.sidebar nav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--surface-alt); color: var(--accent-primary); }

.sidebar-footer { margin-top: auto; padding: 12px 18px 0; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }
.sidebar-footer a { color: var(--accent-coral); }

.main { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    position: sticky;
    top: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(6px);
    z-index: 5;
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar-left { display: flex; align-items: center; gap: 14px; }

.menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    color: var(--text);
    cursor: pointer;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 15;
}

.content { padding: 26px; max-width: 1200px; width: 100%; }

/* Mobile: sidebar becomes an off-canvas panel, hidden by default,
   toggled via a hamburger button in the topbar. Nothing here changes
   desktop behavior at all — .sidebar-open is only ever added on small
   screens via JS, and the media query is what actually enables the
   transform/hide behavior in the first place. */
@media (max-width: 860px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 20;
    }
    .sidebar.sidebar-open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: flex; }
    .sidebar-backdrop.sidebar-open { display: block; }
    .content { padding: 18px; }
}

/* Bottom tab bar — only in the installed app, only on phone-width
   screens. In a regular browser tab, or on desktop, the sidebar +
   hamburger stay exactly as they were; nothing here applies. */
.bottom-tab-bar { display: none; }
@media (max-width: 860px) {
    html.is-standalone .bottom-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        z-index: 25;
    }
    html.is-standalone .menu-toggle { display: none; }
    html.is-standalone .sidebar { display: none; }
    html.is-standalone .main { margin-left: 0; }
    html.is-standalone .content { padding-bottom: 78px; }
}
.bottom-tab-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 4px 6px; color: var(--text-muted); font-size: 10.5px; text-decoration: none;
}
.bottom-tab-item:hover { text-decoration: none; }
.bottom-tab-item.active { color: var(--accent-primary); }
.bottom-tab-item svg { width: 20px; height: 20px; }

.impersonation-banner { background: #4a2e00; color: #ffd680; padding: 8px 16px; font-size: 13px; text-align: center; }
.impersonation-banner a { color: #fff; text-decoration: underline; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; }
.flash-success { background: rgba(16, 185, 129, 0.12); border: 1px solid rgba(16, 185, 129, 0.3); color: var(--accent-teal); }
.flash-error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.3); color: var(--accent-coral); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--tab-color, var(--accent-primary)); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.stat-card .value { font-family: 'IBM Plex Mono', monospace; font-size: 22px; font-weight: 600; }
.stat-card .sub { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-card.primary { --tab-color: var(--accent-primary); }
.stat-card.teal { --tab-color: var(--accent-teal); }
.stat-card.gold { --tab-color: var(--accent-gold); }
.stat-card.coral { --tab-color: var(--accent-coral); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.panel h2, .panel h3 { font-size: 15px; margin-bottom: 12px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 500; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-alt); }
table.data .num { font-family: 'IBM Plex Mono', monospace; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; font-family: 'IBM Plex Mono', monospace; }
.pill-teal { background: rgba(16, 185, 129, 0.15); color: var(--accent-teal); }
.pill-gold { background: rgba(245, 158, 11, 0.15); color: var(--accent-gold); }
.pill-primary { background: rgba(14, 165, 233, 0.15); color: var(--accent-primary); }
.pill-coral { background: rgba(239, 68, 68, 0.15); color: var(--accent-coral); }
.pill-muted { background: var(--surface-alt); color: var(--text-muted); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
    width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 11px; color: var(--text); font-family: 'IBM Plex Sans', sans-serif; font-size: 13.5px;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25);
}
a:focus-visible, button:focus-visible, .btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}
textarea { min-height: 70px; resize: vertical; }

table.items input, table.items select { width: 100%; }

.btn { display: inline-block; background: var(--accent-primary); color: #fff; border: none; border-radius: 8px; padding: 8px 15px; font-family: 'IBM Plex Sans', sans-serif; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn-muted { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--accent-coral); color: #2A0906; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filters a { color: var(--text-muted); padding: 6px 12px; border-radius: 8px; font-size: 13px; background: var(--surface); border: 1px solid var(--border); }
.filters a.active, .filters a:hover { color: var(--accent-primary); border-color: var(--accent-primary); text-decoration: none; }

/* Responsive field-row utilities — used wherever two/three form fields
   sit side by side (e.g. discount type + value, from/to dates). Collapses
   to a single column on narrow screens instead of squeezing fields
   unreadably thin. Any inline "display:grid; grid-template-columns:1fr 1fr"
   was replaced with these classes specifically so this one media query
   fixes every occurrence at once, rather than needing per-page fixes. */
.field-grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field-grid-3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.two-col-panels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 640px) {
    .field-grid-2, .field-grid-3, .two-col-panels { grid-template-columns: 1fr; }
}

/* Tables scroll horizontally instead of squashing columns unreadably —
   applied to every table.data across the whole app from one rule, rather
   than needing a wrapping div added to each individual page. */
@media (max-width: 640px) {
    table.data { font-size: 12.5px; display: block; overflow-x: auto; white-space: nowrap; }
    table.data td, table.data th { white-space: nowrap; }
    table.data th, table.data td { padding: 8px 6px; }

    /* Topbar gets crowded with hamburger + title + search + notif + theme
       all in one row on a phone-width screen — drop the page title (the
       sidebar nav still shows which section you're in once opened) and
       let the search bar take the freed-up space. */
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar h1 { display: none; }
    .global-search-wrap { margin: 0 6px !important; max-width: none !important; }
}

.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); position: relative; }
.auth-theme-toggle { position: absolute; top: 20px; right: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    background: var(--bg);
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent-primary, var(--accent-teal));
    background: var(--surface-alt);
}
.drop-zone .drop-icon { margin-bottom: 8px; opacity: 0.6; display: flex; justify-content: center; color: var(--text-muted); }
.drop-zone .drop-text { font-size: 13px; color: var(--text-muted); }
.drop-zone .drop-text .browse-link { color: var(--accent-primary, var(--accent-teal)); font-weight: 600; }
.drop-zone .drop-filename { font-size: 12.5px; color: var(--text); margin-top: 8px; font-family: 'IBM Plex Mono', monospace; }
.drop-zone-preview { max-height: 70px; margin-bottom: 10px; border-radius: 6px; }
