/* ============================================================================
   همسایه — Design System
   Teal / petrol-blue theme, RTL, Vazirmatn. Shared by landing, admin & panel.
   ============================================================================ */

:root {
    /* Brand — teal / petrol blue */
    --teal-50:  #eafbf8;
    --teal-100: #cdf3ec;
    --teal-200: #9fe6db;
    --teal-300: #66d3c5;
    --teal-400: #2fb8a8;
    --teal-500: #109e8e;   /* primary */
    --teal-600: #0a7e74;
    --teal-700: #0c655e;
    --teal-800: #0f504c;
    --teal-900: #0c3a38;

    --petrol:   #0d3b40;   /* deep header / sidebar */
    --petrol-2: #0a2d31;

    --accent:   #f5a623;   /* warm accent for CTAs/highlights */
    --accent-2: #ffce6b;

    --ok:       #1f9d57;
    --ok-bg:    #e6f6ec;
    --danger:   #d64545;
    --danger-bg:#fbeaea;
    --warn:     #c9870a;
    --warn-bg:  #fdf3e0;
    --info:     #2f7cc0;

    --bg:       #f4f7f8;
    --surface:  #ffffff;
    --surface-2:#f8fafb;
    --line:     #e4eaec;
    --line-2:   #eef2f3;

    --text:     #122024;
    --muted:    #5d7178;
    --muted-2:  #8aa0a6;

    --radius:   16px;
    --radius-sm:10px;
    --radius-lg:24px;
    --shadow:   0 6px 24px rgba(13, 59, 64, .08);
    --shadow-lg:0 18px 50px rgba(13, 59, 64, .16);
    --ring:     0 0 0 4px rgba(16, 158, 142, .18);

    --header-h: 64px;
    --drawer-w: 280px;

    --font: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

body { font-size: 15px; }

a { color: var(--teal-600); text-decoration: none; }
a:hover { color: var(--teal-700); }
.ui-icon { width: 1.2em; height: 1.2em; display: inline-block; flex: 0 0 auto; vertical-align: -.18em; }
.btn > .ui-icon { width: 1.15rem; height: 1.15rem; }
.btn-icon > .ui-icon { width: 1.25rem; height: 1.25rem; }

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 800; line-height: 1.4; }
p { margin: 0 0 1em; }

img { max-width: 100%; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cdd9dc; border-radius: 10px; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.container-narrow { max-width: 760px; }

/* ── Buttons ──────────────────────────────────────────────────────────────*/
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-family: inherit; font-size: 15px; font-weight: 700;
    padding: 11px 22px; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer; transition: .18s;
    background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--teal-500); color: #fff; box-shadow: 0 8px 20px rgba(16,158,142,.28); }
.btn-primary:hover { background: var(--teal-600); color: #fff; }
.btn-accent { background: var(--accent); color: #3a2a00; box-shadow: 0 8px 20px rgba(245,166,35,.3); }
.btn-accent:hover { background: var(--accent-2); color: #3a2a00; }
.btn-outline { background: transparent; border-color: #d5d5d5; color: var(--text); }
.btn-outline:hover { border-color: var(--teal-400); color: var(--teal-700); }
.btn-ghost { background: transparent; color: var(--muted); border-color: #d5d5d5; }
.btn-ghost:hover { background: var(--line-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c23b3b; color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 9px; }
.btn-lg { padding: 14px 30px; font-size: 17px; }
.btn-block { width: 100%; }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-icon { padding: 8px; width: 38px; height: 38px; border-radius: 9px; }
/* Replace the browser's harsh dark focus outline with a soft teal ring. */
.btn:focus { outline: none; }
.btn:focus-visible { outline: 2px solid var(--teal-200); outline-offset: 2px; }
/* Close (×) icon buttons: borderless, gentle hover. */
.btn-icon.btn-ghost { border: none; color: var(--muted-2); }
.btn-icon.btn-ghost:hover { background: var(--line-2); color: var(--text); }

/* ── Cards ────────────────────────────────────────────────────────────────*/
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line-2);
}
.card-head h3 { margin: 0; font-size: 17px; }
.card-body { padding: 22px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::after {
    content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 5px;
    background: var(--teal-400);
}
.stat.is-pay::after { background: var(--ok); }
.stat.is-fund::after { background: var(--accent); }
.stat.is-expense::after { background: var(--danger); }
.stat.is-debt::after { background: var(--info); }

/* Four-card row (cards above the dashboard / board chart) */
.stat-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
@media (max-width: 980px) { .stat-grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stat-grid-4 { grid-template-columns: 1fr; } }
.stat .stat-label { color: var(--muted); font-size: 13.5px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.stat .stat-value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.stat .stat-value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-inline-start: 4px; }
.stat .stat-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--teal-50); color: var(--teal-600); position: absolute; top: 18px; inset-inline-end: 18px; }

/* ── Forms ────────────────────────────────────────────────────────────────*/
.field { margin-bottom: 16px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 620px) { .form-grid-2 { grid-template-columns: 1fr; } }
.field > label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 7px; color: #29393d; }
.field .hint { color: var(--muted-2); font-size: 12px; margin-top: 5px; }
.input, .select, .textarea {
    width: 100%; font-family: inherit; font-size: 15px; color: var(--text);
    background: var(--surface); border: 1.5px solid var(--line);
    border-radius: var(--radius-sm); padding: 11px 14px; transition: .15s;
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--teal-400); box-shadow: var(--ring); }
.input::placeholder { color: var(--muted-2); }
/* Genuinely locked fields look disabled; date-pickers use readonly but stay clickable. */
.input[readonly]:not(.jdate):not(.jmonth), .select:disabled, .input:disabled { background: var(--surface-2); color: var(--muted-2); cursor: not-allowed; }
@media (max-width: 820px) {
    .hide-mobile { display: none !important; }
    /* On mobile the dashboard pay button drops below the welcome, full width. */
    .welcome { flex-wrap: wrap; }
    .dash-pay-btn { width: 100%; }
}
/* Current-document preview in edit forms (small thumbnail + remove button). */
.doc-thumb-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.doc-thumb { max-width: 90px; max-height: 90px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; display: block; }
.doc-thumb-pdf { display: inline-flex; align-items: center; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 13px; }
.input-group { display: flex; }
.input-group .input { border-start-start-radius: 0; border-end-start-radius: 0; }
.input-group .addon {
    display: grid; place-items: center; padding: 0 14px; background: var(--surface-2);
    border: 1.5px solid var(--line); border-inline-end: none;
    border-start-start-radius: var(--radius-sm); border-end-start-radius: var(--radius-sm); color: var(--muted); font-size: 13px;
}
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 6px; }
.input.has-error, .select.has-error { border-color: var(--danger); }

.radio-cards { display: grid; gap: 10px; }
.radio-card {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer;
    border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); transition: .15s;
}
.radio-card:hover { border-color: var(--teal-300); }
.radio-card input { accent-color: var(--teal-500); width: 18px; height: 18px; }
.radio-card.is-checked { border-color: var(--teal-400); background: var(--teal-50); }
.period-choice__label { display:inline-flex;align-items:center;gap:7px; }
.period-discount { color:var(--danger);font-size:11px;font-weight:800;white-space:nowrap; }
.period-choice__prices { display:flex;flex-direction:column;align-items:flex-end;line-height:1.5;white-space:nowrap; }
.period-choice__prices del { color:var(--muted);font-size:11px;opacity:.72; }
.period-final { color:var(--teal-700);font-size:13px;font-weight:800; }

.check {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
}
.check input { width: 17px; height: 17px; accent-color: var(--teal-500); }

/* ── Tables ───────────────────────────────────────────────────────────────*/
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }
.table thead th {
    text-align: right; font-weight: 700; color: var(--muted); font-size: 12.5px;
    padding: 13px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table tbody td { padding: 13px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.table-empty { text-align: center; color: var(--muted-2); padding: 40px 20px; }

/* ── Badges / pills ───────────────────────────────────────────────────────*/
.badge {
    display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700;
    padding: 4px 10px; border-radius: 999px; background: var(--line-2); color: var(--muted);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-teal { background: var(--teal-50); color: var(--teal-700); }
.badge-accent { background: #fdeccd; color: #9a6b06; }

.amount-pos { color: var(--danger); font-weight: 700; }   /* owes */
.amount-neg { color: var(--ok); font-weight: 700; }       /* credit / paid */

/* ── Flash / toast ────────────────────────────────────────────────────────*/
.flash-stack { position: fixed; top: 16px; inset-inline-start: 50%; transform: translateX(50%); z-index: 1200; display: flex; flex-direction: column; gap: 10px; width: min(92vw, 440px); }
.flash {
    display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-radius: 12px;
    background: var(--surface); box-shadow: var(--shadow-lg); border-inline-start: 5px solid var(--teal-400);
    animation: flashIn .3s ease;
}
.flash.success { border-color: var(--ok); }
.flash.error { border-color: var(--danger); }
.flash.warning { border-color: var(--warn); }
@keyframes flashIn { from { opacity: 0; transform: translate(50%, -10px); } to { opacity: 1; } }

/* ── Lightbox (document/image viewer) ─────────────────────────────────────*/
.lightbox { position: fixed; inset: 0; background: rgba(10,45,49,.82); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 1300; padding: 24px; }
.lightbox.open { display: flex; animation: flashIn .2s ease; }
.lightbox__inner { position: relative; display: flex; align-items: center; justify-content: center; max-width: 96vw; max-height: 92vh; }
.lightbox__img { max-width: 96vw; max-height: 92vh; border-radius: 10px; box-shadow: var(--shadow-lg); object-fit: contain; background: #fff; }
.lightbox__pdf { width: min(900px, 96vw); height: 92vh; border: none; border-radius: 10px; background: #fff; box-shadow: var(--shadow-lg); }
.lightbox__close { position: fixed; top: 16px; inset-inline-end: 16px; width: 42px; height: 42px; border-radius: 50%; border: none; background: #fff; color: var(--text); font-size: 18px; cursor: pointer; box-shadow: var(--shadow-lg); display: grid; place-items: center; z-index: 2; }
.lightbox__close:hover { background: var(--line-2); }
.lightbox__newtab { position: fixed; bottom: 16px; inset-inline-start: 50%; transform: translateX(50%); color: #fff; font-size: 13px; font-weight: 700; background: rgba(0,0,0,.35); padding: 7px 14px; border-radius: 999px; }
.lightbox__newtab:hover { color: #fff; background: rgba(0,0,0,.5); }

/* ── Pagination ───────────────────────────────────────────────────────────*/
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 38px; height: 38px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
}
.pagination a:hover { border-color: var(--teal-400); }
.pagination .active { background: var(--teal-500); color: #fff; border-color: var(--teal-500); }
.pagination .disabled { opacity: .45; pointer-events: none; }

/* ── Brand mark (shared: logo box + name) ─────────────────────────────────*/
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); }
.brand__logo {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px;
    display: grid; place-items: center; overflow: hidden;
    background: linear-gradient(135deg, var(--teal-400), var(--teal-600));
    color: #fff; font-size: 17px; line-height: 1; padding: 6px;
    box-shadow: 0 6px 14px rgba(16,158,142,.35);
}
/* Uploaded-logo variant: white tile so any logo reads on light & dark headers. */
.brand__logo--img { background: #fff; box-shadow: 0 4px 12px rgba(13,59,64,.16); padding: 4px; }
.brand__logo--img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand__name { font-size: 19px; }
.brand--light { color: #fff; }

/* ── Hamburger button (shared) ────────────────────────────────────────────*/
.hamburger {
    display: inline-flex; flex-direction: column; gap: 5px;
    width: 42px; height: 42px; padding: 0; flex: 0 0 auto;
    border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
    cursor: pointer; align-items: center; justify-content: center;
}
.hamburger span { display: block; width: 20px; height: 2.2px; background: var(--text); border-radius: 2px; transition: .2s; }

/* ── Drawer (slide-in hamburger menu) ─────────────────────────────────────*/
.drawer-backdrop {
    position: fixed; inset: 0; background: rgba(10, 45, 49, .45); backdrop-filter: blur(2px);
    opacity: 0; visibility: hidden; transition: .25s; z-index: 1000;
}
.drawer-backdrop.open { opacity: 1; visibility: visible; }
.drawer {
    position: fixed; top: 0; bottom: 0; inset-inline-end: calc(-1 * var(--drawer-w)); width: var(--drawer-w);
    background: var(--surface); box-shadow: var(--shadow-lg); z-index: 1001;
    transition: transform .28s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(calc(-1 * var(--drawer-w))); }
[dir="rtl"] .drawer { inset-inline-end: auto; right: calc(-1 * var(--drawer-w)); }
[dir="rtl"] .drawer.open { transform: translateX(calc(-1 * var(--drawer-w))); }

/* Shared drawer header (brand + close button). */
.drawer__head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 18px; border-bottom: 1px solid var(--line-2);
}

/* ── Utilities ────────────────────────────────────────────────────────────*/
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.fw-700 { font-weight: 700; }
.hidden { display: none !important; }
.grid { display: grid; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--line-2); margin: 16px 0; }

/* ── Lightbox (document/image viewer) ─────────────────────────────────────*/
.lightbox {
    position: fixed; inset: 0; z-index: 1300; display: none;
    align-items: center; justify-content: center; padding: 24px;
    background: rgba(10, 45, 49, .8); backdrop-filter: blur(3px);
}
.lightbox.open { display: flex; animation: flashIn .2s ease; }
.lightbox__inner { position: relative; max-width: 94vw; max-height: 92vh; }
.lightbox__inner img { max-width: 94vw; max-height: 92vh; border-radius: 12px; box-shadow: var(--shadow-lg); display: block; }
.lightbox__inner iframe { width: 90vw; height: 88vh; border: none; border-radius: 12px; background: #fff; box-shadow: var(--shadow-lg); }
.lightbox__close {
    position: fixed; top: 18px; inset-inline-end: 18px; width: 44px; height: 44px;
    border-radius: 50%; background: #fff; border: none; cursor: pointer; font-size: 20px;
    display: grid; place-items: center; box-shadow: var(--shadow); color: var(--text);
}
.lightbox__close:hover { background: var(--line-2); }

/* ── Error pages ──────────────────────────────────────────────────────────*/
.error-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--teal-50), var(--bg)); }
.error-box { text-align: center; background: var(--surface); padding: 48px 40px; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); max-width: 440px; }
.error-code { font-size: 64px; font-weight: 900; color: var(--teal-500); letter-spacing: 2px; }
.error-box h1 { font-size: 22px; }
.error-box p { color: var(--muted); }

/* responsive */
@media (max-width: 820px) {
    .stat-grid { grid-template-columns: 1fr; }
}
