/* style.css - NutriAgent Jornada Muda */

/* Importar DM Sans */
@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,700;1,9..40,400&display=swap');

:root {
  /* Cores - Jornada Muda Customizadas */
  --bg-page: #F1EDE4;
  /* Bege claro da paleta */
  --bg-card: #ffffff;
  --bg-input: #ffffff;

  --bg-sidebar: #6b8d5a;
  /* Verde Sálvia (mesmo do botão primário) */
  --bg-sidebar-hover: #567246;
  --bg-sidebar-active: #4A623B;

  /* Bordas */
  --border-light: #e0ddd8;
  --border-input-focus: #7c9c69;

  /* Texto */
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --text-placeholder: #bbbbbb;
  --text-sidebar: #cccccc;
  --text-sidebar-muted: #888888;

  /* Botões - Verde Sálvia da paleta */
  --btn-primary-bg: #6b8d5a;
  /* Tom médio do verde folha/sálvia */
  --btn-primary-bg-hover: #567246;
  --btn-primary-text: #ffffff;
  --btn-primary-disabled: #b5c7ad;

  --btn-secondary-bg: transparent;
  --btn-secondary-border: #a9744e;
  /* Marrom terroso da paleta */
  --btn-secondary-text: #a9744e;
  --btn-secondary-hover-bg: rgba(169, 116, 78, 0.05);

  /* Alert/Warning */
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  /* Success */
  --success-bg: #e8f5e9;
  --success-text: #2e7d32;

  /* Scenario tags (mantido do spec mas levemente ajustado para harmonia) */
  --tag-emocional-color: #f472b6;
  --tag-emocional-bg: #4a1942;
  --tag-social-color: #fbbf24;
  --tag-social-bg: #422006;
  --tag-rotina-color: #34d399;
  --tag-rotina-bg: #064e3b;
  --tag-clinico-color: #60a5fa;
  --tag-clinico-bg: #1e3a5f;
  --tag-geral-color: #a78bfa;
  --tag-geral-bg: #2e1065;

  /* Tipografia */
  --text-xs: 10px;
  --text-sm: 12px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 18px;
  --text-xl: 22px;

  /* Bordas e sombras */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-drawer: 4px 0 16px rgba(0, 0, 0, 0.15);

  /* Espaçamento */
  --sidebar-width: 260px;
  --content-max-width: 720px;
  --content-padding: 20px 16px;
  --card-padding: 20px;
  --header-height: 60px;
}

/* Reset Básico */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'DM Sans', 'Helvetica Neue', sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Utilities */
.hidden {
  display: none !important;
}

#app-view:not(.hidden) .sidebar {
  /* This ensures sidebar interacts properly when app-view is visible */
}

/* --- TELA: LOGIN --- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-container {
  background: var(--bg-card);
  padding: 32px 24px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 360px;
}

.login-logo {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.logo-img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: contain;
}

.logo-img-sidebar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
}

.logo-text {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-icon-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 4px;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.input-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-family: inherit;
  font-size: var(--text-base);
  transition: border-color 0.2s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--border-input-focus);
}

.btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--btn-primary-bg-hover);
}

.btn-primary:disabled {
  background: var(--btn-primary-disabled);
  cursor: not-allowed;
  opacity: 0.8;
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: 1px solid var(--btn-secondary-border);
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover-bg);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--text-sm);
  width: auto;
}

.error-msg {
  color: var(--warning-text);
  font-size: var(--text-sm);
  margin-top: 12px;
  text-align: center;
}

/* --- TELA: APP --- */
#app-view {
  min-height: 100vh;
  display: flex;
  position: relative;
}

/* SIDEBAR */
.sidebar {
  position: fixed;
  top: 0;
  left: -100%;
  /* Hidden by default on mobile */
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  /* Ensure it stays above everything */
  box-shadow: var(--shadow-drawer);
}

.sidebar.open {
  transform: translateX(100%);
  /* Moves it exactly 100% of its width from -100% to 0 */
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-header {
  padding: 24px 20px;
  font-size: var(--text-lg);
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.desktop-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-sidebar);
  cursor: pointer;
  display: none;
  /* Only show on desktop */
  font-size: 20px;
  padding: 4px;
  border-radius: 4px;
}

.desktop-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-menu {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-menu ul {
  list-style: none;
}

.sidebar-menu li {
  margin-bottom: 4px;
}

.sidebar-menu button {
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  font-family: inherit;
  font-size: var(--text-base);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
  overflow: hidden;
  white-space: nowrap;
}

.agent-icon {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-menu button:hover {
  background: var(--bg-sidebar-hover);
}

.sidebar-menu button.active {
  background: var(--bg-sidebar-active);
  color: #fff;
  font-weight: 500;
}

.sidebar-menu button:disabled {
  color: var(--text-sidebar-muted);
  cursor: not-allowed;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-btn {
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  font-family: inherit;
  font-size: var(--text-base);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
}

/* HEADER */
.app-header {
  height: var(--header-height);
  background: var(--bg-page);
  /* Harmonioso com bg ou bg-card */
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-primary);
  cursor: pointer;
  margin-right: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.header-titles h1 {
  font-size: var(--text-md);
  font-weight: 700;
}

.header-titles p {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* CONTENT WRAPPER */
.content-wrapper {
  flex: 1;
  padding: var(--content-padding);
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
}

.agent-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--card-padding);
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}

.input-label {
  display: block;
  font-weight: 500;
  margin-bottom: 12px;
  font-size: var(--text-md);
}

.input-wrapper {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  padding: 12px;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

.input-wrapper:focus-within {
  border-color: var(--border-input-focus);
}

.auto-expand {
  width: 100%;
  min-height: 80px;
  max-height: 200px;
  resize: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: var(--text-md);
  color: var(--text-primary);
  outline: none;
}

.auto-expand::placeholder {
  color: var(--text-placeholder);
}

.actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  /* Reduzido de 16 pra acomodar área da resposta melhor */
}

.hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
  display: none;
  /* Hidden on mobile */
}

/* RESPONSE AREA */
.response-area {
  margin-top: 24px;
  border-top: 1px solid var(--border-light);
  padding-top: 24px;
}

/* Loading */
.loading-state {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
  font-size: var(--text-md);
  animation: fadeIn 0.3s ease;
}

.spinner {
  display: inline-block;
  font-size: 20px;
  animation: spin 1s linear infinite;
  color: var(--btn-primary-bg);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Output */
.output-state {
  animation: fadeIn 0.3s ease;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.output-title {
  font-weight: 500;
  font-size: var(--text-md);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag-emocional {
  background: var(--tag-emocional-bg);
  color: var(--tag-emocional-color);
}

.tag-social {
  background: var(--tag-social-bg);
  color: var(--tag-social-color);
}

.tag-rotina {
  background: var(--tag-rotina-bg);
  color: var(--tag-rotina-color);
}

.tag-clinico {
  background: var(--tag-clinico-bg);
  color: var(--tag-clinico-color);
}

.tag-geral {
  background: var(--tag-geral-bg);
  color: var(--tag-geral-color);
}

.output-content {
  background: var(--bg-page);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.draft-text {
  font-size: var(--text-md);
  white-space: pre-wrap;
  /* preserva quebras de linha */
  line-height: 1.6;
}

.warning-banner {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.output-actions {
  display: flex;
  justify-content: flex-start;
}

/* HISTORY */
.history-container {
  margin-top: 32px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 0 4px;
}

.history-header h2 {
  font-size: var(--text-md);
  color: var(--text-secondary);
  font-weight: 500;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
  border-color: var(--border-input-focus);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item-header .time {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.btn-archive {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  border-radius: 4px;
}

.history-item:hover .btn-archive {
  opacity: 1;
}

.btn-archive:hover {
  color: #e05555;
}

.history-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

/* DESKTOP MEDIA QUERY */
@media (min-width: 768px) {
  .sidebar {
    left: 0;
    /* Align perfectly to the left */
    transform: none;
    /* Always visible on desktop */
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar-overlay {
    display: none;
  }

  .desktop-toggle-btn {
    display: flex;
  }

  .main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Collapsed State Styles */
  .sidebar.collapsed {
    width: 68px;
    /* Width just for icons */
  }

  .sidebar.collapsed .logo-text,
  .sidebar.collapsed .agent-name,
  .sidebar.collapsed .btn-text {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    /* Hide from flow but keep DOM */
  }

  .sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 24px 0;
  }

  .sidebar.collapsed .sidebar-menu button,
  .sidebar.collapsed .sidebar-btn {
    justify-content: center;
    padding: 12px 0;
  }

  .sidebar.collapsed .sidebar-footer {
    display: flex;
    justify-content: center;
  }

  .main-content.expanded {
    margin-left: 68px;
    width: calc(100% - 68px);
  }

  .menu-btn {
    display: none;
    /* Hide hamburger */
  }

  .hint {
    display: inline;
  }

  /* Deixar o botão alinhar a direita caso deseje, 
     ou manter largura inteira. Como tá no Spec "Ctrl+Enter na esquerda e Botão na direita" */
  .btn-primary {
    width: auto;
    min-width: 160px;
  }

  /* Para tela de login não queremos a sidebar, 
     então app-view esconde sidebar-overlay, etc. */
}