/* =====================================================================
   Awan Town House — Stylesheet
   Vivid, warm, mobile-first construction-tracker theme.
   ===================================================================== */

:root {
    --color-primary: #1565C0;       /* construction blue */
    --color-primary-dark: #0D47A1;
    --color-primary-light: #6FA8DC;
    --color-secondary: #00A8A8;     /* teal */
    --color-secondary-dark: #00787D;
    --color-accent-blue: #2980B9;
    --color-amber: #FFC107;
    --color-success: #2ECC71;
    --color-warning: #F39C12;
    --color-danger: #E74C3C;

    --bg-body: #F3F8FB;
    --bg-surface: #FFFFFF;
    --bg-surface-alt: #E9F3F8;
    --text-main: #16232E;
    --text-muted: #5C7385;
    --border-color: #DCE9F0;
    --shadow-soft: 0 2px 10px rgba(16, 35, 46, 0.08);
    --shadow-strong: 0 8px 24px rgba(16, 35, 46, 0.16);
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 999px;
    --nav-height: 64px;
}

:root[data-theme="dark"] {
    --bg-body: #0E1620;
    --bg-surface: #16222E;
    --bg-surface-alt: #1C2C3A;
    --text-main: #E7F0F7;
    --text-muted: #9BB0C0;
    --border-color: #2A3B4A;
    --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow-strong: 0 8px 24px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--color-secondary-dark); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; }
p { margin: 0 0 10px; }

.app-shell {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--nav-height) + 90px);
    min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0 16px;
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.15rem;
}
.topbar .brand .logo-badge {
    width: 38px; height: 38px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    box-shadow: var(--shadow-soft);
}
.topbar .icon-btn {
    width: 40px; height: 40px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    box-shadow: var(--shadow-soft);
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
}
.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 10px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 480px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } }

.stat-tile {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
}
.stat-tile .label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.stat-tile .value { font-size: 1.35rem; font-weight: 800; margin-top: 4px; color: var(--color-primary-dark); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    min-height: 48px;
    transition: transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark)); color: #fff; box-shadow: 0 4px 14px rgba(21, 101, 192, 0.35); }
.btn-secondary { background: var(--color-secondary); color: #fff; box-shadow: 0 4px 14px rgba(0, 168, 168, 0.3); }
.btn-outline { background: transparent; border: 2px solid var(--border-color); color: var(--text-main); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 8px 14px; font-size: 0.85rem; border-radius: var(--radius-md); }
.btn-icon { width: 44px; height: 44px; padding: 0; border-radius: var(--radius-full); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: 0.85rem; margin: 14px 0 6px; color: var(--text-muted); }
label:first-child { margin-top: 0; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=tel], input[type=search], input[type=file], select, textarea {
    width: 100%;
    padding: 13px 14px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15);
}
textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.checkbox-row input { width: 20px; height: 20px; }
.checkbox-row label { margin: 0; }

fieldset { border: 1.5px dashed var(--border-color); border-radius: var(--radius-md); padding: 12px; margin-top: 14px; }
legend { padding: 0 6px; font-weight: 700; color: var(--color-secondary-dark); font-size: 0.85rem; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
}
.badge-outline { background: var(--bg-surface-alt); color: var(--text-main); border: 1px solid var(--border-color); }
.pill-worker { background: var(--color-secondary); }
.pill-shop { background: var(--color-primary); }
.pill-contractor { background: #8E44AD; }
.pill-admin { background: var(--color-danger); }
.pill-member { background: var(--color-secondary); }

/* ---------- Progress bars ---------- */
.progress-track {
    width: 100%;
    height: 14px;
    background: var(--bg-surface-alt);
    border-radius: var(--radius-full);
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.progress-fill { height: 100%; border-radius: var(--radius-full); transition: width 0.3s ease; }
.progress-green { background: linear-gradient(90deg, #2ECC71, #27AE60); }
.progress-amber { background: linear-gradient(90deg, #FFC107, #F39C12); }
.progress-red { background: linear-gradient(90deg, #FF6B6B, #E74C3C); }

/* ---------- Record cards (mobile "table") ---------- */
.record-card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--color-primary);
}
.record-card .rc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.record-card .rc-amount { font-weight: 800; font-size: 1.05rem; color: var(--color-primary-dark); }
.record-card .rc-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.record-card .rc-actions { margin-top: 10px; display: flex; gap: 8px; }

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td { padding: 10px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
table.data-table th { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; }

@media (max-width: 640px) {
    table.data-table.responsive-cards, table.data-table.responsive-cards thead { display: none; }
    table.data-table.responsive-cards tbody, table.data-table.responsive-cards tr, table.data-table.responsive-cards td { display: block; width: 100%; }
    table.data-table.responsive-cards tr {
        background: var(--bg-surface);
        border-radius: var(--radius-md);
        margin-bottom: 10px;
        padding: 10px 14px;
        box-shadow: var(--shadow-soft);
        border: 1px solid var(--border-color);
    }
    table.data-table.responsive-cards td {
        border: none;
        padding: 6px 0;
        display: flex;
        justify-content: space-between;
        gap: 10px;
    }
    table.data-table.responsive-cards td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
    }
}

/* ---------- Bottom navigation ---------- */
.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--nav-height);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 6px 0;
}
.bottom-nav a .nav-icon { font-size: 1.3rem; }
.bottom-nav a.active { color: var(--color-primary); }

.fab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
    width: 60px; height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
    box-shadow: 0 6px 18px rgba(21, 101, 192, 0.45);
    z-index: 41;
    border: none;
}
.fab:active { transform: scale(0.94); }

/* ---------- More menu grid ---------- */
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.more-grid a {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 16px 8px;
    text-align: center;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 0.78rem;
    font-weight: 700;
}
.more-grid a .mg-icon { font-size: 1.6rem; display: block; margin-bottom: 6px; }

/* ---------- Login / setup ---------- */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #1565C0 0%, #2E86C1 35%, #00A8A8 100%);
}
.auth-box {
    width: 100%;
    max-width: 380px;
    background: rgba(255,255,255,0.97);
    border-radius: var(--radius-lg);
    padding: 32px 26px;
    box-shadow: var(--shadow-strong);
    text-align: center;
}
:root[data-theme="dark"] .auth-box { background: rgba(14, 22, 32, 0.97); }
.auth-icon {
    width: 84px; height: 84px;
    margin: 0 auto 14px;
    border-radius: 24px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 2.6rem;
    box-shadow: var(--shadow-strong);
}
.auth-title { font-size: 1.6rem; font-weight: 900; margin-bottom: 2px; color: var(--text-main); }
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 22px; }
.auth-box form { text-align: left; }
.brand-footer-logo { display: block; max-width: 160px; height: auto; margin: 26px auto 0; opacity: 0.85; }
.pdf-footer-note { text-align: center; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-md); margin-bottom: 12px; font-size: 0.88rem; font-weight: 600; }
.alert-success { background: #E7F9EF; color: #1E7F4B; border: 1px solid #B7EDCB; }
.alert-danger { background: #FDECEA; color: #B3261E; border: 1px solid #F6C6C2; }
.alert-warning { background: #FFF6E0; color: #8A5A00; border: 1px solid #FFE0A0; }
.alert-info { background: #E5F7F7; color: #00666A; border: 1px solid #BDEBEB; }
:root[data-theme="dark"] .alert-success { background: #123321; }
:root[data-theme="dark"] .alert-danger { background: #3A1614; }
:root[data-theme="dark"] .alert-warning { background: #3A2A05; }
:root[data-theme="dark"] .alert-info { background: #0F2E2E; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); }
.empty-state .es-icon { font-size: 2.6rem; margin-bottom: 10px; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.section-title h2 { font-size: 1.15rem; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filter-bar select, .filter-bar input { width: auto; flex: 1 1 130px; padding: 10px 12px; font-size: 0.88rem; }

.tab-strip { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.tab-strip a {
    padding: 9px 16px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-alt);
    color: var(--text-main);
    font-weight: 700;
    font-size: 0.82rem;
    white-space: nowrap;
    border: 1px solid var(--border-color);
}
.tab-strip a.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.avatar-circle {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-secondary), var(--color-accent-blue));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800;
    flex-shrink: 0;
}

.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb-grid .thumb { position: relative; border-radius: var(--radius-md); overflow: hidden; aspect-ratio: 1; background: var(--bg-surface-alt); border: 1px solid var(--border-color); }
.thumb-grid .thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-grid .thumb .thumb-caption { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.55); color: #fff; font-size: 0.65rem; padding: 3px 5px; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--color-primary); }
.slider-row .slider-value { min-width: 44px; text-align: right; font-weight: 800; color: var(--color-primary-dark); }

hr.sep { border: none; border-top: 1px solid var(--border-color); margin: 16px 0; }

.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

.chart-wrap { position: relative; width: 100%; }
canvas { max-width: 100%; }

.link-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border-color); }
.link-row:last-child { border-bottom: none; }

@media (max-width: 420px) {
    .form-row { grid-template-columns: 1fr; }
    .auth-box { padding: 26px 18px; }
}

/* =====================================================================
   v2 additions
   ===================================================================== */

/* ---------- Text size scaling ---------- */
:root { --font-scale: 1; }
:root[data-textsize="small"] { --font-scale: 0.9; }
:root[data-textsize="medium"] { --font-scale: 1; }
:root[data-textsize="large"] { --font-scale: 1.18; }
.app-shell, .auth-box { font-size: calc(1rem * var(--font-scale)); }

/* ---------- RTL (Urdu) ---------- */
html[dir="rtl"] .record-card { border-left: none; border-right: 5px solid var(--color-primary); }
html[dir="rtl"] .bottom-nav a { direction: rtl; }
html[dir="rtl"] .fab { right: auto; left: 18px; }

/* ---------- Month selector ---------- */
.month-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 8px 12px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-soft);
}
.month-selector .ms-arrow {
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--color-primary);
    padding: 2px 10px;
    line-height: 1;
}
.month-selector .ms-label { flex: 1; text-align: center; font-weight: 800; }
.month-selector .ms-all {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 6px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-alt);
    color: var(--text-muted);
}
.month-selector .ms-all.active { background: var(--color-primary); color: #fff; }

/* ---------- Sticky today's total bar ---------- */
.sticky-total-bar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    margin-bottom: 12px;
    box-shadow: var(--shadow-soft);
}
.sticky-total-bar .stb-value { font-size: 1.1rem; font-weight: 900; }

/* ---------- Swipe-to-reveal list rows ---------- */
.swipe-wrap { position: relative; overflow: hidden; border-radius: var(--radius-md); margin-bottom: 10px; }
.swipe-actions {
    position: absolute; top: 0; right: 0; bottom: 0;
    display: flex; align-items: stretch;
}
.swipe-actions button {
    border: none; color: #fff; font-weight: 700; font-size: 0.8rem;
    padding: 0 18px; display: flex; align-items: center; gap: 4px;
}
.swipe-actions .swipe-edit { background: var(--color-secondary); }
.swipe-actions .swipe-delete { background: var(--color-danger); }
.swipe-wrap .record-card { position: relative; z-index: 2; transition: transform 0.15s ease; touch-action: pan-y; margin-bottom: 0; background: var(--bg-surface); }

/* ---------- Undo toast ---------- */
.undo-toast {
    position: fixed;
    left: 50%; transform: translateX(-50%);
    bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
    background: #222;
    color: #fff;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; gap: 14px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-strong);
    z-index: 60;
    max-width: 90vw;
}
.undo-toast button { background: none; border: none; color: var(--color-amber); font-weight: 800; font-size: 0.85rem; }

/* ---------- Bottom sheet ---------- */
.sheet-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 70;
    display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
    background: var(--bg-surface);
    width: 100%; max-width: 720px;
    max-height: 88vh; overflow-y: auto;
    border-radius: 22px 22px 0 0;
    padding: 10px 18px 26px;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.3);
    animation: sheet-up 0.2s ease;
}
.sheet-handle { width: 40px; height: 5px; background: var(--border-color); border-radius: 3px; margin: 8px auto 14px; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ---------- Pull to refresh ---------- */
.ptr-indicator {
    text-align: center; font-size: 0.78rem; color: var(--text-muted);
    height: 0; overflow: hidden; transition: height 0.15s ease;
}
.ptr-indicator.active { height: 34px; }

/* ---------- Chips (recent contacts, quick picks) ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; margin: 6px 0 14px; }
.chip {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
}
.chip.active { background: var(--color-secondary); color: #fff; border-color: var(--color-secondary); }

/* ---------- Offline / sync indicator ---------- */
.sync-banner {
    background: var(--color-amber);
    color: #3a2a00;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: none;
}
.sync-banner.show { display: block; }

/* ---------- Weather / map cards ---------- */
.weather-card { display: flex; align-items: center; gap: 14px; }
.weather-card .weather-temp { font-size: 1.8rem; font-weight: 900; color: var(--color-primary-dark); }
.map-embed { width: 100%; height: 220px; border: 0; border-radius: var(--radius-md); }

/* ---------- Spend heatmap ---------- */
.heatmap-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heatmap-cell { aspect-ratio: 1; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 0.62rem; color: var(--text-muted); }

/* ---------- QR box ---------- */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qr-box canvas { border-radius: var(--radius-md); border: 1px solid var(--border-color); }

/* ---------- Data saver notice ---------- */
.data-saver-notice { font-size: 0.78rem; color: var(--text-muted); text-align: center; padding: 20px; }
