/* Tallbook — accessible, clean accounting UI */
/* WCAG 2.2 AA: 4.5:1 text, 3:1 UI components */

:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --bg-nav: #1a1a2e;
  --bg-nav-hover: #16213e;
  --text: #1a1a1a;
  --text-muted: #555555;
  --text-nav: #e8e8e8;
  --border: #c0c0c0;
  --border-focus: #2563eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #a16207;
  --warning-bg: #fef9c3;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --info-bg: #dbeafe;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

/* Focus indicators — WCAG */
:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
}

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--bg-nav);
  color: var(--text-nav);
  padding: 1rem 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar h1 {
  font-size: 1.25rem;
  padding: 0 1rem 1rem;
  margin: 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar nav { padding: 0.5rem 0; }
.sidebar a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text-nav);
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}
.sidebar a:hover, .sidebar a:focus-visible {
  background: var(--bg-nav-hover);
}
.sidebar a.active {
  border-left-color: var(--accent);
  background: var(--bg-nav-hover);
  font-weight: 600;
}
.sidebar .nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1rem 1rem 0.25rem;
  color: #8888aa;
}

.main {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 1200px;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.page-header h2 { margin: 0; font-size: 1.5rem; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h3 { margin: 0 0 0.75rem; font-size: 1.1rem; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.stat-card .value.positive { color: var(--success); }
.stat-card .value.negative { color: var(--danger); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); background: var(--bg); }
tr:hover td { background: #f5f5ff; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.amount { font-family: "SF Mono", Menlo, monospace; font-size: 0.85rem; }
.amount.debit { color: var(--text); }
.amount.credit { color: var(--success); }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-draft { background: var(--warning-bg); color: var(--warning); }
.badge-posted { background: var(--success-bg); color: var(--success); }
.badge-voided { background: var(--danger-bg); color: var(--danger); }
.badge-pending { background: var(--info-bg); color: var(--accent); }
.badge-matched { background: var(--success-bg); color: var(--success); }
.badge-created { background: var(--info-bg); color: var(--accent); }
.badge-unmatched { background: var(--warning-bg); color: var(--warning); }
.badge-ignored { background: #f3f4f6; color: #6b7280; }
.badge-reconciled { background: var(--success-bg); color: var(--success); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: #f0f0f0; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-card);
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #86efac; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.alert-info { background: var(--info-bg); color: var(--accent); border: 1px solid #93c5fd; }

/* Chat layout with sidebar */
.chat-layout { display: flex; gap: 0; height: calc(100vh - 8rem); }
.chat-sidebar {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-sidebar-header {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.chat-sidebar-header .btn { width: 100%; }
.chat-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
}
.chat-sidebar-item {
  display: block;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.chat-sidebar-item:hover { background: var(--info-bg); }
.chat-sidebar-item.active {
  background: var(--info-bg);
  border-left-color: var(--accent);
  font-weight: 600;
}
.chat-sidebar-item .conv-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-sidebar-item .conv-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.chat-sidebar-item-actions {
  display: none;
  float: right;
  gap: 0.25rem;
}
.chat-sidebar-item:hover .chat-sidebar-item-actions { display: inline-flex; }
.chat-sidebar-item-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  color: var(--text-muted);
}
.chat-sidebar-item-actions button:hover { background: var(--danger-bg); color: var(--danger); }
.chat-container { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem 0; }
@media (max-width: 768px) {
  .chat-sidebar { display: none; }
  .chat-layout { flex-direction: column; }
}
.chat-message { margin-bottom: 1rem; display: flex; gap: 0.75rem; }
.chat-message.user { flex-direction: row-reverse; }
.chat-bubble {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}
.chat-message.user .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-message.assistant .chat-bubble { background: var(--bg-card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
}
.chat-input-row input { flex: 1; }
.chat-tool-call {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: #f5f5f5;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  margin-top: 0.5rem;
  font-family: monospace;
}
.chat-examples {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem 1rem;
}
.chat-examples-title {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}
.chat-examples-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  max-width: 600px;
}
.chat-example-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-interactive, #6e6e82);
  border-radius: 1rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.chat-example-chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chat-example-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Utility */
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; } .gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; }
.justify-end { justify-content: flex-end; }
.hidden { display: none; }
.mono { font-family: "SF Mono", Menlo, monospace; }

/* Loading indicator (htmx) */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }
.spinner { width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state p { font-size: 1.1rem; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-card); border-radius: var(--radius); padding: 1.5rem;
  width: 90%; max-width: 600px; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.modal h3 { margin: 0 0 1rem; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar a span, .sidebar h1 span, .sidebar .nav-section { display: none; }
  .sidebar a { text-align: center; padding: 0.75rem 0.5rem; font-size: 1.2rem; }
  .main { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}
