/* ============================================================
   TONY — CSS principal
   Mobile-first, componentes reutilizáveis, estética minimalista.
   As cores vêm de theme.css.php (gerado a partir da config central).
   ============================================================ */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body {
  min-height: 100dvh;
}

/* Evita zoom involuntário em inputs no iPhone: fonte >= 16px */
input, textarea, select, button {
  font-family: inherit;
  font-size: 16px;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
}

.container-wide {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ------------------------------------------------------------
   Tipografia
   ------------------------------------------------------------ */
h1, h2, h3, h4 {
  margin: 0 0 8px 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

p {
  margin: 0 0 12px 0;
  line-height: 1.5;
  color: var(--color-text);
}

.text-muted {
  color: var(--color-text-muted);
}

.text-sm {
  font-size: 13px;
}

.text-center {
  text-align: center;
}

/* ------------------------------------------------------------
   Botões
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.05s ease;
  width: 100%;
}

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

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text);
}

.btn-sm {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 14px;
  width: auto;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  width: 48px;
  min-height: 48px;
  padding: 0;
  flex: none;
}

/* ------------------------------------------------------------
   Inputs
   ------------------------------------------------------------ */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text-muted);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="date"],
.field input[type="time"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-background);
  color: var(--color-text);
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--color-accent);
}

.field-error {
  color: var(--color-danger);
  font-size: 13px;
  margin-top: 6px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.checkbox-row input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
}

/* ------------------------------------------------------------
   Cards
   ------------------------------------------------------------ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.card-flat {
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
}

/* ------------------------------------------------------------
   Navegação superior
   ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-background);
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
}

.topbar-brand .logo-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--color-primary);
}

/* ------------------------------------------------------------
   Navegação inferior (mobile tab bar)
   ------------------------------------------------------------ */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--color-background);
  border-top: 1px solid var(--color-border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  font-size: 11px;
  color: var(--color-text-muted);
  min-height: 48px;
  justify-content: center;
}

.tabbar-item.active {
  color: var(--color-text);
  font-weight: 600;
}

.tabbar-item svg {
  width: 22px;
  height: 22px;
}

/* ------------------------------------------------------------
   Layout de página autenticada (com tabbar)
   ------------------------------------------------------------ */
.app-shell {
  padding-bottom: 88px;
  min-height: 100dvh;
}

/* ------------------------------------------------------------
   Lista de lembretes
   ------------------------------------------------------------ */
.reminder-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  background: var(--color-background);
}

.reminder-item.overdue {
  border-color: var(--color-danger);
  background: color-mix(in srgb, var(--color-danger) 5%, var(--color-background));
}

.reminder-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  flex: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.reminder-checkbox.checked {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}

.reminder-content {
  flex: 1;
  min-width: 0;
}

.reminder-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.reminder-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.badge-priority-high { color: var(--color-danger); border-color: var(--color-danger); }
.badge-priority-medium { color: var(--color-warning); border-color: var(--color-warning); }
.badge-priority-low { color: var(--color-text-muted); }

/* ------------------------------------------------------------
   Conversa (chat)
   ------------------------------------------------------------ */
.chat-scroll {
  padding: 16px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  line-height: 1.4;
  font-size: 15px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--color-surface);
  border-bottom-left-radius: 4px;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-bottom-right-radius: 4px;
}

.chat-status {
  align-self: flex-start;
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 4px 4px;
}

.chat-input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-background);
  border-top: 1px solid var(--color-border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  z-index: 20;
}

.chat-input-bar textarea {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  resize: none;
  max-height: 120px;
  background: var(--color-surface);
}

.chat-quick-actions {
  display: flex;
  gap: 8px;
  padding: 0 20px 10px;
  overflow-x: auto;
}

.chat-quick-actions .btn {
  width: auto;
  white-space: nowrap;
}

/* ------------------------------------------------------------
   Estados vazios
   ------------------------------------------------------------ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-muted);
}

.empty-state svg {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  opacity: 0.5;
}

/* ------------------------------------------------------------
   Toast
   ------------------------------------------------------------ */
.toast-container {
  position: fixed;
  top: 16px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: var(--color-background);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  max-width: 90%;
  box-shadow: var(--shadow-card);
}

.toast.error {
  background: var(--color-danger);
  color: #fff;
}

.toast.success {
  background: var(--color-success);
  color: #fff;
}

/* ------------------------------------------------------------
   Modal
   ------------------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  background: var(--color-background);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
  }
  .modal-sheet {
    border-radius: var(--radius-lg);
    max-height: 80vh;
  }
}

/* ------------------------------------------------------------
   Tabs
   ------------------------------------------------------------ */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  overflow-x: auto;
}

.tabs button {
  flex: 1;
  white-space: nowrap;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text-muted);
  cursor: pointer;
}

.tabs button.active {
  background: var(--color-background);
  color: var(--color-text);
  box-shadow: var(--shadow-card);
}

/* ------------------------------------------------------------
   Planos (pricing cards)
   ------------------------------------------------------------ */
.plans-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

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

.plan-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plan-card.featured {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-card);
}

.plan-price {
  font-size: 28px;
  font-weight: 700;
}

.plan-features {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
}

.plan-features li {
  padding: 6px 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

/* ------------------------------------------------------------
   Tabelas administrativas
   ------------------------------------------------------------ */
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 640px;
}

table.admin-table th,
table.admin-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

table.admin-table th {
  color: var(--color-text-muted);
  font-weight: 600;
  background: var(--color-surface);
}

/* ------------------------------------------------------------
   Loading / spinner
   ------------------------------------------------------------ */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0,0,0,0.15);
  border-top-color: var(--color-text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.skeleton {
  background: linear-gradient(90deg, var(--color-surface) 25%, var(--color-border) 50%, var(--color-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ------------------------------------------------------------
   Utilidades
   ------------------------------------------------------------ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ------------------------------------------------------------
   Drawer (menu lateral)
   ------------------------------------------------------------ */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 60; display: flex; }
.drawer-panel {
  width: 84%; max-width: 320px; height: 100%;
  background: var(--color-background);
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto; transform: translateX(-100%); transition: transform 0.2s ease;
}
.drawer-backdrop.open .drawer-panel { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; margin-bottom: 12px; border-bottom: 1px solid var(--color-border); }
.drawer-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--color-primary); color: var(--color-primary-text); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.drawer-username { font-weight: 600; }
.drawer-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); padding: 16px 12px 6px; }
.drawer-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-sm); color: var(--color-text); font-weight: 500; }
.drawer-item svg { width: 20px; height: 20px; flex: none; color: var(--color-text-muted); }
.drawer-item:hover, .drawer-item:active { background: var(--color-surface); }
.drawer-item-highlight { background: var(--color-surface); margin-bottom: 8px; }

/* ------------------------------------------------------------
   Módulos de "Vida" (Finanças, Dieta, Hábitos, Diário, Ideias)
   ------------------------------------------------------------ */
.module-header { padding: 20px; border-bottom: 1px solid var(--color-border); }
.balance-display { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.quick-actions-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0; }
.quick-action-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: var(--radius-md); background: var(--color-surface); border: 1px solid var(--color-border); font-size: 12px; color: var(--color-text); cursor: pointer; }
.quick-action-btn svg { width: 20px; height: 20px; }
.scope-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.scope-tab-card { flex: none; min-width: 140px; padding: 14px; border-radius: var(--radius-md); border: 1px solid var(--color-border); cursor: pointer; }
.scope-tab-card.active { border-color: var(--color-accent); background: color-mix(in srgb, var(--color-accent) 8%, var(--color-background)); }
.transaction-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--color-border); cursor: pointer; }
.transaction-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--color-surface); display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.transaction-amount.income { color: var(--color-success); }
.transaction-amount.expense { color: var(--color-danger); }
.streak-ring { width: 90px; height: 90px; }
.habit-card { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: 10px; }
.habit-check-circle { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--color-border); display: flex; align-items: center; justify-content: center; flex: none; cursor: pointer; }
.habit-check-circle.checked { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.diary-entry-card { padding: 16px; border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: 12px; }
.idea-card { padding: 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: 10px; }
.macro-bar-track { height: 8px; border-radius: 4px; background: var(--color-surface); overflow: hidden; }
.macro-bar-fill { height: 100%; border-radius: 4px; }
.mood-btn { font-size: 22px; background: none; border: none; border-radius: 50%; width: 36px; height: 36px; opacity: 0.5; cursor: pointer; }
.mood-btn.selected { opacity: 1; background: var(--color-surface); }
.meal-card { padding: 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: 10px; }
