:root {
  --primary: #0F766E;
  --primary-light: #148278;
  --accent: #0F766E;
  --bg: #F8FAFC;
  --card-bg: #FFFFFF;
  --card-border: #DCE7E2;
  --text: #0F172A;
  --text-muted: #647477;
  --danger: #c2414c;
  --warning: #a16207;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Vazirmatn", "Tahoma", system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  direction: rtl;
  text-align: right;
  line-height: 1.55;
  min-height: 100vh;
  padding-bottom: 0;
}

html.has-auth-token #auth-screen {
  display: none !important;
}
html.has-auth-token #main-app-shell {
  display: flex !important;
}
html.no-auth-token #auth-screen {
  display: flex !important;
}
html.no-auth-token #main-app-shell {
  display: none !important;
}

code,
pre,
bdi,
.ltr-text {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

input[dir="ltr"] {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
}

/* Mobile Container */
.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Header (Compact Single Row) */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  padding: 9px 14px;
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-size: 0.94rem;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.brand-subtitle {
  display: none;
}

.user-pill {
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  white-space: nowrap;
  max-width: 155px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dynamic Server Announcement Banner */
.server-banner {
  display: none;
}

/* Main Content Area */
.main-content {
  padding: 10px 12px 46px;
  flex: 1;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.tab-panel.active {
  display: block;
}

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

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.card-title {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(16, 185, 129, 0.18);
  color: #0F766E;
  font-weight: 600;
}

/* Step 1: Camera / Receipt Input */
.capture-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 11px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.35);
}

.btn-secondary {
  background: #334155;
  color: #0F172A;
  border: 1px solid #475569;
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #fff;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #b42335;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-block {
  width: 100%;
}

/* Sample Chips */
.sample-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.sample-chip {
  white-space: nowrap;
  background: rgba(2, 132, 199, 0.16);
  border: 1px solid rgba(2, 132, 199, 0.4);
  color: #0F766E;
  padding: 6px 11px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}

/* Receipt Preview Box */
.receipt-preview-box {
  position: relative;
  border: 2px dashed #475569;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  background: #F1F7F4;
  margin-top: 8px;
}

.receipt-preview-box img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  margin: 0 auto 8px;
}

/* Voice Recording Box */
.voice-recorder-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-btn {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.15);
  border: 2px solid rgba(239, 68, 68, 0.45);
  color: #b42335;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  transition: all 0.2s ease;
}

.record-btn.recording {
  background: #dc2626;
  color: #fff;
  border-color: #f87171;
  animation: pulseRecord 1.2s infinite;
}

@keyframes pulseRecord {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.65); }
  70% { box-shadow: 0 0 0 14px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* Inputs & Forms */
.form-group {
  margin-bottom: 8px;
}

.form-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: #F8FAFC;
  border: 1px solid #334155;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.84rem;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-light);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Dashboard Summary Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: #F1F7F4;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
}

.stat-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0F766E;
  margin-top: 3px;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Category Bars */
.cat-bar-item {
  margin-bottom: 10px;
}

.cat-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.cat-bar-track {
  height: 8px;
  background: #F8FAFC;
  border-radius: 99px;
  overflow: hidden;
}

.cat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
}

/* Transaction List */
.tx-item {
  background: #F1F7F4;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tx-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.tx-merchant {
  font-weight: 700;
  font-size: 0.94rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tx-amount {
  font-weight: 800;
  color: #0F766E;
  font-size: 0.98rem;
  white-space: nowrap;
}

.tx-summary {
  font-size: 0.82rem;
  color: #475569;
}

.tx-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 0.73rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(51, 65, 85, 0.6);
  padding-top: 8px;
}

.tx-media-badges {
  display: flex;
  gap: 6px;
  align-items: center;
}

.media-btn {
  background: rgba(2, 132, 199, 0.18);
  border: 1px solid rgba(2, 132, 199, 0.4);
  color: #0F766E;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
}

/* Bottom Navigation Bar (Compact Horizontal Buttons: Text Beside Icon) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  max-width: 520px;
  margin: 0 auto;
  background: #F1F7F4;
  backdrop-filter: blur(12px);
  border-top: 1px solid #334155;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 4px 12px 5px;
  z-index: 40;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 9px;
  white-space: nowrap;
}

.nav-item.active {
  color: var(--primary-light);
  background: rgba(16, 185, 129, 0.12);
}

.nav-icon {
  font-size: 0.95rem;
  line-height: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  padding: 18px;
  max-height: 88vh;
  overflow-y: auto;
}

/* Toast Notification */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #065f46;
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: none;
}

.toast.show {
  display: block;
}

/* Risido: Persian-first, light surfaces and restrained teal accents. */
body { background: radial-gradient(ellipse at top right, #e4f5eb, transparent 55%), var(--bg); }
.app-shell { background: var(--bg); box-shadow: 0 0 60px #0f766e08; }
#auth-screen { max-width: 480px; background: transparent; box-shadow: none; }
#auth-screen > .card { border: 1px solid var(--card-border) !important; border-radius: 24px; padding: 32px 28px !important; box-shadow: 0 20px 60px #0f766e0c !important; }
.auth-brand-icon { display: block; margin: 0 auto 12px; }
.brand-kicker { color: var(--primary); font-size: 10px; letter-spacing: 4px; margin-bottom: 12px; font-weight: 700; }
#auth-screen-title { font-size: 1.8rem !important; color: var(--primary) !important; }
#auth-screen-subtitle { color: var(--text-muted) !important; margin: 8px 0 24px; }
.app-header { background: white; border-bottom: 1px solid var(--card-border); border-radius: 0 0 20px 20px; padding: 14px; box-shadow: 0 4px 20px #0f766e05; }
.brand-title { color: var(--primary); font-size: 1.1rem; }
.user-pill { background: #eff7f2; color: var(--primary); border-color: var(--card-border); }
#btn-header-logout { color: #b42335; background: #fff1f1 !important; border-color: #f1d5d8 !important; }
.card { padding: 18px; box-shadow: 0 4px 20px #0f766e04; margin-bottom: 14px; }
.card-title { margin-bottom: 14px; }
.btn { border-radius: 12px; min-height: 42px; }
.btn-primary, .btn-accent { background: var(--primary); color: #fff; box-shadow: 0 4px 12px #0f766e14; }
.btn-primary:hover, .btn-accent:hover { background: #095e58; }
.btn-secondary { background: #f1f7f4; color: var(--primary); border: 1px solid var(--card-border); }
.btn-danger, .record-btn { background: #fff1f1; color: #b42335; border-color: #efccd1; }
.form-input, .form-select, .form-textarea { background: #f8faf9; border-color: var(--card-border); border-radius: 12px; padding: 11px 12px; min-height: 44px; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #0f766e12; }
.form-label { color: #475f59; margin-bottom: 6px; }
.stat-box, .tx-item { background: #f8fbf9; border-color: var(--card-border); }
.stat-value, .tx-amount, .badge { color: var(--primary); }
.sample-chip, .media-btn { background: #eef8f1; color: var(--primary); border-color: #cfe5d7; }
.receipt-preview-box { background: #f1f8f4; border-color: #b6d5c6; }
.cat-bar-track { background: #e4eee8; }
.bottom-nav { background: #ffffffef; border-color: var(--card-border); padding: 8px 12px max(8px, env(safe-area-inset-bottom)); }
.nav-item { min-height: 40px; }
.nav-item.active { color: var(--primary); background: #e8f5ed; }
.main-content { padding-bottom: 86px; }
.modal-box { box-shadow: 0 20px 60px #0f172a20; }
button:focus-visible, a:focus-visible { outline: 3px solid #22c55e; outline-offset: 3px; }
@media (max-width: 380px) { #auth-screen > .card { padding: 24px 18px !important; } .header-top { flex-wrap: wrap; } .form-row { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Mobile receipt entry and tap-to-expand report details. */
.capture-help { color: var(--text-muted); font-size: .8rem; line-height: 1.9; margin: 8px 0 12px; }
#capture-status:empty { display: none; }
button:disabled { opacity: .6; cursor: wait; }
.receipt-text-disclosure { border: 1px solid var(--card-border); border-radius: 12px; background: #f1f7f4; margin: 8px 0; overflow: hidden; }
.receipt-text-disclosure summary, #manual-receipt-entry summary, #receipt-text-details summary { min-height: 44px; padding: 10px 12px; cursor: pointer; font-size: .82rem; line-height: 1.7; }
.receipt-text-content { padding: 0 12px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8rem; line-height: 1.9; }
summary:focus-visible { outline: 3px solid #22c55e; outline-offset: -3px; }
.tx-item { overflow-wrap: anywhere; }
.tx-media-badges { flex-wrap: wrap; }
.media-btn, .user-pill { min-height: 44px; }
.toast { width: max-content; max-width: calc(100vw - 24px); border-radius: 16px; text-align: center; line-height: 1.8; }
@media (max-width: 600px) {
  .form-input, .form-select, .form-textarea { font-size: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .tx-top, .tx-meta { flex-wrap: wrap; gap: 8px; }
  .brand-title { flex-shrink: 0; }
  #btn-user-modal { max-width: 140px; }
}
