@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');
@import './variables.css';

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 2px; }

/* Seleção */
::selection { background: var(--accent-dim); color: var(--text-primary); }

/* ───── LAYOUT PRINCIPAL ───── */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar desktop */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--space-lg) 0;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 0 var(--space-lg) var(--space-lg);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-md);
}

.sidebar-logo h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.sidebar-logo span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--space-sm);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px var(--space-md);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 450;
  transition: all var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-item .icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* Conteúdo principal */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
}

.page-header {
  margin-bottom: var(--space-xl);
}

.page-header h2 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.page-header p {
  color: var(--text-secondary);
  margin-top: var(--space-xs);
  font-size: 0.875rem;
}

/* ───── CARDS ───── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition);
}

.card:hover {
  border-color: var(--border-accent);
  background: var(--bg-card-hover);
}

.card-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.card-value {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.2;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

.card-accent {
  border-color: var(--border-accent);
  background: var(--accent-dim);
}

.card-accent .card-value {
  color: var(--accent);
}

/* ───── CHAT ───── */

.chat-panel {
  width: var(--chat-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.chat-header h3 {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.chat-status {
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
  margin-left: auto;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 90%;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.5;
}

.message.user .message-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.message.user .message-time { text-align: right; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.chat-input-area {
  padding: var(--space-md);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color var(--transition);
}

.chat-input:focus {
  border-color: var(--accent);
}

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

.chat-send-btn {
  width: 42px;
  height: 42px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
  font-size: 1rem;
}

.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn:disabled { background: var(--text-muted); cursor: not-allowed; }

/* ───── TELA DE LOGIN ───── */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-lg);
}

.login-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-logo {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.login-logo span {
  color: var(--accent);
}

.login-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xl);
}

.login-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  outline: none;
  text-align: center;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-md);
  transition: border-color var(--transition);
}

.login-input:focus {
  border-color: var(--accent);
}

.login-btn {
  width: 100%;
  padding: var(--space-md);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}

.login-btn:hover { background: var(--accent-hover); }

.login-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin-top: var(--space-md);
  min-height: 20px;
}

/* ───── MÓDULOS — FASE 3 ───── */

.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: var(--space-xl) 0 var(--space-sm);
}

.section-label:first-of-type {
  margin-top: 0;
}

.list-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: var(--space-xl);
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  transition: background var(--transition);
}

.list-row:hover {
  background: var(--bg-card-hover);
}

.list-row-main {
  flex: 1;
  min-width: 0;
}

.list-row-title {
  color: var(--text-primary);
  font-weight: 450;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-row-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.list-row-value {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.list-row-value.receita { color: var(--success); }
.list-row-value.despesa { color: var(--danger); }

/* Barra de progresso */
.progress-bar-wrap {
  background: var(--bg-secondary);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-top: var(--space-sm);
}

.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.warning { background: var(--warning); }
.progress-bar-fill.danger  { background: var(--danger); }

/* Badge de status */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 500;
  flex-shrink: 0;
}

.status-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-ativo    { background: rgba(74,222,128,0.1); color: var(--success); }
.status-planejado { background: rgba(251,191,36,0.1); color: var(--warning); }
.status-concluido { background: rgba(148,163,184,0.1); color: var(--text-muted); }
.status-andamento { background: var(--accent-dim); color: var(--accent); }
.status-pausado  { background: rgba(248,113,113,0.1); color: var(--danger); }

/* ───── UTILITÁRIOS ───── */

.hidden { display: none !important; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
}

.tag-success { background: rgba(74, 222, 128, 0.1); color: var(--success); }
.tag-warning { background: rgba(251, 191, 36, 0.1); color: var(--warning); }
.tag-danger  { background: rgba(248, 113, 113, 0.1); color: var(--danger); }
.tag-accent  { background: var(--accent-dim); color: var(--accent); }

/* ───── MOBILE (PWA no iPhone) ───── */

@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    height: var(--nav-height);
  }

  .sidebar-logo { display: none; }

  .sidebar-nav {
    flex-direction: row;
    padding: 0 var(--space-sm);
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
  }

  .sidebar-nav::-webkit-scrollbar { display: none; }

  .nav-item {
    flex-direction: column;
    gap: 2px;
    padding: 8px var(--space-sm);
    font-size: 0.65rem;
    white-space: nowrap;
    min-width: 56px;
    justify-content: center;
    align-items: center;
  }

  .nav-item .label { display: block; }

  .main-content {
    padding: var(--space-lg) var(--space-md);
  }

  .chat-panel {
    width: 100%;
    height: calc(100vh - var(--nav-height));
    border-left: none;
  }

  /* No mobile, chat abre em fullscreen */
  .page-main {
    flex: 1;
    overflow-y: auto;
  }
}

/* Safe area para iPhone com notch/Dynamic Island */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-input-area {
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }

  .sidebar {
    padding-top: env(safe-area-inset-top);
  }
}
