﻿/* ==========================================================================
   QRMessenger — استایل اصلی
   بدون وابستگی به Bootstrap یا هیچ CDN خارجی، تا در هر شبکه‌ای بارگذاری شود.
   فونت: اگر Vazirmatn روی سیستم/شبکه در دسترس نبود، به Tahoma برمی‌گردد.
   ========================================================================== */

:root {
    --ink:        #10243b;
    --ink-soft:   #5b6b7d;
    --surface:    #eef2f6;
    --card:       #ffffff;
    --line:       #dde4ec;
    --brand:      #0f6e6e;
    --brand-dark: #0a5252;
    --brand-soft: #e6f2f2;
    --accent:     #d98324;
    --danger:     #c0392b;
    --success:    #1e8449;
    --warning:    #d68910;
    --radius:     14px;
    --radius-sm:  9px;
    --shadow:     0 1px 2px rgba(16,36,59,.06), 0 6px 20px rgba(16,36,59,.07);
    --shadow-sm:  0 1px 3px rgba(16,36,59,.10);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    font-family: Vazirmatn, IRANSans, "Segoe UI", Tahoma, sans-serif;
    /* ۱۶ پیکسل: جلوگیری از زوم خودکار هنگام فوکوس روی فیلد در iOS */
    font-size: 16px;
    line-height: 1.8;
    direction: rtl;
}

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

h1, h2, h3, h4 { margin: 0 0 .6rem; font-weight: 700; line-height: 1.5; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.tiny  { font-size: .78rem; }
.center { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.hidden { display: none !important; }
.ltr { direction: ltr; unicode-bidi: embed; }
.nowrap { white-space: nowrap; }

/* ---------------------------- چیدمان پنل ---------------------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px; flex-shrink: 0;
    background: var(--ink); color: #cdd8e4;
    padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
    display: flex; align-items: center; gap: .5rem;
    color: #fff; font-weight: 700; font-size: 1.05rem;
    padding: .5rem .5rem 1rem; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: .75rem;
}
.sidebar .brand-mark {
    width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
    display: grid; place-items: center; color: #fff; font-size: 1rem;
}
.sidebar nav a {
    display: flex; align-items: center; gap: .55rem;
    padding: .6rem .7rem; border-radius: var(--radius-sm);
    color: #cdd8e4; font-size: .93rem; margin-bottom: .15rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.sidebar .section-title {
    font-size: .74rem; color: #7d8fa3; padding: .9rem .7rem .3rem; letter-spacing: .02em;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--card); border-bottom: 1px solid var(--line);
    padding: .7rem 1.25rem; display: flex; align-items: center; gap: 1rem;
    position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.topbar .user-chip {
    display: flex; align-items: center; gap: .5rem; font-size: .9rem;
    background: var(--surface); padding: .35rem .7rem; border-radius: 999px;
}
.avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft);
    color: var(--brand-dark); display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.content { padding: 1.25rem; flex: 1; }

.menu-toggle { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--ink); }

@media (max-width: 900px) {
    .sidebar { position: fixed; right: -260px; z-index: 60; transition: right .22s ease; }
    .sidebar.open { right: 0; box-shadow: -8px 0 30px rgba(0,0,0,.25); }
    .menu-toggle { display: block; }
    .content { padding: .9rem; }
    .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; }
}

/* ---------------------------- کارت ---------------------------- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.1rem; margin-bottom: 1rem;
}
.card-head {
    display: flex; align-items: center; gap: .6rem; margin: -.15rem 0 .9rem;
    padding-bottom: .7rem; border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head h3 { margin: 0; flex: 1; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.kpi {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .9rem 1rem; box-shadow: var(--shadow-sm); border-top: 3px solid var(--brand);
}
.kpi .label { font-size: .82rem; color: var(--ink-soft); }
.kpi .value { font-size: 1.75rem; font-weight: 700; line-height: 1.4; }
.kpi.is-danger  { border-top-color: var(--danger); }
.kpi.is-warning { border-top-color: var(--warning); }
.kpi.is-success { border-top-color: var(--success); }

/* ---------------------------- فرم ---------------------------- */
.field { margin-bottom: .95rem; }
.field > label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: .35rem; }
.field .hint { font-size: .78rem; color: var(--ink-soft); margin-top: .25rem; }

.input, input[type=text], input[type=password], input[type=tel], input[type=email],
input[type=number], input[type=date], select, textarea {
    width: 100%; padding: .62rem .8rem; font: inherit; font-size: .95rem;
    color: var(--ink); background: #fff;
    border: 1px solid var(--line); border-radius: var(--radius-sm); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
    border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,110,110,.13);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.9; }
input[readonly] { background: var(--surface); }

.check { display: flex; align-items: flex-start; gap: .5rem; cursor: pointer; font-size: .92rem; }
.check input[type=checkbox] { width: 19px; height: 19px; margin-top: .28rem; accent-color: var(--brand); flex-shrink: 0; }

.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > * { flex: 1 1 220px; min-width: 0; }

/* ---------------------------- دکمه ---------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .6rem 1.1rem; font: inherit; font-size: .93rem; font-weight: 600;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: var(--brand); color: #fff; cursor: pointer; min-height: 44px;
    transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.02rem; min-height: 52px; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; min-height: 34px; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #a5281a; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #b96c19; }

/* ---------------------------- جدول ---------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); }
table.grid { width: 100%; border-collapse: collapse; background: #fff; font-size: .9rem; }
table.grid th, table.grid td { padding: .65rem .7rem; text-align: right; border-bottom: 1px solid var(--line); }
table.grid th { background: var(--surface); font-weight: 600; font-size: .85rem; white-space: nowrap; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr:hover td { background: #fafcfd; }

/* ---------------------------- نشان و برچسب ---------------------------- */
.badge {
    display: inline-block; padding: .18rem .55rem; border-radius: 999px;
    font-size: .76rem; font-weight: 600; color: #fff; white-space: nowrap;
}
.badge-soft { background: var(--surface); color: var(--ink-soft); }
.pill-count { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .72rem; }

/* ---------------------------- هشدار ---------------------------- */
.alert {
    padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem;
    font-size: .92rem; border: 1px solid transparent; position: relative;
}
.alert-success { background: #e8f6ee; border-color: #b7e1c8; color: #14603a; }
.alert-danger  { background: #fdecea; border-color: #f5c6c0; color: #922b21; }
.alert-info    { background: var(--brand-soft); border-color: #bfdede; color: var(--brand-dark); }
.alert-warning { background: #fef5e7; border-color: #f8d7a3; color: #8a5a08; }
.alert .btn-close {
    position: absolute; left: .6rem; top: .5rem; background: none; border: 0;
    font-size: 1.1rem; cursor: pointer; opacity: .5; color: inherit;
}
.alert .btn-close::before { content: "×"; }
.alert .btn-close:hover { opacity: 1; }

/* ---------------------------- لیست پیام‌ها ---------------------------- */
.msg-list { display: flex; flex-direction: column; gap: .6rem; }
.msg-item {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: .85rem 1rem; display: block; color: inherit;
    border-right: 5px solid var(--line); box-shadow: var(--shadow-sm);
}
.msg-item:hover { text-decoration: none; border-color: #c3cfdb; box-shadow: var(--shadow); }
.msg-item.unread { background: #fbfdff; }
.msg-item.unread .msg-subject { font-weight: 700; }
.msg-top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .25rem; }
.msg-subject { flex: 1; min-width: 140px; font-size: .97rem; }
.msg-preview { color: var(--ink-soft); font-size: .87rem; margin-bottom: .35rem; }
.msg-meta { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .78rem; color: var(--ink-soft); }
.msg-item.overdue { border-right-color: var(--danger); }

/* گفتگو */
.thread { display: flex; flex-direction: column; gap: .75rem; }
.bubble { padding: .8rem 1rem; border-radius: var(--radius); max-width: 88%; font-size: .93rem; }
.bubble .who { font-size: .76rem; color: var(--ink-soft); margin-bottom: .3rem; }
.bubble-in  { background: var(--surface); align-self: flex-start; border: 1px solid var(--line); }
.bubble-out { background: var(--brand-soft); align-self: flex-end; border: 1px solid #cfe6e6; }
.bubble-note { background: #fef8e7; border: 1px dashed #e8c96a; align-self: flex-end; }

/* خط زمانی پیگیری */
.timeline { list-style: none; margin: 0; padding: 0 1.1rem 0 0; border-right: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 1rem .95rem 0; }
.timeline li::before {
    content: ""; position: absolute; right: -1.42rem; top: .55rem;
    width: 11px; height: 11px; border-radius: 50%; background: var(--line); border: 2px solid #fff;
}
.timeline li.done::before { background: var(--brand); }
.timeline .t-title { font-weight: 600; font-size: .93rem; }
.timeline .t-time { font-size: .78rem; color: var(--ink-soft); }

/* ---------------------------- بخش عمومی ---------------------------- */
.public-wrap { max-width: 560px; margin: 0 auto; padding: 0 .85rem 3rem; }
.public-header {
    background: var(--card); border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow); padding: 1.1rem 1rem; text-align: center; margin-bottom: 1rem;
}
.public-header .org-name { font-size: .85rem; color: var(--ink-soft); }
.public-header .target-name { font-size: 1.2rem; font-weight: 700; margin-top: .2rem; }
.public-header .target-job { font-size: .87rem; color: var(--ink-soft); }
.public-header .org-logo { max-height: 54px; margin-bottom: .5rem; }

/* تب‌های نوع پیام */
.tabs { display: flex; gap: .4rem; background: var(--surface); padding: .3rem; border-radius: var(--radius-sm); margin-bottom: .9rem; }
.tabs button {
    flex: 1; padding: .55rem .3rem; border: 0; background: transparent; border-radius: var(--radius-sm);
    font: inherit; font-size: .88rem; font-weight: 600; color: var(--ink-soft); cursor: pointer; min-height: 42px;
}
.tabs button.active { background: #fff; color: var(--brand-dark); box-shadow: var(--shadow-sm); }

/* چیپ فوریت */
.chips { display: flex; gap: .45rem; flex-wrap: wrap; }
.chip {
    flex: 1 1 auto; padding: .5rem .3rem; text-align: center; cursor: pointer;
    border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    font-size: .87rem; font-weight: 600; background: #fff; min-height: 44px;
    display: flex; align-items: center; justify-content: center; user-select: none;
}
.chip.selected { color: #fff; border-color: transparent; }

/* ضبط صدا */
.recorder { text-align: center; padding: 1rem .5rem; background: var(--surface); border-radius: var(--radius); }
.rec-btn {
    width: 78px; height: 78px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--danger); color: #fff; font-size: 1.9rem; display: grid; place-items: center;
    margin: 0 auto .6rem; box-shadow: 0 4px 14px rgba(192,57,43,.35);
}
.rec-btn.recording { animation: pulse 1.3s infinite; }
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(192,57,43,.5); }
    70%  { box-shadow: 0 0 0 18px rgba(192,57,43,0); }
    100% { box-shadow: 0 0 0 0 rgba(192,57,43,0); }
}
.rec-timer { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* نتیجه ثبت */
.tracking-box {
    background: var(--brand-soft); border: 2px dashed var(--brand);
    border-radius: var(--radius); padding: 1.2rem; text-align: center; margin: 1rem 0;
}
.tracking-code {
    font-size: 2rem; font-weight: 800; letter-spacing: .12em; color: var(--brand-dark);
    direction: ltr; font-family: Consolas, monospace; margin: .4rem 0;
}

/* ---------------------------- چاپ QR ---------------------------- */
.qr-sheet { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.qr-card {
    border: 1px dashed #999; border-radius: 10px; padding: 1rem; text-align: center;
    background: #fff; page-break-inside: avoid;
}
.qr-card img { width: 190px; height: 190px; }
.qr-card .qr-name { font-size: 1.05rem; font-weight: 700; margin-top: .5rem; }
.qr-card .qr-job { font-size: .85rem; color: #555; }
.qr-card .qr-hint { font-size: .82rem; margin-top: .5rem; }
.qr-card .qr-url { font-size: .7rem; color: #777; direction: ltr; margin-top: .25rem; }

@media print {
    .no-print, .sidebar, .topbar { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
    .qr-sheet { grid-template-columns: repeat(2, 1fr); }
    .qr-card { border-style: solid; border-color: #ccc; }
}

/* ---------------------------- ابزارها ---------------------------- */
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin-bottom: 0; }
.toolbar .field > label { font-size: .8rem; }

.pager { display: flex; gap: .3rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.pager a, .pager span {
    padding: .35rem .7rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: #fff; font-size: .85rem;
}
.pager .current { background: var(--brand); color: #fff; border-color: var(--brand); }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-soft); }
.empty .icon { font-size: 2.4rem; opacity: .35; display: block; margin-bottom: .5rem; }

.spinner {
    width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* دسترسی‌پذیری */
:focus-visible { outline: 3px solid rgba(15,110,110,.45); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ---------------------------- استیکر ---------------------------- */
.sticker-box { margin-top: .4rem; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.sticker-tabs { display: flex; gap: 0; background: var(--surface); }
.sticker-tabs button {
    flex: 1; padding: .45rem .3rem; border: 0; background: transparent;
    font: inherit; font-size: .82rem; font-weight: 600; color: var(--ink-soft);
    cursor: pointer; min-height: 38px;
}
.sticker-tabs button.active { background: #fff; color: var(--brand-dark); }
.sticker-grid {
    display: grid; grid-template-columns: repeat(8, 1fr);
    gap: .2rem; padding: .5rem; background: #fff; max-height: 150px; overflow-y: auto;
}
.sticker {
    border: 0; background: transparent; cursor: pointer; padding: .25rem;
    font-size: 1.4rem; line-height: 1.4; border-radius: 7px; min-height: 40px;
}
.sticker:hover { background: var(--surface); }
.sticker:active { transform: scale(.9); }

@media (max-width: 420px) {
    .sticker-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ---------------------------- ضبط ویدیو ---------------------------- */
.video-stage {
    position: relative; background: #10243b; border-radius: var(--radius);
    overflow: hidden; margin-bottom: .6rem;
}
.video-stage video { width: 100%; display: block; max-height: 300px; background: #000; }
.video-meta {
    display: flex; justify-content: space-between; align-items: center;
    gap: .5rem; font-size: .85rem; margin-bottom: .5rem;
}
.video-meta .rec-timer { font-size: 1.2rem; }
.size-meter { font-variant-numeric: tabular-nums; color: var(--ink-soft); }

/* نوار پیشرفت بارگذاری */
.upload-bar {
    height: 8px; background: var(--surface); border-radius: 999px;
    overflow: hidden; margin-top: .6rem;
}
.upload-bar > span {
    display: block; height: 100%; width: 0;
    background: var(--brand); transition: width .2s ease;
}
.upload-text { font-size: .85rem; color: var(--ink-soft); margin-top: .35rem; text-align: center; }

/* ---------------------------- فهرست فایل‌های انتخاب‌شده ---------------------------- */
.file-row {
    display: flex; align-items: center; gap: .5rem;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: .45rem .6rem; margin-bottom: .35rem;
}
.file-name { flex: 1; min-width: 0; font-size: .85rem; word-break: break-all; }
.file-del {
    flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%;
    border: 1px solid var(--line); background: #fff; color: var(--danger);
    font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.file-del:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
