/* ─── CSS custom properties – overridden per tenant after login ─── */
:root {
  --color-primary-50:  #f0f9ff;
  --color-primary-100: #e0f2fe;
  --color-primary-200: #bae6fd;
  --color-primary-500: #0ea5e9;
  --color-primary-600: #0284c7;
  --color-primary-700: #0369a1;
  --color-accent: #FFB300;
}

/* ─── Base ─── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
#app { height: 100%; }

/* ─── App shell ─── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 240px;
  background: white;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.main-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.content-area {
  flex: 1;
  padding: 24px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.mobile-header {
  display: none;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  padding: 12px 16px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
}

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e2e8f0;
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-header { display: flex; }
  .bottom-nav { display: flex; }
  .content-area {
    padding: 16px;
    padding-bottom: 80px;
  }
}

/* ─── Sidebar nav items ─── */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  color: #64748b;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
  margin: 2px 8px;
}
.nav-item:hover { background: #f1f5f9; color: #0f172a; }
.nav-item.active {
  background: var(--color-primary-50);
  color: var(--color-primary-700);
}
.nav-item svg { flex-shrink: 0; }

/* ─── Bottom nav item ─── */
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.625rem;
  font-weight: 500;
  gap: 3px;
  transition: color 0.15s;
  border: none;
  background: none;
}
.bottom-nav-item.active { color: var(--color-primary-600); }

/* ─── Cards ─── */
.card {
  background: white;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  padding: 20px;
}
.card-hover {
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: pointer;
}
.card-hover:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

/* ─── Status badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-teal   { background: #ccfbf1; color: #134e4a; }
.badge-slate  { background: #f1f5f9; color: #475569; }
.badge-indigo { background: #e0e7ff; color: #3730a3; }

/* ─── Shimmer loading ─── */
.shimmer {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  outline: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--color-primary-600);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-700); }
.btn-secondary {
  background: #f1f5f9;
  color: #334155;
}
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-danger {
  background: #fee2e2;
  color: #991b1b;
}
.btn-danger:hover:not(:disabled) { background: #fecaca; }
.btn-success {
  background: #dcfce7;
  color: #166534;
}
.btn-success:hover:not(:disabled) { background: #bbf7d0; }
.btn-warning {
  background: #fef9c3;
  color: #854d0e;
}
.btn-warning:hover:not(:disabled) { background: #fef08a; }
.btn-sm { padding: 5px 12px; font-size: 0.8125rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-full { width: 100%; }

/* ─── Form elements ─── */
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: white;
  color: #0f172a;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px var(--color-primary-100);
}
.form-input.error { border-color: #f87171; }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 36px;
}
textarea.form-input { resize: vertical; min-height: 80px; }

/* ─── Avatar ─── */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
  color: white;
  background: var(--color-primary-600);
}
.avatar-sm { width: 32px; height: 32px; font-size: 0.75rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.125rem; }
.avatar-xl { width: 72px; height: 72px; font-size: 1.375rem; }

/* ─── Chat ─── */
.chat-bubble-user {
  background: var(--color-primary-600);
  color: white;
  border-radius: 18px 18px 4px 18px;
}
.chat-bubble-ai {
  background: white;
  border: 1px solid #e2e8f0;
  color: #1e293b;
  border-radius: 18px 18px 18px 4px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0ms; }
.typing-dot:nth-child(2) { animation-delay: 120ms; }
.typing-dot:nth-child(3) { animation-delay: 240ms; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Streaming chat additions */
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--color-primary-600);
  border-radius: 2px;
  animation: stream-blink 0.9s steps(2, start) infinite;
}
@keyframes stream-blink { to { visibility: hidden; } }

.chat-status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  padding: 2px 4px;
  color: #64748b;
  font-size: 12px;
  font-style: italic;
}
.chat-status-line:empty { display: none; }

.chat-error-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  color: #b91c1c;
  font-size: 13px;
}

.chat-copy-btn {
  font-size: 11px;
  color: #94a3b8;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.chat-copy-btn:hover { color: var(--color-primary-600); }

.chat-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.source-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11.5px;
  color: var(--color-primary-700, #0f766e);
  background: var(--color-primary-50, #f0fdfa);
  border: 1px solid var(--color-primary-100, #ccfbf1);
  border-radius: 8px;
}
.chat-action-card {
  margin-top: 8px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

/* Markdown rendering inside assistant bubbles */
.markdown-body p { margin: 0 0 8px; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body ul, .markdown-body ol { margin: 4px 0 8px; padding-left: 20px; }
.markdown-body li { margin: 2px 0; }
.markdown-body code {
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.markdown-body pre {
  background: #f1f5f9;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  margin: 6px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--color-primary-400, #2dd4bf);
  background: var(--color-primary-50, #f0fdfa);
  color: #475569;
}
.markdown-body a { color: var(--color-primary-600); text-decoration: underline; }
.markdown-body table { border-collapse: collapse; margin: 6px 0; }
.markdown-body th, .markdown-body td { border: 1px solid #e2e8f0; padding: 4px 8px; font-size: 12.5px; }

/* ─── Page transitions ─── */
.screen-enter {
  animation: screen-fade-in 0.2s ease-out;
}
@keyframes screen-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Leave balance gradient card ─── */
.balance-card {
  background: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-700) 100%);
  color: white;
  border-radius: 20px;
  padding: 24px;
}

/* ─── Tabs ─── */
.tab-bar {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  color: #64748b;
  transition: all 0.15s;
}
.tab-btn.active {
  background: white;
  color: #0f172a;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ─── Org tree indentation ─── */
.org-tree-row {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: white;
  margin-bottom: 6px;
  transition: box-shadow 0.15s;
}
.org-tree-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

/* ─── Toast notification ─── */
.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
@media (min-width: 769px) {
  .toast-container { bottom: 24px; }
}
.toast {
  background: #1e293b;
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toast-in 0.25s ease-out, toast-out 0.25s ease-in 2.5s forwards;
  pointer-events: auto;
}
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; } }

/* ─── Drawer/Modal overlay ─── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: white;
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in 0.2s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* ─── Divider ─── */
.divider { height: 1px; background: #e2e8f0; margin: 16px 0; }

/* ─── Empty state ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 12px;
}
.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Reporting chain ─── */
.chain-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  color: #475569;
}
.chain-separator { color: #cbd5e1; }

/* ─── Login page ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #f0fdf4 100%);
  padding: 24px;
}
.login-card {
  background: white;
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.1);
}

/* ─── Section headings ─── */
.section-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}
.section-subtitle {
  font-size: 0.9375rem;
  color: #64748b;
  margin-bottom: 20px;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Input with icon ─── */
.input-group { position: relative; }
.input-group .input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  pointer-events: none;
}
.input-group .form-input { padding-left: 40px; }
.input-group .input-suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: #94a3b8;
  background: none;
  border: none;
  padding: 2px;
  display: flex;
}
.input-group .input-suffix:hover { color: #475569; }

/* ─── Chat prompt chips ─── */
.prompt-chip {
  display: inline-block;
  padding: 8px 14px;
  background: var(--color-primary-50);
  border: 1px solid var(--color-primary-100);
  color: var(--color-primary-700);
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.prompt-chip:hover {
  background: var(--color-primary-100);
  border-color: var(--color-primary-200);
}
