:root {
  --navy-950: #031528;
  --navy-900: #003a66;
  --navy-800: #005596;
  --navy-700: #0a6bb3;
  --navy-600: #1a7fc4;
  --navy-100: #e6f1f8;
  --navy-50: #f2f8fc;
  --white: #ffffff;
  --bg: #f5f7fb;
  --text: #0f1b2d;
  --muted: #5b6b82;
  --border: #d5deeb;
  --shadow: 0 10px 40px rgba(11, 31, 58, .08);
  --shadow-sm: 0 2px 12px rgba(11, 31, 58, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 260px;
  --font: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;
  --st-client: #d97706;
  --st-client-bg: #fff7ed;
  --st-support: #2563eb;
  --st-support-bg: #eff6ff;
  --st-progress: #7c3aed;
  --st-progress-bg: #f5f3ff;
  --st-closed: #059669;
  --st-closed-bg: #ecfdf5;
  --danger: #dc2626;
  --success: #059669;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  font-family: var(--font);
  font-size: 15px;
}
html, body {
  font-family: var(--font) !important;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  font-weight: 400;
  font-size: var(--fs-md);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* همه المان‌های متنی با Vazirmatn */
button, input, select, textarea, option, optgroup,
label, a, p, h1, h2, h3, h4, h5, h6, span, div, li, td, th,
table, .form-control, .form-select, .form-textarea,
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger, .btn-soft,
.nav-item, .chip, .toast, .modal, .status-badge, .kpi,
.panel, .meta-item, .bubble, .encourage, .empty-state,
.aspNetDisabled, input[type="submit"], input[type="button"] {
  font-family: var(--font) !important;
}

/* آیکون‌ها فونت خودشان را نگه دارند */
.ti, [class^="ti-"], [class*=" ti-"],
.ti::before, [class^="ti-"]::before, [class*=" ti-"]::before {
  font-family: "tabler-icons" !important;
  font-style: normal !important;
  font-weight: normal !important;
}

a { color: var(--navy-700); }
.fa-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "ss01";
  font-family: var(--font) !important;
}

h1, h2, h3, h4 {
  font-family: var(--font) !important;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

/* ===== Login ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #003a66 0%, #005596 48%, #1a7fc4 100%);
  font-family: var(--font);
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 15% 20%, rgba(255,255,255,.16), transparent 42%),
    radial-gradient(ellipse at 85% 80%, rgba(0,30,70,.35), transparent 50%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.045'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.login-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 980px;
  min-height: 560px;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: #fff;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0, 20, 50, .35);
  animation: rise .55s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
.login-visual {
  background: #ffffff;
  padding: 48px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 1px solid #e6eef6;
}
.login-logo {
  width: 220px;
  height: auto;
  max-height: 64px;
  object-fit: contain;
  background: #ffffff;
  padding: 0;
  border: none;
  display: block;
  margin-bottom: 28px;
}
.login-visual-title {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 800;
  color: var(--navy-900);
  letter-spacing: -0.02em;
  line-height: 1.35;
}
.login-visual-text {
  margin: 0 0 28px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.9;
  max-width: 360px;
}
.login-features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}
.login-features li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--navy-50);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy-800);
}
.login-features li i {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--navy-50);
  color: var(--navy-700);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.login-form-panel {
  padding: 52px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #fff;
}
.login-form-head {
  margin-bottom: 28px;
}
.login-form-head h2 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
  color: var(--navy-900);
}
.login-form-head p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.login-form-panel .form-group {
  margin-bottom: 18px;
}
.login-form-panel .form-control {
  padding: 14px 16px;
  font-size: 15px;
  border-radius: 12px;
}
.login-form-panel .btn-primary,
.login-card .btn-primary {
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 12px;
}
.login-hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin: 20px 0 0;
  line-height: 1.7;
}

@media (max-width: 860px) {
  .login-shell {
    grid-template-columns: 1fr;
    max-width: 520px;
    min-height: 0;
    border-radius: 22px;
  }
  .login-visual {
    padding: 28px 24px 20px;
    border-left: none;
    border-bottom: 1px solid #e6eef6;
  }
  .login-logo { width: 170px; max-height: 48px; margin-bottom: 16px; }
  .login-visual-title { font-size: 20px; }
  .login-visual-text { margin-bottom: 0; font-size: 13px; max-width: none; }
  .login-features { display: none; }
  .login-form-panel { padding: 24px; }
  .login-form-head { margin-bottom: 20px; }
  .login-form-head h2 { font-size: 20px; }
}

@media (max-width: 1100px) and (min-width: 861px) {
  .login-shell {
    max-width: 860px;
    min-height: 520px;
  }
  .login-visual { padding: 36px 32px; }
  .login-form-panel { padding: 40px 36px; }
  .login-visual-title { font-size: 24px; }
  .login-features li { padding: 10px 12px; font-size: 12px; }
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--navy-900);
  margin-bottom: 7px;
  font-weight: 600;
}
.form-control, .form-select, .form-textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-family: var(--font) !important;
  font-size: 14px;
  font-weight: 500;
  transition: border-color .15s, box-shadow .15s;
}
.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235b6b82' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 36px;
}
.form-control:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--navy-600);
  box-shadow: 0 0 0 3px rgba(36, 80, 143, .15);
}
.form-textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.7;
}
.form-textarea.lg { min-height: 220px; }

/* Searchable select */
.search-select {
  position: relative;
}
.search-select .ss-display {
  position: relative;
}
.search-select .ss-input {
  padding-left: 36px;
}
.search-select .ss-clear {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.search-select .ss-clear:hover {
  background: rgba(0,0,0,.05);
  color: var(--text);
}
.search-select .ss-list {
  position: absolute;
  z-index: 40;
  inset-inline: 0;
  top: calc(100% + 6px);
  max-height: 260px;
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .12);
  padding: 6px;
}
.search-select .ss-option {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: right;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}
.search-select .ss-option:hover,
.search-select .ss-option.active {
  background: rgba(36, 80, 143, .08);
}
.search-select .ss-option-label {
  font-size: 13px;
  font-weight: 600;
}
.search-select .ss-option-hint {
  font-size: 11px;
  color: var(--muted);
  direction: ltr;
}
.search-select .ss-empty {
  padding: 14px 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.btn-primary, .btn-secondary, .btn-ghost, .btn-danger, .btn-soft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font) !important;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: .15s;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--navy-800), var(--navy-600));
  color: #fff;
  box-shadow: 0 6px 18px rgba(18, 48, 86, .25);
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--white);
  color: var(--navy-800);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--navy-50); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--navy-50); color: var(--navy-800); }
.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fee2e2; }
.btn-soft {
  background: var(--navy-50);
  color: var(--navy-800);
  border: 1px solid var(--border);
}
.btn-icon {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--navy-800);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--navy-50); }
.btn-sm { padding: 7px 11px; font-size: 12px; }

/* ===== Shell ===== */
.app-shell { display: flex; min-height: 100vh; overflow-x: hidden; }
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy-900), var(--navy-800));
  color: #fff;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(7, 17, 31, .2);
  transition: transform .28s ease;
  overflow: hidden;
  max-height: 100vh;
  max-height: 100dvh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-brand img {
  width: 120px; height: auto;
  max-height: 38px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
  padding: 8px 10px;
  border: none;
  box-shadow: none;
  filter: none;
}
.sidebar-brand > div { min-width: 0; }
.sidebar-brand h2 { margin: 0; font-size: var(--fs-md); font-weight: 700; }
.sidebar-brand small { color: rgba(255,255,255,.55); font-size: var(--fs-xs); font-weight: 500; }
.sidebar-nav {
  padding: 14px 10px;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.nav-group {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: rgba(255,255,255,.45);
  padding: 12px 12px 6px;
  letter-spacing: .3px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  color: rgba(255,255,255,.78);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  text-align: right;
  transition: .15s;
  margin-bottom: 2px;
}
.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-item.active {
  background: rgba(255,255,255,.14);
  box-shadow: inset -3px 0 0 #7eb6ff;
}
.nav-item .badge-dot {
  margin-right: auto;
  background: #f59e0b;
  color: #111;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.sidebar-footer {
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin-bottom: 6px;
  background: rgba(255,255,255,.06);
  border-radius: 10px;
}
.user-chip i { font-size: 28px; opacity: .85; }
.user-chip strong { display: block; font-size: var(--fs-sm); font-weight: 700; }
.user-chip span { font-size: var(--fs-xs); color: rgba(255,255,255,.55); font-weight: 500; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(7,17,31,.45);
  z-index: 199;
}

.main-wrap {
  margin-right: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  width: calc(100% - var(--sidebar-w));
  background: var(--bg);
  transition: margin-right .28s ease, width .28s ease;
}

/* بستن سایدبار در دسکتاپ با دکمه منو */
body.sidebar-collapsed .sidebar {
  transform: translateX(105%);
}
body.sidebar-collapsed .main-wrap {
  margin-right: 0;
  width: 100%;
}
body.sidebar-collapsed .sidebar-backdrop {
  display: none;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}
.topbar-start { display: flex; align-items: center; gap: 12px; }
.topbar h1 { margin: 0; font-size: var(--fs-xl); font-weight: 800; color: var(--navy-900); }
.topbar-sub { margin: 2px 0 0; font-size: var(--fs-xs); color: var(--muted); font-weight: 500; }
.topbar-end {
  display: flex;
  align-items: center;
  background: #ffffff;
  padding: 4px 0;
}
.topbar-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
  background: #ffffff;
  padding: 0;
  border: none;
  display: block;
}
.content {
  padding: 22px 28px 40px;
  width: 100%;
  max-width: none;
  min-height: calc(100vh - 72px);
  background: var(--bg);
}

/* ===== Cards / KPI ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  animation: rise .45s ease both;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; right: 0; left: 0;
  height: 3px;
  background: var(--navy-700);
}
.kpi.k-client::before { background: var(--st-client); }
.kpi.k-support::before { background: var(--st-support); }
.kpi.k-progress::before { background: var(--st-progress); }
.kpi.k-closed::before { background: var(--st-closed); }
.kpi .label { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.kpi .value { font-size: var(--fs-3xl); font-weight: 800; color: var(--navy-900); margin-top: 6px; line-height: 1.2; }
.kpi .hint { font-size: var(--fs-xs); color: var(--muted); margin-top: 4px; font-weight: 500; }

.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--navy-50));
}
.panel-hd h3 { margin: 0; font-size: var(--fs-md); font-weight: 700; color: var(--navy-900); }
.panel-bd { padding: 18px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar-end { justify-content: flex-start; }

.ticket-no-search {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.ticket-no-search-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--navy-800);
  margin-bottom: 10px;
}
.ticket-no-search-label i { font-size: 18px; color: var(--navy-600); }
.ticket-no-search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.ticket-no-search-row .form-control {
  flex: 1;
  min-width: 180px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .04em;
}
.ticket-no-search-row .btn-primary,
.ticket-no-search-row .btn-ghost {
  flex-shrink: 0;
}

.ticket-filters {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr 1.2fr;
  gap: 12px;
  align-items: end;
}
.ticket-filter-item {
  margin: 0;
}
.ticket-filter-item label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
}
.ticket-filter-no .ticket-no-search-row {
  margin: 0;
}

@media (max-width: 980px) {
  .ticket-filters { grid-template-columns: 1fr 1fr; }
  .ticket-filter-no { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
  .ticket-no-search-row .btn-primary,
  .ticket-no-search-row .btn-ghost,
  .ticket-no-search-row .btn-secondary {
    width: auto;
    justify-content: center;
  }
  .ticket-filters { grid-template-columns: 1fr; }
  .ticket-filter-no { grid-column: auto; }
}

/* ===== Status badges ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}
.status-badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.st-پاسخ-کاربر, [data-status="پاسخ کاربر"] {
  color: var(--st-client);
  background: var(--st-client-bg);
}
.st-پاسخ-پشتیبان, [data-status="پاسخ پشتیبان"] {
  color: var(--st-support);
  background: var(--st-support-bg);
}
.st-در-حال-پیگیری, [data-status="در حال پیگیری"] {
  color: var(--st-progress);
  background: var(--st-progress-bg);
}
.st-بسته-شده, [data-status="بسته شده"] {
  color: var(--st-closed);
  background: var(--st-closed-bg);
}

/* ===== Tables ===== */
.table-wrap { overflow: auto; }
table.nice {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
table.nice th {
  text-align: right;
  padding: 11px 12px;
  color: var(--muted);
  font-weight: 700;
  font-size: var(--fs-xs);
  border-bottom: 1px solid var(--border);
  background: var(--navy-50);
  white-space: nowrap;
}
table.nice td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-weight: 500;
}
table.nice tr {
  cursor: pointer;
  transition: background .12s;
}
table.nice tr:hover { background: #f8fafc; }
table.nice tr.no-click { cursor: default; }
.ticket-no {
  font-weight: 700;
  color: var(--navy-700);
  letter-spacing: .5px;
}
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state i { font-size: 40px; opacity: .35; display: block; margin-bottom: 10px; }

/* ===== Ticket chat ===== */
.chat-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
  align-items: stretch;
  min-height: calc(100vh - 130px);
}
.chat-main {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 560px;
  max-height: calc(100vh - 130px);
}
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: linear-gradient(180deg, #fff, var(--navy-50));
  border-bottom: 1px solid var(--border);
}
.chat-toolbar-info {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-toolbar-info strong {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--navy-900);
}
.chat-toolbar-info span {
  font-size: var(--fs-xs);
  color: var(--muted);
  font-weight: 500;
}
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 28px;
  background:
    radial-gradient(ellipse at 10% 0%, rgba(0,85,150,.06), transparent 45%),
    radial-gradient(ellipse at 90% 100%, rgba(0,58,102,.05), transparent 40%),
    #eef3f9;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.chat-day {
  display: flex;
  justify-content: center;
  margin: 4px 0 8px;
}
.chat-day span {
  background: rgba(255,255,255,.85);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
}
.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 82%;
  animation: chatIn .28s ease both;
}
@keyframes chatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.chat-row.support {
  align-self: flex-start;
  flex-direction: row;
}
.chat-row.client {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}
.chat-avatar.support {
  background: var(--navy-800);
  color: #fff;
}
.chat-avatar.client {
  background: #fff;
  color: var(--navy-800);
  border: 1px solid var(--border);
}
.chat-bubble {
  position: relative;
  padding: 10px 14px 8px;
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(11, 31, 58, .06);
  max-width: 100%;
}
.chat-bubble.support {
  background: linear-gradient(160deg, var(--navy-800), var(--navy-700));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble.client {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 11px;
}
.chat-bubble.support .chat-meta strong { color: rgba(255,255,255,.95); font-weight: 700; }
.chat-bubble.support .chat-meta span { color: rgba(255,255,255,.65); }
.chat-bubble.client .chat-meta strong { color: var(--navy-800); font-weight: 700; }
.chat-bubble.client .chat-meta span { color: var(--muted); }
.chat-text {
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 14px;
  font-weight: 500;
  word-break: break-word;
}
.chat-bubble.support .attach-chip {
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.2);
  color: #fff;
}
.chat-composer {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: #fff;
}
.chat-composer.closed {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  background: var(--navy-50);
}
.chat-closed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}
.chat-closed-row span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.chat-composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.chat-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--navy-50);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.chat-composer-box:focus-within {
  border-color: var(--navy-600);
  box-shadow: 0 0 0 3px rgba(0, 85, 150, .12);
  background: #fff;
}
.chat-attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--navy-700);
  cursor: pointer;
  flex-shrink: 0;
  transition: .15s;
}
.chat-attach-btn:hover { background: var(--navy-100); }
.chat-attach-btn input { display: none; }
.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: var(--font) !important;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.6;
  max-height: 140px;
  padding: 8px 4px;
  color: var(--text);
}
.chat-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-800), var(--navy-600));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(0, 85, 150, .28);
  transition: .15s;
}
.chat-send:hover { transform: translateY(-1px); filter: brightness(1.06); }
.chat-send:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.chat-side {
  min-width: 0;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  align-self: start;
}
.chat-side .meta-attachments {
  background: #fff;
  border-color: #c7dbf5;
}
.attach-list-stack {
  flex-direction: column;
  align-items: stretch;
  flex-wrap: nowrap;
  margin-top: 8px;
  max-height: min(42vh, 320px);
  overflow-y: auto;
  padding: 2px 2px 6px 0;
  gap: 6px;
}
.attach-list-stack .attach-chip {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  white-space: normal;
  word-break: break-word;
  line-height: 1.45;
}
.attach-list-stack .attach-chip span {
  flex: 1;
  min-width: 0;
}
.attach-list-stack .attach-chip i {
  flex-shrink: 0;
  margin-top: 2px;
}

@media (max-width: 980px) {
  .chat-layout { grid-template-columns: 1fr; min-height: 0; }
  .chat-main {
    max-height: none;
    min-height: 0;
    overflow: visible;
  }
  .chat-window {
    flex: none;
    max-height: min(58vh, 520px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .chat-toolbar {
    position: sticky;
    top: 0;
    z-index: 6;
  }
  .chat-composer {
    position: sticky;
    bottom: 0;
    z-index: 6;
  }
  .chat-side {
    order: 2;
    max-height: none;
    overflow: visible;
  }
  .attach-list-stack {
    max-height: none;
  }
  .chat-row { max-width: 92%; }
}

/* legacy bubble keep for safety */
.detail-grid {
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  gap: 16px;
}
.meta-list { display: grid; gap: 10px; }
.meta-item {
  background: var(--navy-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.meta-item .k { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.meta-item .v { font-size: var(--fs-sm); font-weight: 700; margin-top: 3px; word-break: break-word; }
.meta-item a.v { color: var(--navy-600); text-decoration: none; }

.status-pick {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.status-pick-btn {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: right;
  transition: .15s;
  overflow: hidden;
}
.status-pick-btn:hover { background: var(--navy-50); }
.status-pick-btn.active {
  border-color: var(--navy-600);
  background: var(--navy-50);
  box-shadow: 0 0 0 2px rgba(0, 85, 150, .12);
}
.status-pick-btn .status-badge {
  max-width: 100%;
  white-space: normal;
  line-height: 1.45;
  justify-content: flex-start;
}
.meta-status-pick {
  overflow: hidden;
  min-width: 0;
}

.thread { display: flex; flex-direction: column; gap: 12px; }
.bubble {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  background: #fff;
  position: relative;
}
.bubble.support {
  background: linear-gradient(180deg, #f0f6ff, #fff);
  border-color: #c7dbf5;
}
.bubble.client { background: #fff; }
.bubble-hd {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: var(--fs-xs);
}
.bubble-hd strong { color: var(--navy-800); font-weight: 700; }
.bubble-hd span { color: var(--muted); font-weight: 500; }
.bubble-body {
  white-space: pre-wrap;
  line-height: 1.85;
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--text);
}

.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--navy-50);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--navy-800);
  text-decoration: none;
}
.attach-chip:hover { background: var(--navy-100); }

.encourage {
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
  border: 1px dashed #93c5fd;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--navy-800);
  line-height: 1.85;
}
.encourage strong { color: var(--navy-900); font-weight: 700; }
.encourage ul { margin: 8px 0 0; padding-right: 18px; color: var(--muted); }
.char-count {
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-top: 6px;
  text-align: left;
  font-weight: 600;
}
.char-count.ok { color: var(--success); }
.char-count.warn { color: var(--st-client); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.file-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  text-align: center;
  color: var(--muted);
  background: var(--navy-50);
  cursor: pointer;
  transition: .15s;
}
.file-drop:hover, .file-drop.drag {
  border-color: var(--navy-600);
  background: #eaf1fb;
  color: var(--navy-800);
}
.file-drop input { display: none; }
.file-names {
  margin-top: 8px;
  font-size: 12px;
  color: var(--navy-700);
  font-weight: 600;
  word-break: break-word;
  line-height: 1.5;
  min-height: 0;
}
.file-names:empty { display: none; }
.file-names:not(:empty) {
  padding: 8px 10px;
  background: var(--navy-50);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.password-cell {
  font-family: var(--font) !important;
  letter-spacing: .3px;
  font-weight: 600;
}
.toggle-pass {
  border: none;
  background: none;
  color: var(--navy-600);
  cursor: pointer;
  padding: 0 4px;
}

.switch {
  position: relative;
  width: 42px; height: 24px;
  display: inline-block;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: .2s;
}
.switch span::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 3px; right: 3px;
  transition: .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + span { background: var(--navy-600); }
.switch input:checked + span::before { transform: translateX(-18px); }

.loading-block {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--navy-600);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-wrap {
  position: fixed;
  left: 16px; bottom: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--navy-900);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: rise .25s ease both;
  max-width: 320px;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }

.modal-back {
  position: fixed; inset: 0;
  background: rgba(7,17,31,.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade .2s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
  animation: rise .3s ease both;
}
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: #fff;
}
.modal-hd h3 { margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.modal-bd { padding: 18px; }

.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.chip {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: var(--fs-xs);
  cursor: pointer;
  font-weight: 700;
}
.chip.active {
  background: var(--navy-800);
  border-color: var(--navy-800);
  color: #fff;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 18px 16px 32px; }
  .chat-layout { grid-template-columns: 1fr 260px; gap: 12px; }
}

@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; }
  .topbar-logo { display: none; }
  .chat-toolbar-info strong {
    font-size: 13px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(105%);
    transition: transform .28s ease;
    width: min(var(--sidebar-w), 86vw);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; }
  .main-wrap { margin-right: 0 !important; width: 100% !important; }
  body.sidebar-collapsed .sidebar { transform: translateX(105%); }
  body.sidebar-collapsed .main-wrap { margin-right: 0; width: 100%; }

  .topbar {
    padding: 12px 14px;
    gap: 8px;
  }
  .topbar h1 { font-size: 16px; }
  .topbar-sub { font-size: 11px; }
  .topbar-logo { display: none; }

  .content {
    padding: 14px 12px 28px;
    min-height: calc(100vh - 64px);
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 22px; }

  .panel-hd { padding: 12px 14px; }
  .panel-bd { padding: 14px; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar .grow { min-width: 0; width: 100%; }
  .toolbar .btn-primary,
  .toolbar .btn-secondary { width: 100%; }

  .filter-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .chip { flex-shrink: 0; }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -2px;
  }
  table.nice { min-width: 640px; }
  table.nice th,
  table.nice td { padding: 10px; font-size: 12px; }

  .chat-layout {
    min-height: 0;
    gap: 12px;
  }
  .chat-main {
    min-height: 0;
    max-height: none;
    border-radius: 14px;
    overflow: visible;
  }
  .chat-window {
    max-height: min(55vh, 480px);
  }
  .chat-toolbar {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .chat-toolbar #btnBack {
    order: -1;
    width: 100%;
    justify-content: center;
  }
  .chat-window {
    padding: 14px 10px 10px;
    gap: 10px;
  }
  .chat-row { max-width: 94%; }
  .chat-avatar { width: 30px; height: 30px; font-size: 12px; }
  .chat-bubble { padding: 9px 12px 7px; border-radius: 14px; }
  .chat-text { font-size: 13px; line-height: 1.7; }
  .chat-composer { padding: 10px; }
  .chat-composer-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .chat-composer-actions .btn-sm { width: 100%; justify-content: center; }

  .modal-back { padding: 10px; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 12px 12px;
  }
  .modal-bd { padding: 14px; }

  .toast-wrap {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }
  .toast { max-width: none; }

  .actions-row { gap: 8px; }
  .encourage { padding: 12px; font-size: 12px; }
}

@media (max-width: 520px) {
  .login-page { padding: 12px; }
  .login-shell { border-radius: 18px; }
  .login-visual { padding: 22px 18px 16px; }
  .login-form-panel { padding: 20px 18px 24px; }
  .login-logo { width: 150px; max-height: 42px; }
  .login-visual-title { font-size: 18px; }

  .kpi-grid { grid-template-columns: 1fr; }
  .kpi .value { font-size: 24px; }

  .sidebar-brand {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .sidebar-brand h2 { font-size: 13px; }

  .chat-meta { flex-direction: column; gap: 2px; }
  .chat-row { max-width: 98%; }
  .topbar h1 { font-size: 15px; }

  table.nice { min-width: 560px; }
}

@supports (padding: max(0px)) {
  .login-page {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .topbar {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .content {
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .toast-wrap {
    bottom: max(10px, env(safe-area-inset-bottom));
  }
}
