:root {
  --primary: #059669;
  --primary-light: #10b981;
  --accent: #0284c7;
  --bg: #0f172a;
  --card-bg: #1e293b;
  --card-border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --warning: #f59e0b;
  --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: #34d399;
  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: #f8fafc;
  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: #fca5a5;
  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: #7dd3fc;
  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: rgba(15, 23, 42, 0.5);
  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: #fecaca;
  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: #0f172a;
  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: rgba(15, 23, 42, 0.65);
  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: #34d399;
  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: #0f172a;
  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: rgba(15, 23, 42, 0.6);
  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: #34d399;
  font-size: 0.98rem;
  white-space: nowrap;
}

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

.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: #7dd3fc;
  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: rgba(15, 23, 42, 0.96);
  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;
}
