:root {
  --bg: #F3F1EC;
  --surface: #FFFFFF;
  --surface-2: #E9E6DF;
  --ink: #1D1C1A;
  --ink-2: #5C5850;
  --line: #DAD5CB;
  --accent: #F5B400;
  --accent-press: #E0A400;
  --accent-ink: #1D1C1A;
  --accent-soft: #FFF2C6;
  --mine: #FFE596;
  --mine-ink: #1D1C1A;
  --danger: #B8321C;
  --focus: #1D5FD1;
  --shadow: 0 1px 2px rgb(29 28 26 / .08), 0 8px 24px rgb(29 28 26 / .08);
  --radius: 14px;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131311;
    --surface: #1E1D1A;
    --surface-2: #2A2925;
    --ink: #F2F0EB;
    --ink-2: #A8A398;
    --line: #36342E;
    --accent: #FFC21A;
    --accent-press: #F0B000;
    --accent-soft: #3A3217;
    --mine: #4A3D10;
    --mine-ink: #FFF6DA;
    --danger: #FF7A63;
    --focus: #7FB0FF;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.icon { width: 22px; height: 22px; flex: none; }
.muted { color: var(--ink-2); margin: 0 0 12px; }

/* Marca */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font: 700 24px/1 var(--font-display);
  letter-spacing: .02em; text-transform: uppercase;
}
.brand-lg { font-size: 34px; }
.brand-mark {
  width: 1.1em; height: 1.1em; border-radius: 6px;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 6px, var(--ink) 6px 12px);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.brand-mark-xl { width: 72px; height: 72px; border-radius: 16px; opacity: .9; }

.screen { min-height: 100dvh; }
.screen-loading { display: grid; place-content: center; justify-items: center; gap: 12px; }

/* Firma "Powered by solvai." */
.credit { margin: 0; font-size: 14px; color: var(--ink-2); }
.credit .solvai {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: bottom;
  color: var(--ink); font-weight: 700; text-decoration: none;
}
.credit a.solvai:hover { text-decoration: underline; }
/* El logo toma el color del texto: blanco en modo oscuro, negro en claro. */
.solvai-logo {
  width: 1.2em; height: 1.2em; flex: none;
  background-color: currentColor;
  -webkit-mask: url(solvai-logo.png) center / contain no-repeat;
  mask: url(solvai-logo.png) center / contain no-repeat;
}
.credit-auth { margin-top: 28px; text-align: center; }
.credit-foot { margin-left: auto; align-self: center; white-space: nowrap; }
.credit-sheet { margin-top: 16px; text-align: center; font-size: 13px; }
.screen-loading .brand { animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px;
  border: 0; border-radius: 12px;
  font-weight: 600; font-size: 17px;
  transition: background-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-press); }
.btn-secondary { background: var(--surface-2); color: var(--ink); }
.btn-secondary:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--ink)); }
.btn-danger-ghost { background: transparent; color: var(--danger); padding: 0 8px; }
.btn-block { width: 100%; }
.btn-link {
  display: block; margin: 14px auto 0; padding: 8px;
  background: none; border: 0; color: var(--ink-2); text-decoration: underline;
}
.icon-btn {
  display: grid; place-items: center;
  width: 48px; height: 48px; flex: none;
  background: none; border: 0; border-radius: 12px;
}
.icon-btn:hover { background: var(--surface-2); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.pill-warn { background: var(--accent-soft); color: var(--ink); }
.pill-admin { background: #1D1C1A; color: #FFC21A; box-shadow: inset 0 0 0 1px #FFC21A; }
.pill-danger { margin-top: 4px; background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 15px; }
.head-actions { display: flex; align-items: center; gap: 4px; }

/* Formularios */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; font-weight: 600; font-size: 15px; }
.field em { font-style: normal; font-weight: 400; color: var(--ink-2); }
.field input, .field select {
  width: 100%; min-height: 52px; padding: 0 14px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 12px;
}
.field input:focus, .field select:focus { border-color: var(--ink); outline: none; }
.form-error { margin: 0 0 14px; color: var(--danger); font-weight: 600; }
.notice {
  margin: 0 0 18px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); font-weight: 500;
}

/* Acceso */
.screen-auth {
  display: grid; place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card { width: 100%; max-width: 420px; }
.auth-tagline { margin: 10px 0 24px; color: var(--ink-2); font-size: 19px; }
.btn-google { background: var(--surface); color: var(--ink); border: 2px solid var(--line); }
.btn-google:hover { background: var(--surface-2); }
.google-error { margin: 10px 0 0; }
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0; color: var(--ink-2); font-size: 15px;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin-bottom: 20px;
  background: var(--surface-2); border-radius: 14px;
}
.segmented button {
  min-height: 46px; border: 0; border-radius: 10px;
  background: transparent; font-weight: 600; color: var(--ink-2);
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* Estructura principal */
.screen-main { display: grid; grid-template-columns: minmax(0, 1fr); height: 100dvh; min-height: 0; }
@media (min-width: 800px) {
  .screen-main { grid-template-columns: 360px minmax(0, 1fr); }
  .back-btn { display: none !important; }
}
@media (max-width: 799px) {
  .screen-main[data-view="list"] .chat { display: none; }
  .screen-main[data-view="chat"] .sidebar { display: none; }
}

/* Lista de obras */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 12px 18px;
}
.avatar-btn { padding: 0; border: 0; background: none; border-radius: 50%; }
.sidebar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 16px 12px; }
.sidebar-actions .btn { padding: 0 10px; font-size: 16px; }
.list-title {
  margin: 8px 18px 6px;
  font: 600 13px/1 var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2);
}
.group-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.group-list:empty { flex: 0; }
.group-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px; min-height: 72px;
  background: none; border: 0; border-radius: 12px; text-align: left;
}
.group-item:hover { background: var(--bg); }
.group-item[aria-current="true"] { background: var(--accent-soft); }
.group-main { flex: 1; min-width: 0; }
.group-row { display: flex; align-items: baseline; gap: 8px; }
.group-name { flex: 1; font-weight: 700; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-time { font-size: 13px; color: var(--ink-2); flex: none; }
.group-last {
  display: block; color: var(--ink-2); font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.group-item.unread .group-last { color: var(--ink); font-weight: 600; }
.unread-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--ink); flex: none; }
.groups-empty { flex: 1; padding: 8px 20px; color: var(--ink-2); }
.groups-empty p { margin: 0 0 8px; }
.groups-empty strong { color: var(--ink); }
.sidebar-foot {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.avatar {
  display: grid; place-items: center; flex: none;
  width: 48px; height: 48px; border-radius: 50%;
  font-weight: 700; font-size: 17px; color: #fff;
}
.avatar-sm { width: 36px; height: 36px; font-size: 14px; }
.avatar-square { border-radius: 12px; font-family: var(--font-display); font-size: 20px; }

/* Chat */
.chat { display: flex; min-height: 0; min-width: 0; }
.chat-empty {
  flex: 1; display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--ink-2);
}
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.chat-title {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start;
  padding: 6px 8px; border: 0; background: none; border-radius: 10px; text-align: left;
}
.chat-title:hover { background: var(--bg); }
.chat-name { font: 700 22px/1.1 var(--font-display); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 14px; color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.messages-empty { margin: auto; max-width: 320px; text-align: center; color: var(--ink-2); }
.day-sep {
  align-self: center; margin: 14px 0 8px; padding: 4px 12px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2); font-size: 13px; font-weight: 600;
}
.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: min(78%, 620px); }
.msg-row.mine { align-self: flex-end; }
.msg-row.first { margin-top: 10px; }
.msg-row .avatar-slot { width: 36px; flex: none; }
.bubble {
  padding: 8px 12px 6px; border-radius: 16px;
  background: var(--surface); box-shadow: 0 1px 1px rgb(0 0 0 / .06);
  min-width: 0;
}
.mine .bubble { background: var(--mine); color: var(--mine-ink); }
.msg-row.first:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.msg-row.first.mine .bubble { border-bottom-right-radius: 6px; }
.msg-author { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin-bottom: 2px; }
.msg-name { font-weight: 700; font-size: 15px; }
.msg-trade { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 3px;
  margin-top: 2px; font-size: 12px; color: var(--ink-2);
}
.mine .msg-meta { color: color-mix(in srgb, var(--mine-ink) 65%, transparent); }
.msg-meta .icon { width: 14px; height: 14px; }
.msg-delete {
  margin-left: 6px; padding: 2px 4px; border: 0; background: none;
  color: var(--danger); font-size: 12px; font-weight: 600; text-decoration: underline;
}

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 150px; min-height: 50px;
  padding: 12px 14px; line-height: 1.4;
  background: var(--bg); border: 2px solid var(--line); border-radius: 14px;
}
.composer textarea:focus { border-color: var(--ink); outline: none; }
.send-btn {
  display: grid; place-items: center; flex: none;
  width: 50px; height: 50px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
}
.send-btn:hover { background: var(--accent-press); }

/* Hojas (diálogos) */
.sheet {
  width: min(460px, calc(100% - 32px)); max-height: 90dvh;
  padding: 22px; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet h2 { margin: 0 0 16px; font: 700 26px/1.1 var(--font-display); }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.sheet-actions .btn-primary { flex: 1; }
@media (max-width: 599px) {
  .sheet {
    width: 100%; max-width: none; margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
}
.code-input { font-family: var(--font-display) !important; font-size: 26px !important; letter-spacing: .12em; text-transform: uppercase; }
.join-preview { margin: -4px 0 14px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); }

.info-address { display: flex; align-items: center; gap: 6px; margin: -8px 0 16px; color: var(--ink-2); }
.info-address .icon { width: 18px; height: 18px; }
.invite-box {
  padding: 16px; margin-bottom: 18px; border-radius: 16px;
  background: var(--accent-soft); border: 2px dashed color-mix(in srgb, var(--accent) 70%, var(--ink));
}
.invite-label { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.invite-code { display: block; margin: 4px 0 12px; font: 700 40px/1 var(--font-display); letter-spacing: .1em; }
.invite-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.invite-actions .btn { padding: 0 10px; font-size: 16px; }
.sheet .list-title { margin: 0 0 6px; }
.member-list { list-style: none; margin: 0; padding: 0; max-height: 34dvh; overflow-y: auto; }
.member-list li { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.member-list .member-name { font-weight: 600; }
.member-list .member-sub { display: block; font-size: 14px; color: var(--ink-2); }
.member-list li > span:not(.avatar) { flex: 1; min-width: 0; }
#users-list { max-height: 55dvh; }
.admin-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}

/* Aviso flotante */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 10;
  transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: var(--shadow);
}

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