/* Admin panel - RTL, responsive, no external dependencies (CSP: style-src 'self'). */
:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e2e6ee;
    --text: #1e2533;
    --muted: #6b7486;
    --primary: #1d5fd1;
    --primary-dark: #164aa6;
    --danger: #c62f3b;
    --warn: #b7791f;
    --success: #1f8a4c;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(20, 30, 50, .06);
    --font: "Vazirmatn", "Vazir", "IRANSans", Tahoma, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12161f; --surface: #1b212c; --border: #2b3342; --text: #e5e9f0; --muted: #98a2b3;
        --primary: #4d8af0; --primary-dark: #3b74d6; --shadow: none;
    }
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.7; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-start { text-align: right; unicode-bidi: plaintext; }
.prewrap { white-space: pre-wrap; word-break: break-word; }
.center { text-align: center; }
.inline { display: inline; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
.topbar-user { margin-inline-start: auto; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.nav-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: .2rem .6rem; font-size: 1.2rem; color: var(--text); cursor: pointer; }
.shell { display: flex; min-height: calc(100vh - 54px); }
.sidebar { width: 220px; flex-shrink: 0; background: var(--surface); border-inline-start: 1px solid var(--border); padding: 1rem .5rem; }
.sidebar a { display: flex; gap: .5rem; align-items: center; padding: .55rem .8rem; border-radius: 8px; color: var(--text); }
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.active { background: var(--primary); color: #fff; }
.nav-icon { width: 1.4rem; text-align: center; }
.main { flex: 1; min-width: 0; padding: 1.25rem; }
.page-title { font-size: 1.35rem; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat-card { display: flex; flex-direction: column; gap: .2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; color: var(--text); box-shadow: var(--shadow); }
a.stat-card:hover { border-color: var(--primary); text-decoration: none; }
.stat-label { color: var(--muted); font-size: .88rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; }
.small-value { font-size: 1.1rem; }
.stat-card.alerting.danger { border-color: var(--danger); }
.stat-card.alerting.danger .stat-value { color: var(--danger); }
.stat-card.alerting.warn .stat-value { color: var(--warn); }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
label { display: block; margin-bottom: .8rem; }
label > input, label > select, label > textarea { margin-top: .25rem; }
label.check { display: flex; align-items: center; gap: .45rem; margin-bottom: .4rem; cursor: pointer; }
label.check input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem; margin: 0 0 1rem; }
legend { padding: 0 .4rem; font-weight: 600; }
.hint { display: block; color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; align-items: center; }
.filters label { margin: 0; }
.filters .filter-actions { display: flex; gap: .4rem; flex-wrap: wrap; grid-column: 1 / -1; }
.inline-filters { display: flex; flex-wrap: wrap; gap: .5rem; }
.inline-filters input, .inline-filters select { width: auto; min-width: 160px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-warn { color: var(--warn); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .2rem .55rem; font-size: .82rem; }
.btn-block { width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: .85rem; white-space: nowrap; }
.table tbody tr:hover { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.table.compact th, .table.compact td { padding: .35rem .5rem; font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem !important; list-style: none; }
.row-actions { white-space: nowrap; display: inline-flex; gap: .25rem; flex-wrap: wrap; }

/* Badges */
.badge { display: inline-block; padding: .05rem .55rem; border-radius: 99px; font-size: .78rem; background: var(--bg); border: 1px solid var(--border); white-space: nowrap; }
.badge-new { background: #e8f0ff; color: #1d4fb8; border-color: #c8d9ff; }
.badge-waiting-for-assignment { background: #fdecee; color: #a8232f; border-color: #f6c6cb; }
.badge-assigned, .badge-in-progress { background: #fff6e0; color: #8a5a00; border-color: #f2dc9f; }
.badge-waiting-for-user { background: #f1e9ff; color: #5b2fb0; border-color: #dccbff; }
.badge-completed-by-expert, .badge-waiting-for-user-confirmation { background: #e6f7f5; color: #12756a; border-color: #b9e6df; }
.badge-closed { background: #e8f6ed; color: #1f7a45; border-color: #bfe3cc; }
.badge-reopened { background: #fff0e6; color: #b04a00; border-color: #ffd0b0; }
.badge-cancelled { background: #eef0f3; color: #59606c; }
@media (prefers-color-scheme: dark) { .badge { filter: brightness(.9) saturate(.9); } }
.prio { font-size: .85rem; }
.prio-high { color: var(--warn); font-weight: 600; }
.prio-urgent { color: var(--danger); font-weight: 700; }
.prio-low { color: var(--muted); }

/* Alerts */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: #e8f6ed; border-color: #bfe3cc; color: #1f6b3e; }
.alert-error { background: #fdecee; border-color: #f6c6cb; color: #8e1f29; }

/* Pagination */
.pagination { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin: .5rem 0 1rem; }
.pagination a, .pagination span.current, .pagination .gap { padding: .25rem .65rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); }
.pagination span.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .gap { border: none; background: none; }

/* Ticket details */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
.action-box { border: 1px solid var(--border); border-radius: 8px; padding: .8rem; display: flex; flex-direction: column; gap: .5rem; }
.action-box h3 { margin: 0; }
.messages { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
.msg { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; }
.msg-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .3rem; }
.msg-internal_note { background: color-mix(in srgb, var(--warn) 8%, transparent); border-style: dashed; }
.msg-reply, .msg-info_request { border-inline-start: 3px solid var(--primary); }
.msg-user_reply, .msg-reopen_reason { border-inline-start: 3px solid var(--success); }
.timeline { list-style: none; padding: 0; margin: 0 0 1rem; border-inline-start: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 1rem .8rem 0; }
.timeline li::before { content: ""; position: absolute; right: -6px; top: .55rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.files { padding-inline-start: 1rem; }
.stars { color: #e3a008; letter-spacing: 2px; }
.secret { font-family: monospace; font-size: 1.2rem; background: var(--bg); padding: .5rem; border-radius: 6px; text-align: center; }
.kv { display: inline-block; margin-inline-end: .5rem; }

/* Category tree */
.cat-tree { list-style: none; margin: 0; padding-inline-start: 1.4rem; border-inline-start: 1px dashed var(--border); }
.card > .cat-tree { padding-inline-start: 0; border: none; }
.cat-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .4rem .5rem; border-radius: 6px; }
.cat-row:hover { background: var(--bg); }
.cat-row.inactive .cat-title { color: var(--muted); text-decoration: line-through; }
.cat-title { font-weight: 600; }
.cat-row .row-actions { margin-inline-start: auto; }
.tree-checks { max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; margin-top: .5rem; }
.tree-filter { margin-top: .4rem; }
.depth-1 { padding-inline-start: 1.2rem; } .depth-2 { padding-inline-start: 2.4rem; } .depth-3 { padding-inline-start: 3.6rem; }
.depth-4 { padding-inline-start: 4.8rem; } .depth-5 { padding-inline-start: 6rem; } .depth-6 { padding-inline-start: 7.2rem; }
.depth-7 { padding-inline-start: 8.4rem; } .depth-8 { padding-inline-start: 9.6rem; }
.hidden { display: none !important; }

/* Reports */
.rating-bars { display: flex; flex-direction: column; gap: .35rem; max-width: 520px; margin-bottom: 1rem; }
.rating-row { display: grid; grid-template-columns: 3rem 1fr 3rem; align-items: center; gap: .6rem; }
.rating-row meter { width: 100%; height: 1rem; }

/* Auth pages */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.6rem; box-shadow: 0 8px 30px rgba(20, 30, 50, .08); }
.auth-card h1 { font-size: 1.3rem; }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--primary); }
.debug { text-align: left; font-size: .75rem; max-height: 300px; overflow: auto; background: var(--bg); padding: .6rem; border-radius: 6px; }

/* Jalali date picker */
.jdp-pop { position: absolute; z-index: 100; width: 270px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem;
    box-shadow: 0 10px 30px rgba(20, 30, 50, .18); user-select: none; }
.jdp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; font-weight: 600; }
.jdp-head button { background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; padding: 0 .55rem; }
.jdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jdp-grid span { padding: .25rem 0; font-size: .85rem; border-radius: 6px; }
.jdp-grid .wd { color: var(--muted); font-size: .75rem; }
.jdp-grid .day { cursor: pointer; }
.jdp-grid .day:hover { background: var(--bg); }
.jdp-grid .today { border: 1px solid var(--primary); }
.jdp-grid .sel { background: var(--primary); color: #fff; }
.jdp-grid .fri { color: var(--danger); }
.jdp-foot { display: flex; justify-content: space-between; margin-top: .4rem; }
.jdp-foot button { background: none; border: none; color: var(--primary); cursor: pointer; font-size: .85rem; }

/* Responsive */
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .nav-toggle { display: inline-block; }
    .sidebar { position: fixed; top: 54px; bottom: 0; right: 0; z-index: 30; transform: translateX(100%); transition: transform .2s; box-shadow: -4px 0 20px rgba(0, 0, 0, .1); }
    .sidebar.open { transform: none; }
    .main { padding: .8rem; }
    .topbar-user .muted { display: none; }
}
@media (max-width: 640px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: .6rem; padding: .3rem; }
    .table td { border: none; padding: .25rem .5rem; }
    .table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .8rem; }
    .details { grid-template-columns: 1fr; }
    .details dd { margin-bottom: .4rem; }
}
