/* ==========================================================================
   MT Panel v2 — design system
   Modern, responsive, RTL-first admin UI. Light & dark themes.
   ========================================================================== */

@import url("../fonts/vazir/vazir.css");

:root {
    --font: vazir, "Segoe UI", Tahoma, sans-serif;

    /* Brand */
    --brand: #4f46e5;
    --brand-600: #4338ca;
    --brand-700: #3730a3;
    --brand-soft: #eef2ff;

    /* Status */
    --green: #16a34a;
    --green-soft: #dcfce7;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --blue: #2563eb;
    --blue-soft: #dbeafe;
    --purple: #7c3aed;
    --purple-soft: #ede9fe;

    /* Neutrals (light) */
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e6e9f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 16px rgba(15, 23, 42, .08);
    --shadow-lg: 0 18px 40px rgba(15, 23, 42, .16);

    --radius: 14px;
    --radius-sm: 9px;
    --radius-lg: 22px;

    --sidebar-w: 268px;
    --header-h: 66px;
    --speed: .2s;
}

[data-theme="dark"] {
    --bg: #0b1020;
    --surface: #141a2e;
    --surface-2: #1b2238;
    --border: #273150;
    --text: #e8edf7;
    --text-muted: #9aa6c2;
    --text-faint: #6b779b;
    --brand-soft: #1e2547;
    --green-soft: #0e2a1b;
    --amber-soft: #2e2410;
    --red-soft: #2e1414;
    --blue-soft: #11214a;
    --purple-soft: #221742;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lg: 0 22px 48px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    transition: background var(--speed), color var(--speed);
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }

h1, h2, h3, h4, h5, h6 { margin: 0 0 .4em; font-weight: 700; line-height: 1.35; }

.ltr { direction: ltr; }
.rtl { direction: rtl; }
.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ============================ Layout ============================ */
.layout { min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: transform var(--speed) ease;
}

.sidebar__brand {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    border-bottom: 1px solid var(--border);
}
.sidebar__brand img { width: 34px; height: 34px; border-radius: 9px; }
.sidebar__brand b { font-size: 17px; }
.sidebar__brand span { display: block; font-size: 11.5px; color: var(--text-faint); font-weight: 500; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 16px 14px; }
.sidebar__section { font-size: 11px; color: var(--text-faint); font-weight: 700; padding: 16px 12px 8px; letter-spacing: .04em; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 3px;
    transition: background var(--speed), color var(--speed);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand); color: #fff; box-shadow: 0 8px 18px -8px var(--brand); }
.nav-link.active .ic { color: #fff; }
.nav-link .ic { width: 20px; height: 20px; flex-shrink: 0; }
.nav-link span:not(.nav-dot) { flex: 1; }
.nav-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent);
    flex-shrink: 0;
    margin-inline-start: auto;
}
.nav-link.active .nav-dot {
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255,255,255,.25);
}

.sidebar__footer { padding: 14px; border-top: 1px solid var(--border); }

.main { margin-right: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    height: var(--header-h);
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 14px;
    padding: 0 24px;
}
.topbar__title { font-size: 18px; font-weight: 700; flex: 1; }
.topbar__date { color: var(--text-muted); font-size: 13px; }

.content { padding: 26px; flex: 1; }
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .spacer { flex: 1; }

.icon-btn {
    width: 42px; height: 42px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--speed);
}
.icon-btn:hover { color: var(--text); border-color: var(--brand); }
.hamburger { display: none; }

/* ============================ Cards ============================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card__head h3 { margin: 0; font-size: 16px; }
.card__body { padding: 22px; }
.card__foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-start; }

/* ============================ Grid ============================ */
.grid { display: grid; gap: 20px; }
/* Allow grid items (cards with tables/charts) to shrink instead of overflowing the viewport. */
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.col-span-2 { grid-column: span 2; }
.table-wrap { max-width: 100%; }
canvas { max-width: 100%; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }

/* ============================ Stat cards ============================ */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 16px;
}
.stat__icon {
    width: 52px; height: 52px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat__icon svg { width: 26px; height: 26px; }
.stat__value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat__label { color: var(--text-muted); font-size: 13px; }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-blue { background: var(--blue-soft); color: var(--blue); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-purple { background: var(--purple-soft); color: var(--purple); }
.tone-brand { background: var(--brand-soft); color: var(--brand); }

/* ============================ Buttons ============================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px; font-weight: 700;
    cursor: pointer;
    transition: all var(--speed);
    white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 10px 20px -10px var(--brand); }
.btn-primary:hover { background: var(--brand-600); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-warning { background: var(--amber); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--brand); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-icon svg { width: 17px; height: 17px; }

/* Match convert button height to neighboring .input / .select fields */
.config .convert-link {
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
}

/* ============================ Forms ============================ */
.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 700; margin-bottom: 7px; font-size: 13.5px; }
.field .hint { color: var(--text-faint); font-size: 12px; margin-top: 6px; }

.input, .select, .textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    transition: border var(--speed), box-shadow var(--speed);
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.textarea { resize: vertical; min-height: 110px; }
/* RTL layout: addon sits on the right, input on the left (DOM order: addon, input). */
.input-group { display: flex; align-items: stretch; }
.input-group .input,
.input-group .select { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; min-width: 0; }
.input-group__addon {
    display: inline-flex; align-items: center; padding: 0 14px; gap: 8px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-muted); font-size: 13px; font-weight: 700;
    white-space: nowrap; flex-shrink: 0;
}

/* Toggle / switch */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; gap: 10px; }
/* Keep the toggle inline even when used as a direct child of .field (which styles labels as block). */
.field > label.switch { display: inline-flex; margin-bottom: 0; font-weight: 600; }
.switch input { display: none; }
.switch .track {
    width: 46px; height: 26px; border-radius: 99px; background: var(--border);
    position: relative; transition: background var(--speed); flex-shrink: 0;
}
.switch .track::after {
    content: ""; position: absolute; top: 3px; right: 3px;
    width: 20px; height: 20px; border-radius: 50%; background: #fff;
    transition: transform var(--speed); box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(-20px); }

/* Chips / multiselect */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    padding: 8px 14px; border-radius: 99px; border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text-muted); cursor: pointer;
    font-size: 13px; font-weight: 700; transition: all var(--speed); user-select: none;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ============================ Badges ============================ */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 11px; border-radius: 99px; font-size: 12px; font-weight: 700;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-gray { background: var(--surface-2); color: var(--text-muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ============================ Tables ============================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
    text-align: right; padding: 13px 14px; color: var(--text-muted);
    font-weight: 700; font-size: 12.5px; border-bottom: 1px solid var(--border);
    white-space: nowrap; background: var(--surface-2);
}
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background var(--speed); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: 6px; }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .search { flex: 1; min-width: 200px; position: relative; }
.toolbar .search svg { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-faint); }
.toolbar .search .input { padding-right: 42px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.seg button {
    border: none; background: transparent; color: var(--text-muted);
    padding: 7px 15px; border-radius: 7px; cursor: pointer; font-family: var(--font);
    font-weight: 700; font-size: 13px; transition: all var(--speed);
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* progress bar */
.meter { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 90px; }
.meter span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.meter span.warn { background: var(--amber); }
.meter span.danger { background: var(--red); }

/* ============================ Empty / loading ============================ */
.state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.state svg { width: 54px; height: 54px; opacity: .5; margin-bottom: 12px; }
.spinner {
    width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--brand);
    animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Toast ============================ */
.toast-wrap { position: fixed; bottom: 22px; left: 22px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--surface); border: 1px solid var(--border);
    border-right: 4px solid var(--brand);
    border-radius: var(--radius-sm); padding: 13px 18px; box-shadow: var(--shadow-lg);
    min-width: 260px; max-width: 380px; display: flex; align-items: center; gap: 11px;
    animation: toast-in .25s ease;
}
.toast.ok { border-right-color: var(--green); }
.toast.err { border-right-color: var(--red); }
.toast.info { border-right-color: var(--blue); }
.toast svg { width: 20px; height: 20px; flex-shrink: 0; }
.toast.ok svg { color: var(--green); }
.toast.err svg { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ============================ Modal ============================ */
.overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px); z-index: 9000;
    display: flex; align-items: center; justify-content: center; padding: 20px;
    opacity: 0; visibility: hidden; transition: opacity var(--speed), visibility var(--speed);
}
.overlay.show { opacity: 1; visibility: visible; }
.modal {
    background: var(--surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); width: 100%; max-width: 440px;
    transform: scale(.94); transition: transform var(--speed);
}
.overlay.show .modal { transform: scale(1); }
.modal__body { padding: 26px; }
.modal__icon { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; }
.modal__icon svg { width: 28px; height: 28px; }
.modal h3 { font-size: 18px; }
.modal p { color: var(--text-muted); margin: 6px 0 0; }
.modal__foot { display: flex; gap: 10px; padding: 0 26px 26px; }
.modal__foot .btn { flex: 1; }

/* ============================ Auth ============================ */
.auth {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1200px 600px at 90% -10%, color-mix(in srgb, var(--brand) 28%, transparent), transparent),
        radial-gradient(1000px 500px at -10% 110%, color-mix(in srgb, var(--purple) 22%, transparent), transparent),
        var(--bg);
}
.auth__card {
    width: 100%; max-width: 410px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); padding: 38px 34px;
}
.auth__logo { text-align: center; margin-bottom: 26px; }
.auth__logo img { width: 64px; height: 64px; }
.auth__logo h1 { font-size: 22px; margin: 14px 0 4px; }
.auth__logo p { color: var(--text-muted); margin: 0; font-size: 13px; }

/* ============================ Utilities ============================ */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.avatar { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; vertical-align: middle; }

/* ============================ Responsive ============================ */
.backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 55;
    opacity: 0; visibility: hidden; transition: opacity var(--speed), visibility var(--speed);
}
.backdrop.show { opacity: 1; visibility: visible; }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-right: 0; }
    .hamburger { display: inline-flex; }
    .grid-2, .col-span-2 { grid-column: auto; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .grid-4, .grid-3 { grid-template-columns: 1fr; }
    .card__body { padding: 16px; }
    .topbar__date { display: none; }
}
