:root {
  --ink: #14212b;
  --muted: #5a6b78;
  --line: #d5dde4;
  --paper: #f3f6f8;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-2: #0e4f4a;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #067a46;
  --busy: #1d4ed8;
  --shadow: 0 18px 40px rgba(20, 33, 43, 0.08);
  --radius: 18px;
  --font: "Sora", "Vazirmatn", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 100% -10%, rgba(15, 118, 110, 0.16), transparent 55%),
    radial-gradient(900px 420px at -10% 110%, rgba(29, 78, 216, 0.10), transparent 50%),
    linear-gradient(180deg, #eef3f6 0%, var(--paper) 40%, #e8eef2 100%);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 1.5rem 1.1rem;
  border-left: 1px solid rgba(213, 221, 228, 0.9);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: grid;
  gap: 0.2rem;
  margin-bottom: 1.8rem;
  padding: 0.4rem 0.6rem;
}

.brand strong {
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.brand span {
  color: var(--muted);
  font-size: 0.82rem;
}

.nav {
  display: grid;
  gap: 0.35rem;
}

.nav a {
  display: block;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  transition: background 160ms ease, transform 160ms ease;
}

.nav a:hover,
.nav a.is-active {
  background: rgba(15, 118, 110, 0.12);
  text-decoration: none;
  transform: translateX(-2px);
}

.main {
  padding: 1.5rem 1.75rem 2.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2vw, 2rem);
  letter-spacing: -0.04em;
}

.topbar p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.user-chip {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
}

.flash-stack {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  animation: rise 320ms ease both;
}

.flash-ok { border-color: rgba(6, 122, 70, 0.35); background: #effaf4; }
.flash-error { border-color: rgba(180, 35, 24, 0.3); background: #fff2f1; }
.flash-info { border-color: rgba(15, 118, 110, 0.3); background: #eefaf8; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
  animation: rise 420ms ease both;
}

.stat:nth-child(2) { animation-delay: 40ms; }
.stat:nth-child(3) { animation-delay: 80ms; }
.stat:nth-child(4) { animation-delay: 120ms; }

.stat .label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.stat .value {
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.04em;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
}

.panel h2 {
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.fleet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}

.account-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem;
  background: linear-gradient(180deg, #fff, #f7fafb);
  transition: transform 180ms ease, border-color 180ms ease;
}

.account-card:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 118, 110, 0.45);
}

.account-card .title {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: start;
  margin-bottom: 0.45rem;
}

.account-card strong { letter-spacing: -0.02em; }

.meta {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: nowrap;
}

.badge-active { color: var(--ok); border-color: rgba(6,122,70,.35); background: #effaf4; }
.badge-needs_relogin,
.badge-expired { color: var(--warn); border-color: rgba(180,83,9,.35); background: #fff7ed; }
.badge-banned,
.badge-disabled,
.badge-error { color: var(--danger); border-color: rgba(180,35,24,.3); background: #fff2f1; }
.badge-busy { color: var(--busy); border-color: rgba(29,78,216,.3); background: #eff4ff; }
.badge-idle { color: var(--muted); }

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: right;
  padding: 0.7rem 0.45rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: top;
}

.table th {
  color: var(--muted);
  font-weight: 560;
  font-size: 0.78rem;
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.field input[type="checkbox"],
.field input[type="radio"] {
  width: auto;
  margin-left: 0.45rem;
}

.field:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.field:has(input[type="checkbox"]) label {
  margin: 0;
}

.field .errorlist {
  margin: 0.3rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--danger);
  font-size: 0.8rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: transform 150ms ease, background 150ms ease;
}

.btn:hover { background: var(--accent-2); transform: translateY(-1px); }
.btn-ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: #f4f7f9; }
.btn-danger { background: var(--danger); }
.btn-warn { background: var(--warn); }

.collapsible {
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
}

.collapsible-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  user-select: none;
}

.collapsible-summary::-webkit-details-marker { display: none; }

.collapsible-hint::before {
  content: "باز کردن";
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  background: #fff;
}

.collapsible[open] .collapsible-hint::before {
  content: "بستن";
}

.collapsible-body {
  margin-top: 1rem;
  padding-top: 0.2rem;
  border-top: 1px solid var(--line);
  animation: rise 220ms ease both;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.filters input,
.filters select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: #fff;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.bubble-error {
  color: var(--danger);
  margin-top: 0.35rem;
  font-size: 0.82rem;
}

.attach-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  background: rgba(255, 255, 255, 0.8);
  font-size: 0.75rem;
  color: var(--accent-2);
}

.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.attach-size {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.65rem;
}

/* —— ChatGPT-like conversation view —— */
.main:has(.gpt-chat) {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main:has(.gpt-chat) > .topbar {
  display: none;
}

.main:has(.gpt-chat) > .flash-stack {
  margin: 0.65rem 1rem 0;
}

.gpt-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #f7f7f8;
}

.gpt-chat-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.gpt-chat-bar-text {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.gpt-chat-bar-text strong {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gpt-chat-bar .meta {
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gpt-provider-link {
  font-family: var(--mono);
  font-size: 0.72rem;
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 10px;
}

.gpt-chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 1rem 0 0.5rem;
}

.gpt-chat-column {
  width: min(768px, 100%);
  margin-inline: auto;
  padding: 0 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.gpt-row {
  display: flex;
  width: 100%;
}

.gpt-row.user {
  justify-content: flex-start; /* راست در RTL */
}

.gpt-row.assistant,
.gpt-row.system {
  justify-content: flex-end; /* چپ در RTL */
}

.gpt-msg {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  max-width: 100%;
}

.gpt-msg.user {
  max-width: min(85%, 36rem);
}

.gpt-msg.assistant {
  max-width: min(92%, 42rem);
  flex-direction: row-reverse; /* آواتار سمت چپ فیزیکی در RTL */
}

.gpt-avatar {
  flex: 0 0 auto;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 650;
  color: #fff;
  background: #10a37f;
  margin-top: 0.15rem;
}

.gpt-msg-main {
  min-width: 0;
}

.gpt-msg-body {
  padding: 0.55rem 0.85rem;
  border-radius: 1.15rem;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
}

.gpt-msg.user .gpt-msg-body {
  background: #e8e8ea;
}

.gpt-msg.assistant .gpt-msg-body {
  background: #fff;
  border: 1px solid #d8d8de;
  box-shadow: 0 1px 2px rgba(20, 33, 43, 0.04);
}


.gpt-meta {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--muted);
}

.gpt-empty {
  margin: 4rem auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.gpt-composer {
  width: min(768px, 100%);
  margin: 0 auto;
  padding: 0.5rem 1rem 1rem;
  background: linear-gradient(180deg, transparent, #f7f7f8 28%);
}

.gpt-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.45rem 0.5rem 0.45rem 0.55rem;
  border: 1px solid #d0d0d5;
  border-radius: 1.35rem;
  background: #fff;
  box-shadow: 0 4px 18px rgba(20, 33, 43, 0.06);
}

.gpt-composer-box textarea,
.gpt-composer-box .chat-input {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 0.55rem 0.35rem;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  background: transparent;
}

.gpt-attach {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 999px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  margin-bottom: 0.1rem;
  overflow: hidden;
}

.gpt-attach:hover {
  background: rgba(20, 33, 43, 0.07);
  color: var(--ink);
}

.gpt-attach-icon {
  display: block;
  pointer-events: none;
}

.gpt-attach input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.gpt-attach-names {
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 0.2rem;
}

.gpt-send {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: #0f766e;
  cursor: pointer;
  margin-bottom: 0.1rem;
}

.gpt-send:hover {
  background: #0e5f59;
}

.gpt-composer-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.45rem;
  padding-inline: 0.35rem;
}

.gpt-composer-foot .check-inline {
  margin-inline-end: 0;
  font-size: 0.78rem;
}

.gpt-composer-foot .meta {
  font-size: 0.75rem;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.empty {
  color: var(--muted);
  padding: 1.2rem 0.2rem;
  text-align: center;
  margin: auto;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(420px, 100%);
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.login-card h1 {
  margin: 0 0 0.35rem;
  letter-spacing: -0.04em;
}

.login-card p {
  margin: 0 0 1.1rem;
  color: var(--muted);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
