/* Cauce - tokens de los tres temas y UI minima de la fase 1. */

:root {
  color-scheme: light;

  --bg: #F6F3EE;
  --surface: #FBF9F5;
  --raised: #FEFCF9;
  --border: #DED8CD;
  --text1: #24211D;
  --text2: #5C564D;
  --accent: #35625C;
  --on-accent: #F7F5F0;
  --bubble-own: #E3EDE7;
  --bubble-other: #F1EDE6;
  --danger: #9B3F38;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size: 15px;
  --line-height: 1.45;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #1A1917;
  --surface: #21201D;
  --raised: #292722;
  --border: #3A362F;
  --text1: #E8E4DC;
  --text2: #ADA79B;
  --accent: #86B8A6;
  --on-accent: #11201B;
  --bubble-own: #2C3F38;
  --bubble-other: #262420;
  --danger: #D98B82;
}

[data-theme="neutral"] {
  color-scheme: light;

  --bg: #A8A6A0;
  --surface: #B2B0AA;
  --raised: #BCBAB3;
  --border: #8E8C86;
  --text1: #26241F;
  --text2: #3C3A34;
  --accent: #24403A;
  --on-accent: #F2F0EA;
  --bubble-own: #98A79F;
  --bubble-other: #C1BFB8;
  --danger: #642420;
}

/* --- Base ---------------------------------------------------------------- */

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

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text1);
  font-family: var(--font);
  font-size: var(--font-size);
  line-height: var(--line-height);
  display: flex;
  flex-direction: column;
}

h1,
h2 {
  margin: 0 0 0.4rem;
  line-height: 1.2;
  font-weight: 600;
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1.1rem;
}

p {
  margin: 0 0 0.85rem;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.55rem 0.9rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 10;
}

.skip-link:focus {
  left: 0;
}

/* --- Estructura ---------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text1);
}

.who {
  color: var(--text2);
  font-size: 0.92rem;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  flex: 1;
}

.offline {
  margin: 0;
  padding: 0.6rem 1rem;
  background: var(--danger);
  color: var(--on-accent);
  font-size: 0.92rem;
}

.loading {
  color: var(--text2);
}

/* --- Tarjetas y formularios --------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
}

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

.field {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
}

input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  min-height: 40px;
  padding: 0.5rem 0.7rem;
  font: inherit;
  color: var(--text1);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

input::placeholder {
  color: var(--text2);
}

input.is-invalid {
  border-color: var(--danger);
}

.hint {
  margin: 0.35rem 0 0;
  color: var(--text2);
  font-size: 0.88rem;
}

.error {
  margin: 0 0 0.9rem;
  color: var(--danger);
  font-weight: 500;
}

/* --- Botones ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--on-accent);
}

.btn-secondary {
  background: transparent;
  color: var(--text1);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  padding-inline: 0.6rem;
}

/* --- Lista de conversaciones -------------------------------------------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.section-head h1 {
  margin: 0;
}

.conversation-list {
  list-style: none;
  margin: 0 0 0.9rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.conversation-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.8rem 0.9rem;
}

.conversation-title {
  font-weight: 500;
}

.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  color: var(--text2);
  text-align: center;
}

/* --- Ajustes: tema ------------------------------------------------------- */

.section-title {
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.theme-fieldset {
  border: 0;
  margin: 0 0 1.4rem;
  padding: 0;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.theme-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.theme-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.theme-card:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-card:has(input:checked) {
  border-color: var(--accent);
  border-width: 2px;
  padding: calc(0.7rem - 1px);
}

.theme-name {
  font-size: 0.92rem;
  color: var(--text1);
}

.theme-swatch {
  display: block;
  height: 2.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--swatch-bg, var(--bg));
}

.theme-card[data-theme-card="light"] {
  --swatch-bg: #F6F3EE;
  --swatch-dot: #35625C;
}

.theme-card[data-theme-card="dark"] {
  --swatch-bg: #1A1917;
  --swatch-dot: #86B8A6;
}

.theme-card[data-theme-card="neutral"] {
  --swatch-bg: #A8A6A0;
  --swatch-dot: #24403A;
}

.theme-swatch::after {
  content: "";
  display: block;
  width: 40%;
  height: 0.55rem;
  margin: 0.55rem auto 0;
  border-radius: 999px;
  background: var(--swatch-dot, var(--accent));
}

.session-actions {
  margin-top: 1.5rem;
}

/* --- Adaptacion a pantallas estrechas ----------------------------------- */

@media (max-width: 26rem) {
  .theme-grid {
    grid-template-columns: 1fr;
  }

  .theme-card {
    flex-direction: row;
    align-items: center;
  }

  .theme-swatch {
    width: 3.2rem;
    flex: 0 0 auto;
  }

  .theme-swatch::after {
    margin-top: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
