/* CRM operator panel — design system. RTL-first, Persian typography.
   Self-contained (no build step); linked from layouts/app.blade.php. */

:root {
    --brand: #4f46e5;
    --brand-600: #4338ca;
    --brand-50: #eef2ff;
    --ink: #0f172a;
    --ink-2: #1e293b;          /* headings */
    --ink-3: #475569;          /* labels / secondary buttons */
    --muted: #64748b;
    --line: #e2e8f0;
    --bg: #f1f5f9;
    --card: #ffffff;
    --card-2: #f8fafc;         /* subtle surfaces: th, row hover, code */
    --input-bg: #ffffff;
    --topbar-bg: rgba(255,255,255,.85);
    --ok: #059669; --ok-bg: #d1fae5;
    --warn: #b45309; --warn-bg: #fef3c7;
    --bad: #dc2626; --bad-bg: #fee2e2;
    --info: #2563eb; --info-bg: #dbeafe;
    --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.06);
    --shadow-lg: 0 8px 30px rgba(15,23,42,.12);
    --radius: 12px;
    --sidebar-w: 232px;
    color-scheme: light;
}

/* ---- Dark mode ----
   Explicit choice (data-theme, persisted by the topbar toggle) wins; without
   one, the OS preference applies. The sidebar is dark in both themes. */
html[data-theme="dark"] {
    --brand-50: rgba(79,70,229,.22);
    --ink: #e2e8f0;
    --ink-2: #e2e8f0;
    --ink-3: #cbd5e1;
    --muted: #94a3b8;
    --line: #253248;
    --bg: #0b1220;
    --card: #111c30;
    --card-2: #16223a;
    --input-bg: #0e1830;
    --topbar-bg: rgba(11,18,32,.85);
    --ok-bg: rgba(5,150,105,.18);
    --warn-bg: rgba(180,83,9,.2);
    --bad-bg: rgba(220,38,38,.18);
    --info-bg: rgba(37,99,235,.2);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.35);
    --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]):not([data-theme="dark"]) {
        --brand-50: rgba(79,70,229,.22);
        --ink: #e2e8f0;
        --ink-2: #e2e8f0;
        --ink-3: #cbd5e1;
        --muted: #94a3b8;
        --line: #253248;
        --bg: #0b1220;
        --card: #111c30;
        --card-2: #16223a;
        --input-bg: #0e1830;
        --topbar-bg: rgba(11,18,32,.85);
        --ok-bg: rgba(5,150,105,.18);
        --warn-bg: rgba(180,83,9,.2);
        --bad-bg: rgba(220,38,38,.18);
        --info-bg: rgba(37,99,235,.2);
        --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.35);
        --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: Vazirmatn, "Segoe UI", Tahoma, system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }
h1 { font-size: 21px; font-weight: 700; margin: 0 0 2px; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 14.5px; font-weight: 700; margin: 0 0 10px; color: var(--ink-2); }
code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; font-family: ui-monospace, Menlo, Consolas, monospace; }
hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---- App shell: fixed RTL sidebar + content ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: #0b1220; color: #cbd5e1;
    position: fixed; inset-block: 0; inset-inline-start: 0;
    display: flex; flex-direction: column; padding: 14px 12px; overflow-y: auto; z-index: 30;
}
.sidebar .brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 14px; color: #fff; font-weight: 800; font-size: 16px; }
.sidebar .brand .logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), #7c3aed); display: grid; place-items: center; font-size: 16px; }
.sidebar .group { color: #64748b; font-size: 11px; font-weight: 700; margin: 14px 8px 4px; letter-spacing: .02em; }
.sidebar a.nav {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
    color: #cbd5e1; font-size: 13.5px; margin-bottom: 1px; transition: background .12s, color .12s;
}
.sidebar a.nav:hover { background: #1e293b; color: #fff; }
.sidebar a.nav.active { background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.4); }
.sidebar a.nav .ic { width: 18px; text-align: center; opacity: .95; }
.sidebar a.nav.admin { color: #fbbf24; }

.main { flex: 1; margin-inline-start: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
    background: var(--topbar-bg); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
    padding: 12px 22px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 20;
}
.topbar .who { margin-inline-start: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.topbar .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.content { padding: 22px; max-width: 1180px; width: 100%; }

/* ---- Cards (Material-style resting/raised elevation) ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); transition: box-shadow .18s ease; }
.card:hover { box-shadow: 0 2px 4px rgba(15,23,42,.06), 0 8px 20px rgba(15,23,42,.09); }
.card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .grid.cols-2 { grid-template-columns: 1fr; } }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    background: var(--brand); color: #fff; border: 1px solid transparent; padding: 9px 16px;
    border-radius: 9px; cursor: pointer; font-size: 13.5px; font-weight: 600; font-family: inherit;
    transition: background .12s, box-shadow .12s, transform .05s;
}
.btn:hover { background: var(--brand-600); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.3); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--card); color: var(--ink-3); border-color: var(--line); }
.btn.secondary:hover { background: var(--card-2); color: var(--ink); box-shadow: var(--shadow); }
.btn.danger { background: var(--bad); } .btn.danger:hover { background: #b91c1c; box-shadow: 0 4px 12px rgba(220,38,38,.3); }
.btn.small { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Forms ---- */
label { font-size: 12.5px; color: var(--ink-3); display: block; margin-bottom: 5px; font-weight: 600; }
input, select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
    font-family: inherit; font-size: 13.5px; margin-bottom: 12px; background: var(--input-bg); color: var(--ink);
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 4px; height: 42px; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: none; background: var(--card-2); }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--card-2); }
td a { font-weight: 600; }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.7; }
.badge.open, .badge.info { background: var(--info-bg); color: #1e40af; }
.badge.pending, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.solved, .badge.ok { background: var(--ok-bg); color: #065f46; }
.badge.closed { background: #e2e8f0; color: #475569; }
.badge.urgent, .badge.bad { background: var(--bad-bg); color: #991b1b; }
.badge.high { background: #ffedd5; color: #9a3412; }
.badge.medium { background: var(--brand-50); color: var(--brand-600); }
.badge.low { background: #f1f5f9; color: #475569; }

/* ---- Alerts ---- */
.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid transparent; }
.alert.error { background: var(--bad-bg); color: #991b1b; border-color: #fecaca; }
.alert.ok { background: var(--ok-bg); color: #065f46; border-color: #a7f3d0; }

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--brand); }
.stat.good::before { background: var(--ok); } .stat.warn::before { background: var(--warn); } .stat.bad::before { background: var(--bad); }
.stat .num { font-size: 25px; font-weight: 800; letter-spacing: -.01em; }
.stat .lbl { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.good .num { color: var(--ok); } .stat.warn .num { color: var(--warn); } .stat.bad .num { color: var(--bad); }

/* ---- Horizontal bar charts (reports) ---- */
.hbar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12.5px; }
.hbar-lbl { flex: 0 0 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { flex: 1; background: var(--card-2); border-radius: 6px; height: 14px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--brand); border-radius: 6px; transition: width .3s ease; }
.hbar-val { flex: 0 0 40px; text-align: end; font-weight: 700; }

.muted { color: var(--muted); font-size: 13px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-inline-end: auto; }

/* ---- Focus visibility (keyboard a11y, Material focus ring) ---- */
.btn:focus-visible, a.nav:focus-visible { outline: 3px solid var(--brand-50); outline-offset: 1px; }

/* ---- Mobile drawer toggle: hidden on desktop ---- */
.menu-toggle { display: none; }
.scrim { display: none; }

/* ---- Responsive: icons-only rail + hamburger overlay drawer on phones ---- */
@media (max-width: 720px) {
    :root { --sidebar-w: 58px; }
    .sidebar .brand span, .sidebar a.nav span, .sidebar .group { display: none; }
    .sidebar a.nav { justify-content: center; }
    .sidebar .brand { justify-content: center; padding-inline: 0; }
    .content { padding: 14px; }
    .topbar { padding: 10px 14px; }
    .menu-toggle { display: inline-flex; }

    /* Hamburger expands the rail into a full Material drawer over a scrim. */
    body.nav-open .sidebar { width: 240px; box-shadow: var(--shadow-lg); }
    body.nav-open .sidebar .brand span, body.nav-open .sidebar a.nav span, body.nav-open .sidebar .group { display: block; }
    body.nav-open .sidebar a.nav { justify-content: flex-start; }
    body.nav-open .sidebar .brand { justify-content: flex-start; padding: 6px 8px 14px; }
    body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 25; }

    /* Wide tables scroll inside their card instead of breaking the page. */
    .card { overflow-x: auto; }
    table { min-width: 560px; }

    .grid.cols-2 { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Print: content only (reports/invoices saved as PDF) ---- */
@media print {
    .sidebar, .topbar, .scrim, .menu-toggle, .btn { display: none !important; }
    .main { margin: 0 !important; }
    body { background: #fff; }
    .card { box-shadow: none; border-color: #cbd5e1; break-inside: avoid; }
}
