/* ===================================================================
   Sardar Plaza Management System - Custom Responsive Stylesheet
   No external CDN so the app works fully offline (PWA).
   =================================================================== */

:root {
    --primary: #1e3a5f;
    --primary-dark: #16293f;
    --accent: #c9a227;
    --bg: #f4f6f9;
    --card: #ffffff;
    --text: #24303f;
    --muted: #7b8794;
    --border: #e2e8f0;
    --green: #1a9d5a;
    --red: #d9463e;
    --orange: #e08e0b;
    --blue: #2a74d4;
    --gray: #8a94a6;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--primary);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .25s ease;
    overflow-y: auto;
}

.sidebar .brand {
    padding: 20px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar .brand img { width: 40px; height: 40px; border-radius: 8px; background:#fff; object-fit: contain; }
.sidebar .brand h1 { font-size: 17px; font-weight: 700; line-height: 1.1; }
.sidebar .brand span { font-size: 11px; color: var(--accent); }

.nav { padding: 12px 0; flex: 1; }
.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #cfd8e3;
    font-size: 14.5px;
    border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--accent); }
.nav a .icon { width: 20px; text-align: center; font-size: 16px; }
.nav .divider { padding: 14px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #8ea3bd; }

.main { flex: 1; margin-left: 250px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    background: var(--card);
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 500;
}
.topbar .menu-btn { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--primary); }
.topbar .page-title { font-size: 18px; font-weight: 600; }
.topbar .user-box { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar .user-box .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 600;
}

.content { padding: 22px; flex: 1; }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card h3 { font-size: 16px; margin-bottom: 16px; }
.card-header { display:flex; justify-content: space-between; align-items:center; margin-bottom:16px; flex-wrap: wrap; gap: 10px;}
.card-header h3 { margin-bottom: 0; }

/* ---------- Stats grid ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 22px; }
.stat {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat .stat-icon {
    width: 52px; height: 52px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; color: #fff; flex-shrink: 0;
}
.stat .stat-info .value { font-size: 24px; font-weight: 700; }
.stat .stat-info .label { font-size: 13px; color: var(--muted); }
.bg-primary { background: var(--primary); }
.bg-green { background: var(--green); }
.bg-red { background: var(--red); }
.bg-orange { background: var(--orange); }
.bg-blue { background: var(--blue); }
.bg-accent { background: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
table.data tr:hover td { background: #fafbfc; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-green { background: #e3f6ec; color: var(--green); }
.badge-red { background: #fdecea; color: var(--red); }
.badge-orange { background: #fdf1dd; color: var(--orange); }
.badge-blue { background: #e6f0fc; color: var(--blue); }
.badge-blue2 { background: #eae6fc; color: #5b3fd4; }
.badge-gray { background: #eef1f5; color: var(--gray); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: none;
    font-size: 14px; font-weight: 600; cursor: pointer;
    background: var(--primary); color: #fff; text-decoration: none;
    transition: background .15s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-accent { background: var(--accent); color: #3a2e00; }
.btn-accent:hover { background: #b28f1f; color: #3a2e00; }
.btn-green { background: var(--green); }
.btn-green:hover { background: #157a46; }
.btn-red { background: var(--red); }
.btn-red:hover { background: #b5362f; }
.btn-light { background: #eef1f5; color: var(--text); }
.btn-light:hover { background: #e2e8f0; color: var(--text); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.1);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-actions { margin-top: 8px; display: flex; gap: 10px; }
.required { color: var(--red); }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #e3f6ec; color: #157a46; border: 1px solid #b6e6c9; }
.alert-danger  { background: #fdecea; color: #b5362f; border: 1px solid #f5c6c2; }
.alert-info    { background: #e6f0fc; color: #1c5ba8; border: 1px solid #c2d9f5; }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); padding: 20px; }
.login-box { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 400px; box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.login-box .logo { text-align: center; margin-bottom: 20px; }
.login-box .logo img { width: 70px; height: 70px; border-radius: 12px; object-fit: contain; }
.login-box h2 { text-align: center; margin-bottom: 4px; color: var(--primary); }
.login-box .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-box .btn { width: 100%; justify-content: center; padding: 12px; }

/* ---------- Misc ---------- */
.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 16px; } .mt-2 { margin-top: 16px; }
.flex { display: flex; } .gap { gap: 10px; } .between { justify-content: space-between; }
.wrap { flex-wrap: wrap; } .items-center { align-items: center; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 42px; margin-bottom: 8px; }

.dev-footer { text-align: center; padding: 16px; font-size: 11px; color: #b3bccb; }
.dev-footer a { color: #b3bccb; }

/* Notification bell */
.notif-bell { position: relative; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--primary); background: #eef1f5; text-decoration: none; }
.notif-bell:hover { background: #e2e8f0; text-decoration: none; }
.notif-badge { position: absolute; top: -2px; right: -2px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.notif-item { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.notif-item.unread { background: #f1f6ff; margin: 0 -20px; padding: 12px 20px; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); margin-top: 6px; flex-shrink: 0; }

/* Online/offline indicator */
.net-indicator { position: fixed; bottom: 16px; left: 16px; z-index: 2000; padding: 8px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; box-shadow: var(--shadow); display: none; align-items: center; gap: 7px; }
.net-indicator.show { display: inline-flex; }
.net-offline { background: var(--red); color: #fff; }
.net-syncing { background: var(--orange); color: #fff; }
.net-synced { background: var(--green); color: #fff; }
[dir="rtl"] .net-indicator { left: auto; right: 16px; }

/* ---------- Overlay for mobile sidebar ---------- */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 999; }
.overlay.show { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar .menu-btn { display: block; }
}

@media (max-width: 560px) {
    .content { padding: 14px; }
    .card { padding: 16px; }
    .topbar .user-box .uname { display: none; }
    .stat .stat-info .value { font-size: 20px; }
}

/* ---------- Print (invoice) ---------- */
@media print {
    .sidebar, .topbar, .no-print, .dev-footer { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; }
}

/* ===================================================================
   Consistent dropdowns (native select styled like inputs)
   =================================================================== */
select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%237b8794' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 30px !important; cursor: pointer;
    border: 1px solid var(--border); border-radius: 8px; background-color: #fff;
    font-family: inherit; font-size: 14px; color: var(--text);
}
select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,.1); }
[dir="rtl"] select { background-position: left 12px center; padding-right: 12px !important; padding-left: 30px !important; }

/* ===================================================================
   File preview modal (lightbox)
   =================================================================== */
.fp-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 3000; align-items: center; justify-content: center; padding: 20px; }
.fp-modal.show { display: flex; }
.fp-inner { background: #fff; border-radius: 12px; max-width: 900px; width: 100%; max-height: 92vh; overflow: hidden; display: flex; flex-direction: column; }
.fp-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.fp-head .fp-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.fp-body { flex: 1; overflow: auto; background: #f4f6f9; display: flex; align-items: center; justify-content: center; }
.fp-body img { max-width: 100%; max-height: 82vh; display: block; }
.fp-body iframe { width: 100%; height: 82vh; border: 0; }

/* ===================================================================
   PWA install button
   =================================================================== */
.install-btn { display: none; }
.install-btn.show { display: inline-flex; }

/* ===================================================================
   Responsive data tables -> stacked cards on phones/tablets
   =================================================================== */
@media (max-width: 768px) {
    .table-wrap { overflow-x: visible; }
    table.data { border: 0; }
    table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    table.data tr { display: block; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; padding: 6px 14px; background: #fff; }
    table.data tr:hover td { background: transparent; }
    table.data td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 8px 0; border: 0; border-bottom: 1px dashed var(--border);
        white-space: normal; text-align: right;
    }
    table.data td:last-child { border-bottom: 0; }
    table.data td::before {
        content: attr(data-label); font-weight: 600; color: var(--muted);
        font-size: 12px; text-transform: uppercase; letter-spacing: .3px; text-align: left; flex-shrink: 0;
    }
    table.data td.no-label { display: block; text-align: left; }
    table.data td.no-label::before { content: ""; }
    table.data td.text-right { text-align: right; }
    /* action button cells wrap nicely */
    table.data td .btn { margin: 2px 0 2px 4px; }
    /* forms: single column on phones */
    .form-grid { grid-template-columns: 1fr; }
    .split { grid-template-columns: 1fr !important; }
    .dash-grid { grid-template-columns: 1fr !important; }
    .stats { grid-template-columns: 1fr 1fr; }
    .card { padding: 14px; }
    /* any inline 2-col grid collapses */
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}

/* ===================================================================
   Deep responsive polish (tablet + phone) + text overflow fixes
   =================================================================== */
/* Never let content force horizontal page scroll */
html, body { max-width: 100%; overflow-x: hidden; }
.content, .card, .portal-wrap { max-width: 100%; }
/* Long references, codes, URLs, emails wrap instead of overflowing */
.card, table.data td, .r-row, .verify, .verify-box, .stat-info { overflow-wrap: anywhere; word-break: break-word; }
code, .mono { overflow-wrap: anywhere; }

@media (max-width: 1024px) {
    /* tablet: shrink stat numbers a touch, allow 2-up stats */
    .stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

@media (max-width: 768px) {
    body { font-size: 14.5px; }
    .topbar { padding: 0 14px; }
    .topbar .page-title { font-size: 16px; }
    .topbar .user-box { gap: 7px; }
    .topbar .user-box .btn { padding: 6px 9px; }
    .card-header { align-items: flex-start; }
    .card-header h3 { font-size: 15px; }
    /* stat cards more compact */
    .stat { padding: 15px; gap: 12px; }
    .stat .stat-icon { width: 44px; height: 44px; font-size: 18px; }
    .stat .stat-info .value { font-size: 19px; }
    /* buttons in headers wrap */
    .card-header .flex, .card-header form { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .stats { grid-template-columns: 1fr; }
    .stat .stat-info .value { font-size: 22px; }
    .btn { padding: 9px 13px; }
    .btn-sm { padding: 7px 11px; }
    /* full-width primary action buttons on tiny screens */
    .form-actions { flex-wrap: wrap; }
    .form-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ===================================================================
   Copy-to-clipboard button (bank details)
   =================================================================== */
.copy-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.copy-btn { background: #eef1f5; border: 1px solid var(--border); color: var(--primary); cursor: pointer;
    border-radius: 8px; padding: 6px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.copy-btn:hover { background: #e2e8f0; }
.copy-btn.copied { background: #e3f6ec; color: var(--green); border-color: #b6e6c9; }

/* ===================================================================
   PWA install card + instructions
   =================================================================== */
.install-card { display: none; }
.install-card.show { display: block; }
.install-card .steps { font-size: 13px; color: var(--muted); margin-top: 10px; line-height: 1.7; }
.install-card .steps b { color: var(--text); }
