:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --info: #0891b2;
    --info-bg: #cffafe;
    --sidebar-w: 250px;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
    --shadow-sm: 0 1px 2px rgba(15,23,42,.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", Roboto, "Noto Naskh Arabic", "Segoe UI Historic", Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout shell ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #cbd5e1;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .25s ease;
}
.brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.15rem 1.25rem;
    color: #fff; font-weight: 700; font-size: 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand .logo {
    width: 38px; height: 38px; border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), #38bdf8);
    display: grid; place-items: center; color: #fff; font-size: 1.15rem;
    box-shadow: 0 6px 16px rgba(37,99,235,.45);
}
.brand small { display:block; font-weight: 400; font-size: .7rem; color: #94a3b8; letter-spacing: .12em; text-transform: uppercase; }

.nav { padding: .75rem; display: flex; flex-direction: column; gap: .15rem; overflow-y: auto; flex: 1; }
.nav .section { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: #64748b; padding: .9rem .8rem .35rem; }
.nav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .62rem .8rem; border-radius: 10px;
    color: #cbd5e1; font-weight: 500; text-decoration: none;
    transition: background .15s, color .15s;
}
.nav a i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(37,99,235,.4); }

.sidebar-foot { padding: .9rem 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .78rem; color: #94a3b8; }

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

.topbar {
    position: sticky; top: 0; z-index: 30;
    background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 1rem;
    padding: .8rem 1.5rem;
}
.topbar h1 { font-size: 1.2rem; margin: 0; font-weight: 700; display: flex; align-items: center; gap: .55rem; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .88rem; }
.topbar .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color:#fff; display: grid; place-items: center; font-weight: 600; }
.hamburger { display: none; background: none; border: 0; font-size: 1.4rem; color: var(--ink); cursor: pointer; }

.main { padding: 1.5rem; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .5rem .9rem; border-radius: 10px; border: 1px solid transparent;
    font-weight: 600; font-size: .88rem; cursor: pointer; background: var(--surface);
    color: var(--ink); text-decoration: none; transition: all .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color:#fff; }
.btn-outline { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--line); }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .6rem; }
.card-head h2 { font-size: 1rem; margin: 0; font-weight: 700; display:flex; align-items:center; gap:.5rem; }
.card-head .spacer { flex: 1; }
.card-body { padding: 1.25rem; }
.card-body.flush { padding: 0; }

/* ---------- KPI grid ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; margin-bottom: .8rem; }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.7rem; font-weight: 800; margin-top: .15rem; letter-spacing: -.02em; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.kpi .unit { font-size: .95rem; font-weight: 600; color: var(--muted); margin-left: .25rem; }
.ic.blue { background: #dbeafe; color: #2563eb; }
.ic.green { background: var(--success-bg); color: var(--success); }
.ic.red { background: var(--danger-bg); color: var(--danger); }
.ic.amber { background: var(--warning-bg); color: var(--warning); }
.ic.cyan { background: var(--info-bg); color: var(--info); }
.ic.violet { background: #ede9fe; color: #7c3aed; }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 1.25rem; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: 2fr 1fr; }
@media (max-width: 992px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .62rem .8rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data thead th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; }
table.data tbody tr:hover { background: #f8fafc; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.money { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge.green { background: var(--success-bg); color: var(--success); }
.badge.red { background: var(--danger-bg); color: var(--danger); }
.badge.amber { background: var(--warning-bg); color: var(--warning); }
.badge.blue { background: #dbeafe; color: var(--primary); }
.badge.slate { background: #e2e8f0; color: #475569; }
.chip { display:inline-block; padding:.15rem .5rem; border-radius:8px; background:#eef2ff; color:#4338ca; font-weight:700; font-size:.8rem; }

/* ---------- Bars (mini chart) ---------- */
.bars { display: flex; align-items: flex-end; gap: .5rem; height: 180px; padding-top: .5rem; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem; height: 100%; justify-content: flex-end; }
.bars .bar .fill { width: 100%; max-width: 34px; background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 6px 6px 0 0; min-height: 3px; transition: height .3s; }
.bars .bar .xl { font-size: .7rem; color: var(--muted); }
.bars .bar .vl { font-size: .68rem; color: var(--ink); font-weight: 600; }

/* ---------- Progress (payments by type) ---------- */
.plist { display: flex; flex-direction: column; gap: .8rem; }
.plist .row { display: flex; flex-direction: column; gap: .3rem; }
.plist .row .top { display: flex; justify-content: space-between; font-size: .85rem; }
.plist .track { height: 8px; border-radius: 999px; background: #eef2f7; overflow: hidden; }
.plist .track > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2563eb, #38bdf8); }

/* ---------- Toolbar / search ---------- */
.toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.search { position: relative; }
.search input { padding: .55rem .8rem .55rem 2.2rem; border: 1px solid var(--line); border-radius: 10px; min-width: 260px; font-size: .9rem; background: var(--surface); }
.search i { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ---------- Detail definition list ---------- */
.dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .9rem 1.5rem; }
.dl .item .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.dl .item .v { font-size: .98rem; font-weight: 500; margin-top: .1rem; word-break: break-word; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: .4rem; justify-content: center; margin-top: 1.1rem; flex-wrap: wrap; }
.pager a, .pager span { padding: .4rem .7rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: .85rem; color: var(--ink); }
.pager a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pager .cur { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .disabled { color: #cbd5e1; }

/* ---------- Object cards (data browser) ---------- */
.obj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.obj {
    display: flex; gap: .85rem; align-items: flex-start; padding: 1rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); text-decoration: none; color: var(--ink); transition: transform .12s, box-shadow .12s, border-color .12s;
}
.obj:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #c7d2fe; text-decoration: none; }
.obj .ic { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 1.2rem; background: #eef2ff; color: #4338ca; flex: 0 0 auto; }
.obj .t { font-weight: 700; }
.obj .d { font-size: .8rem; color: var(--muted); margin-top: .15rem; line-height: 1.35; }
.obj .n { font-size: .72rem; color: #94a3b8; margin-top: .3rem; font-family: ui-monospace, monospace; }

/* ---------- Alerts ---------- */
.alert { padding: .9rem 1.1rem; border-radius: 12px; border: 1px solid; display: flex; gap: .6rem; align-items: flex-start; }
.alert.warn { background: var(--warning-bg); border-color: #fcd34d; color: #92400e; }
.alert.err { background: var(--danger-bg); border-color: #fca5a5; color: #991b1b; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty i { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }

.pagetitle-sub { color: var(--muted); font-weight: 400; font-size: .95rem; }

/* ---------- Print header (hidden on screen) ---------- */
.print-only { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    body.nav-open .sidebar { transform: translateX(0); }
    .content { margin-left: 0; }
    .hamburger { display: block; }
    body.nav-open::after { content:""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
}

/* ---------- Add/Edit modal ---------- */
.mm-overlay {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(15,23,42,.55); backdrop-filter: blur(3px);
    display: none; align-items: flex-start; justify-content: center; padding: 4vh 1rem;
    overflow-y: auto;
}
.mm-overlay.open { display: flex; }
.mm-dialog {
    background: var(--surface); border-radius: 16px; width: 100%; max-width: 640px;
    box-shadow: 0 30px 70px rgba(0,0,0,.4); overflow: hidden; animation: mm-in .18s ease;
}
@keyframes mm-in { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.mm-head { display: flex; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.mm-head h3 { margin: 0; font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; flex: 1; }
.mm-x { background: none; border: 0; font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: .3rem; border-radius: 8px; }
.mm-x:hover { background: var(--line); color: var(--ink); }
.mm-body { padding: 1.25rem; max-height: 66vh; overflow-y: auto; }
.mm-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); background: #f8fafc; }
.mm-loading { text-align: center; color: var(--muted); padding: 2rem; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* form grid inside modal */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.fld { display: flex; flex-direction: column; gap: .35rem; }
.fld.fld-wide { grid-column: 1 / -1; }
.fld label { font-size: .78rem; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.fld label .req { color: var(--danger); }
.fld label .hint { margin-left: auto; font-weight: 400; font-size: .72rem; color: #94a3b8; }
.fld input, .fld select, .fld textarea {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px;
    font-size: .92rem; font-family: inherit; background: var(--surface); color: var(--ink);
}
.fld input:focus, .fld select:focus, .fld textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.fld input[readonly] { background: #f1f5f9; color: var(--muted); }
.fld textarea { resize: vertical; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* searchable select */
.ss { position: relative; }
.ss-search { width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px; font-size: .92rem; font-family: inherit; background: var(--surface); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }
.ss-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.ss-menu { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); max-height: 220px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.ss-item { padding: .5rem .7rem; cursor: pointer; font-size: .9rem; }
.ss-item:hover, .ss-item.active { background: #eef2ff; }
.ss-empty { padding: .5rem .7rem; color: var(--muted); font-size: .85rem; }

/* ---------- Print ---------- */
@media print {
    @page { margin: 14mm; }
    body { background: #fff; font-size: 12px; }
    .sidebar, .topbar, .no-print, .toolbar, .pager, .hamburger { display: none !important; }
    .content { margin-left: 0; }
    .main { padding: 0; }
    .print-only { display: block; }
    .card, .kpi { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; }
    table.data thead th { position: static; }
    a { color: #000; text-decoration: none; }
    .print-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid #0f172a; padding-bottom: 8px; margin-bottom: 14px; }
    .print-head .pt { font-size: 18px; font-weight: 800; }
    .print-head .meta { font-size: 11px; color: #334155; text-align: right; }
    table.data td, table.data th { white-space: normal; }
}
