:root {
  --ink: #12242c;
  --muted: #5d717c;
  --line: #e4ece9;
  --bg: #eef4f1;
  --card: #ffffff;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #d9f2ec;
  --ok: #047857;
  --cash: #0f766e;
  --bank: #0369a1;
  --wait: #b45309;
  --pay: #be123c;
  --shadow: 0 1px 2px rgba(16, 42, 38, 0.05), 0 14px 40px rgba(16, 42, 38, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 100% -10%, #d7efe6 0%, transparent 55%),
    radial-gradient(900px 420px at -10% 0%, #e7f1fb 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: Vazirmatn, Tahoma, sans-serif;
}

.app {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 12px 16px 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page > section:not([hidden]) {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
  background: transparent;
  box-shadow: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-text span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.brand-text strong {
  font-size: 14px;
  font-weight: 800;
}

.updated {
  margin: 0;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 12px;
  background: #f3f8f6;
  border-radius: 12px;
  padding: 8px 12px;
  max-width: 100%;
  overflow: visible;
  white-space: normal;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 4px 12px;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 800;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.filters label.grow { flex: 1; min-width: min(220px, 100%); }

.filters input,
.filters select {
  height: 42px;
  border: 1px solid var(--line);
  background-color: #f8fbfa;
  padding: 0 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  min-width: 0;
  max-width: 100%;
  width: 100%;
  border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.filters textarea {
  min-height: 84px;
  border: 1px solid var(--line);
  background-color: #f8fbfa;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  width: 100%;
  border-radius: 12px;
  resize: vertical;
}

.mail-form {
  align-items: start;
}

.mail-status {
  margin: 0 16px 8px;
  color: var(--muted);
  font-size: 13px;
}

.error {
  margin: 0 16px 8px;
  color: #be123c;
  font-weight: 700;
}

.table-card + .table-card {
  margin-top: 16px;
}

.accordion-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: right;
  cursor: pointer;
}

.accordion-toggle strong {
  display: block;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 4px;
}

.accordion-toggle .summary {
  margin: 0;
}

.accordion-icon {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #eef5f2;
  position: relative;
}

.accordion-icon::before,
.accordion-icon::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 12px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transform: translate(-50%, -50%);
}

.accordion-icon::after {
  transform: translate(-50%, -50%) rotate(90deg);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.accordion.open .accordion-icon::after {
  transform: translate(-50%, -50%) rotate(0deg);
  opacity: 0;
}

.accordion-body {
  border-top: 1px solid var(--line);
}

.filters input:focus,
.filters select:focus,
.filters textarea:focus {
  outline: none;
  background-color: #fff;
  border-color: #99d6cc;
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.btn {
  height: 42px;
  border: 0;
  background: linear-gradient(180deg, #11998a, var(--accent));
  color: #fff;
  padding: 0 18px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 12px;
  box-shadow: 0 8px 16px rgba(15, 118, 110, 0.2);
}

.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.65; cursor: wait; }

.btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 4px;
  background: #eef5f2;
  border-radius: 14px;
  justify-self: center;
}

.nav-btn {
  height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 16px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 11px;
}

.nav-btn[hidden],
.admin-only[hidden] {
  display: none !important;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tab {
  border: 1px solid var(--line);
  background: var(--card);
  padding: 16px 16px 14px;
  text-align: right;
  cursor: pointer;
  font-family: inherit;
  border-radius: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tab:hover { transform: translateY(-2px); }

.tab::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--tone, var(--accent));
}

.tab-atCash { --tone: var(--cash); }
.tab-assignedToBank { --tone: var(--bank); }
.tab-inCollection { --tone: var(--wait); }
.tab-payable { --tone: var(--pay); }

.tab.active {
  border-color: transparent;
  background: var(--tone, var(--accent));
  color: #fff;
  box-shadow: 0 14px 30px rgba(15, 118, 110, 0.28);
}

.tab b,
.tab-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
  opacity: 0.88;
}

.tab .count { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.tab .amount { font-size: 12px; opacity: 0.82; margin-top: 6px; font-weight: 600; overflow-wrap: anywhere; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 0;
}

.summary {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 18px 4px;
}

.stat {
  padding: 14px 16px;
  border-radius: 14px;
  background: #f4faf8;
  border: 1px solid var(--line);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.stat b {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.stat.total {
  background: linear-gradient(135deg, #0f766e, #115e59);
  color: #fff;
  border: 0;
}

.stat.total span { color: rgba(255, 255, 255, 0.78); }
.stat.total small { font-size: 12px; font-weight: 600; margin-right: 6px; opacity: 0.8; }

.table-card { overflow: hidden; }

.table-wrap {
  overflow: visible;
  margin-top: 12px;
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 8px;
  border-bottom: 1px solid #eef3f1;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  text-align: right;
  background: #f7fbf9;
  font-weight: 700;
  color: #4d646e;
  position: sticky;
  top: 0;
  font-size: 12px;
}

tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: #f4fbf8; }

.docs-table td:last-child,
.docs-table th:last-child {
  white-space: normal;
  min-width: 0;
  color: var(--muted);
}

.num {
  text-align: left;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.money {
  font-weight: 800;
  color: var(--accent-2);
}

.party { font-weight: 700; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 12px;
  font-weight: 600;
}

.error { color: var(--pay); }

.bank-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: hsl(var(--hue, 170) 42% 38%);
  flex: 0 0 auto;
}

.bank-cell strong { display: block; font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; }

.mono {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: left;
  color: #3e5560;
}

.money-cell {
  min-width: 0;
}

.money-cell strong {
  display: block;
  font-size: 14px;
}

.bar {
  display: block;
  height: 6px;
  border-radius: 999px;
  background: #e6f3ef;
  margin-top: 6px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5eead4, #0f766e);
}

.jalali-input {
  min-width: 0;
  width: 100%;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%235d717c' stroke-width='1.6'%3E%3Crect x='2.5' y='3.5' width='13' height='12' rx='1.5'/%3E%3Cpath d='M2.5 7.5h13M6 2v3M12 2v3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 10px center;
  background-color: #f8fbfa;
  padding-left: 34px !important;
}

jdp-container {
  --jdp-primary: #0f766e;
  --jdp-color-0: #ffffff;
  --jdp-color-1: #d9f2ec;
  --jdp-color-2: #e4ece9;
  --jdp-color-5: #12242c;
  font-family: Vazirmatn, Tahoma, sans-serif;
}

.session {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  justify-self: end;
}

.session .updated {
  margin-inline-start: 0;
  max-width: none;
}

#whoami {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-2);
}

.row-actions {
  display: flex;
  gap: 8px;
}

.row-actions button {
  height: 32px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: inherit;
  cursor: pointer;
  padding: 0 10px;
  border-radius: 8px;
}

.table-card .filters {
  margin: 12px 18px 0;
}

.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  padding: 28px 26px 26px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.auth-card .brand {
  justify-content: center;
  min-width: 0;
  width: 100%;
}

.auth-card h1 {
  font-size: 24px;
  margin: 18px 0 8px;
  text-align: center;
}

.auth-lead {
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 14px;
  text-align: center;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.auth-card input {
  width: 100%;
  margin-bottom: 12px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0 12px;
  font-family: inherit;
  font-size: 14px;
  background: #f8fbfa;
}

.auth-card .btn { width: 100%; margin-top: 6px; }

.auth-alt {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.auth-alt summary { cursor: pointer; font-weight: 700; }
.auth-alt form { margin-top: 12px; }

.filters label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.filters label.check input { width: 18px; height: 18px; }

.analyst-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.analyst-card .card-head {
  align-items: flex-start;
  flex-shrink: 0;
}

.analyst-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#page-analyst:not([hidden]) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.analyst-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}

.analyst-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.analyst-archive {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  border: 0;
  border-inline-start: 1px solid var(--line);
  border-radius: 0;
  background: #f4faf8;
}

.archive-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 8px;
  flex-shrink: 0;
}

.archive-head strong {
  font-size: 14px;
}

.analyst-archive > .summary {
  padding: 0 12px 8px;
  margin: 0;
  flex-shrink: 0;
}

.archive-list {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 0 8px 12px;
}

.archive-head .btn {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.archive-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 6px;
  border-radius: 10px;
  text-align: right;
}

.archive-item:hover {
  background: #fff;
}

.archive-item.active {
  background: #fff;
  box-shadow: 0 0 0 1px #99d6cc;
}

.archive-item .archive-open {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: right;
  cursor: pointer;
}

.archive-item .archive-open b {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-item .archive-open span {
  color: var(--muted);
  font-size: 12px;
}

.archive-item .archive-del {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: #be123c;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 8px;
}

.archive-item .archive-del:hover {
  background: #fff1f2;
}

.archive-list .empty {
  margin: 0;
  padding: 8px 8px 12px;
  color: var(--muted);
  font-size: 13px;
}

.analyst-chat {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 16px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, #f8fbfa 0%, #fff 40%);
}

.analyst-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  max-width: 28rem;
  line-height: 1.7;
}

.analyst-msg {
  max-width: min(720px, 92%);
  padding: 12px 14px;
  border-radius: 16px;
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 14px;
}

.analyst-msg.user {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.analyst-msg.assistant {
  align-self: flex-end;
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.analyst-msg.pending {
  color: var(--muted);
  font-style: italic;
}

.analyst-composer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.analyst-composer textarea {
  flex: 1;
  min-width: min(240px, 100%);
  min-height: 46px;
  max-height: 140px;
  border: 1px solid var(--line);
  background: #f8fbfa;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

.analyst-composer textarea:focus {
  outline: none;
  background: #fff;
  border-color: #99d6cc;
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.btn.mic {
  width: 42px;
  padding: 0;
  font-size: 18px;
}

.btn.mic.live {
  background: #be123c;
  color: #fff;
  border-color: #be123c;
}

@media (max-width: 980px) {
  .tabs { grid-template-columns: 1fr 1fr; }
  .topbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
  }
  .app-nav { width: 100%; }
  .updated { margin-right: 0; max-width: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .session { margin-inline-start: 0; width: 100%; justify-content: flex-end; }
  .analyst-shell { grid-template-columns: 1fr; }
  .analyst-archive {
    border-inline-start: 0;
    border-top: 1px solid var(--line);
    max-height: 220px;
  }
}

@media (max-width: 720px) {
  h1 { font-size: 24px; }
  .app { padding: 8px 8px 12px; }
}
