/* Artifact platform tokens — auto-resolved */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #root {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  color: inherit;
}

a { color: var(--primary); text-decoration: none; }

/* ---------- Layout ---------- */
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 96px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 4px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: white;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand-name {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
}
.brand-sub {
  color: var(--text-muted);
  font-size: 12px;
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-tint);
  color: var(--primary-dark);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.user-chip-name { font-size: 13px; font-weight: 600; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  margin-bottom: 20px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}
.tab svg { width: 16px; height: 16px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 720px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Stat card ---------- */
.stat {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  overflow: hidden;
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--text-muted); }
.stat-icon {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: var(--primary-tint);
  color: var(--primary-dark);
  display: grid; place-items: center;
}
.stat.danger .stat-icon { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.stat.warning .stat-icon { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.stat.success .stat-icon { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.stat.danger .stat-value { color: var(--danger); }
.stat.warning .stat-value { color: var(--warning); }
.stat.success .stat-value { color: var(--success); }

/* ---------- Quick actions ---------- */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}
.qa-btn {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  font-size: 13px; font-weight: 600;
  transition: transform .1s, box-shadow .15s;
}
.qa-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.qa-btn .qa-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-tint);
  color: var(--primary-dark);
  display: grid; place-items: center;
}
.qa-btn.primary .qa-icon { background: var(--primary); color: white; }
.qa-btn.accent .qa-icon { background: var(--accent); color: white; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--neutral); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--text-muted); }
.btn.ghost:hover { background: var(--neutral); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn svg { width: 16px; height: 16px; }

/* ---------- Section header ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 8px 4px 16px;
}
.section-head h2 { font-size: 20px; font-weight: 700; }
.section-head p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ---------- List rows ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.row-icon {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  background: var(--primary-tint);
  color: var(--primary-dark);
  display: grid; place-items: center; flex-shrink: 0;
}
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 14px; }
.row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.row-value { font-weight: 700; font-size: 15px; text-align: right; }
.row-actions { display: flex; gap: 4px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600;
  background: var(--neutral);
  color: var(--text-muted);
}
.badge.pending { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge.paid { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge.overdue { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.cancelled { background: var(--neutral); color: var(--text-muted); text-decoration: line-through; }

/* ---------- Filters ---------- */
.filters {
  display: flex; gap: 6px; margin-bottom: 12px;
  flex-wrap: wrap;
}
.chip {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
}
.chip[aria-pressed="true"] { background: var(--primary); color: white; }

/* ---------- Empty ---------- */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty h3 { font-size: 16px; margin-bottom: 4px; color: var(--text); }

/* ---------- Dialog ---------- */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); }
.dialog-body { padding: 24px; }
.dialog-body h2 { font-size: 18px; margin-bottom: 4px; }
.dialog-body .hint { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form input, .form textarea, .form select {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.form input:focus, .form textarea:focus, .form select:focus {
  border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

menu {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px; padding: 0;
  list-style: none;
}

/* ---------- Chat ---------- */
.chat-wrap {
  display: flex; flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 480px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--neutral);
  display: flex; align-items: center; gap: 12px;
}
.wa-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: white;
  display: grid; place-items: center;
}
.chat-header .h-title { font-weight: 700; font-size: 15px; }
.chat-header .h-sub { font-size: 12px; color: var(--text-muted); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--bg);
}
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.bubble.welcome {
  align-self: center;
  background: var(--primary-tint);
  color: var(--primary-dark);
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}

.chat-input-wrap {
  padding: 12px;
  border-top: 1px solid var(--neutral);
  display: flex; gap: 8px;
  background: var(--surface);
}
.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-lg);
  font-size: 14px;
  outline: none;
}
.chat-input:focus { border-color: var(--primary); }
.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary); color: white;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.suggestions {
  display: flex; gap: 8px; padding: 0 20px 12px; overflow-x: auto;
  background: var(--bg);
  scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestion {
  padding: 8px 14px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  font-size: 12px; font-weight: 600;
  color: var(--primary-dark);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.suggestion:hover { background: var(--primary-tint); }

/* ---------- Category pill ---------- */
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--primary-tint);
  color: var(--primary-dark);
  font-size: 11px; font-weight: 600;
}

/* ---------- WhatsApp connect card ---------- */
.wa-connect {
  padding: 24px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}
.wa-connect .wa-big {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--scrim);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.wa-connect h3 { font-size: 16px; margin-bottom: 4px; }
.wa-connect p { font-size: 13px; opacity: 0.9; }

/* ---------- Toggle ---------- */
.toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.toggle-title { font-weight: 600; font-size: 14px; }
.toggle-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.switch {
  width: 44px; height: 24px;
  border-radius: 12px;
  background: var(--neutral);
  position: relative;
  transition: background .15s;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: var(--shadow-sm);
  transition: transform .15s;
}
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* ---------- Charts ---------- */
.cat-chart { display: flex; flex-direction: column; gap: 12px; }
.cat-row { display: flex; flex-direction: column; gap: 6px; }
.cat-row-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.cat-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.cat-name { font-weight: 600; flex: 1; min-width: 0; }
.cat-val { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.cat-bar {
  height: 8px;
  background: var(--neutral);
  border-radius: 999px;
  overflow: hidden;
}
.cat-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .3s;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  height: 200px;
  align-items: end;
}
.bar-col {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  height: 100%;
}
.bar-value { font-size: 10px; font-weight: 600; color: var(--text-muted); min-height: 14px; }
.bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.bar {
  width: 70%;
  min-height: 2px;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  border-radius: 6px 6px 0 0;
  transition: height .3s;
}
.bar-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: capitalize; }

.cashflow-chart {
  display: flex; flex-direction: column; gap: 8px;
}
.cashflow-legend {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-muted); font-weight: 600;
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .app { padding: 0 12px 24px; }
  .topbar { padding: 16px 4px; }
  .brand-name { font-size: 17px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stat-value { font-size: 20px; }
}
