/* Nutri Agente — estilos compartidos (panel + app del paciente) */
/* Paleta Ana Paula Recéndez (derivada del logo: carbón + hoja).
   Todos los pares texto/fondo cumplen contraste AA (≥ 4.5:1). */
:root {
  --bg: #f8f5ef;          /* crema cálido */
  --surface: #ffffff;
  --surface-2: #f1ece3;
  --border: #e5ded2;
  --text: #262626;        /* carbón del logo */
  --muted: #6b675f;
  --brand: #46705a;       /* verde hoja */
  --brand-ink: #ffffff;
  --brand-strong: #3b6150;
  --brand-soft: #e3ede5;
  --accent: #965630;      /* terracota (texto) */
  --accent-soft: #f7e6da; /* durazno */
  --danger: #a63d2c;
  --danger-soft: #f8e2dd;
  --info-soft: #eaf0ea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(38, 38, 38, .05), 0 6px 20px rgba(38, 38, 38, .06);
  --font: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171917;
    --surface: #202420;
    --surface-2: #282d28;
    --border: #353b35;
    --text: #ece8e1;
    --muted: #a39e94;
    --brand: #8dbb9c;
    --brand-ink: #111a14;
    --brand-strong: #a9d1b5;
    --brand-soft: #283a2f;
    --accent: #e7b08a;
    --accent-soft: #3a2c22;
    --danger: #ee9a8a;
    --danger-soft: #3b2420;
    --info-soft: #243029;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  padding: .55em 1em; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: .35em .7em; font-size: .85rem; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: .3em .5em; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Formularios ---------- */
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .5em .65em;
}
textarea { resize: vertical; min-height: 2.6em; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
input[type="checkbox"] { width: auto; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25em; }
.field { margin-bottom: .85em; min-width: 0; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1em; }
.grid-2 .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1em 1.1em .3em; margin: 0 0 1em; background: var(--surface); }
legend { font-weight: 700; padding: 0 .4em; }
.check-row { display: flex; gap: .6em; align-items: flex-start; }
.check-row label { font-weight: 500; margin: 0; }

/* ---------- Chips ---------- */
.chip { display: inline-block; padding: .1em .6em; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip-ok { background: var(--brand-soft); color: var(--brand-strong); }
.chip-warn { background: var(--accent-soft); color: var(--accent); }
.chip-off { background: var(--surface-2); color: var(--muted); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Pantallas de acceso ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card p { color: var(--muted); }
.login-card .btn { width: 100%; margin-top: .6em; }
.login-msg { margin-top: .8em; font-size: .9rem; }
.login-msg[data-kind="error"] { color: var(--danger); }
.brand { display: flex; align-items: center; gap: .65em; }
.brand-mark { display: block; flex: none; }
.brand-mark img { display: block; height: 34px; width: auto; }
.brand-text h1 { font-size: 1.05rem; font-weight: 700; }
.login-logo { display: block; margin: 0 auto 1.4em; }
.login-logo img { display: block; width: 220px; max-width: 100%; height: auto; margin: 0 auto; }
.login-card h2 { text-align: center; font-size: 1.15rem; margin-bottom: .2em; }
.login-card > p { text-align: center; }
.brand-text p { margin: 0; font-size: .8rem; color: var(--muted); }

/* ---------- Barra superior ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1em; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .spacer { flex: 1; }
.user-chip { font-size: .85rem; color: var(--muted); }

/* ---------- Panel: diseño de dos columnas ---------- */
.panel-layout { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.sidebar-tools { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.pac-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.pac-item { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.pac-item:hover { background: var(--surface-2); }
.pac-item[aria-current="true"] { background: var(--brand-soft); }
.pac-item .nombre { font-weight: 600; display: flex; justify-content: space-between; gap: .5em; }
.pac-item .meta { font-size: .8rem; color: var(--muted); }
.list-empty { padding: 20px 12px; color: var(--muted); font-size: .9rem; text-align: center; }

.detail { overflow-y: auto; padding: 20px 24px 60px; min-width: 0; }
.detail-head { display: flex; align-items: flex-start; gap: 1em; flex-wrap: wrap; margin-bottom: 14px; }
.detail-head .spacer { flex: 1; }
.empty-detail { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

.save-bar { position: sticky; bottom: 0; display: flex; gap: .6em; justify-content: flex-end; align-items: center; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.save-bar .spacer { flex: 1; }

.access-box { display: flex; align-items: center; gap: .8em; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius); background: var(--info-soft); border: 1px solid var(--border); margin-bottom: 1em; font-size: .9rem; }
.access-box .spacer { flex: 1; }

/* ---------- Plan ---------- */
.eq-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 1em; }
.eq-table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.eq-table th, .eq-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: center; }
.eq-table th:first-child, .eq-table td:first-child { text-align: left; white-space: nowrap; position: sticky; left: 0; background: var(--surface); }
.eq-table thead th { background: var(--surface-2); font-weight: 600; }
.eq-table thead th:first-child { background: var(--surface-2); }
.eq-table input { width: 4.2em; padding: .25em .3em; text-align: center; }
.eq-table .total { font-weight: 700; color: var(--muted); }

.menu-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px 14px; margin-bottom: 12px; }
.menu-card-head { display: flex; gap: .6em; align-items: center; margin-bottom: 10px; }
.menu-card-head input { font-weight: 700; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1em; }

.versions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }

/* ---------- Tablas simples ---------- */
.table-wrap { overflow-x: auto; }
.simple-table { width: 100%; border-collapse: collapse; font-size: .9rem; background: var(--surface); border-radius: var(--radius); }
.simple-table th, .simple-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.simple-table th { font-size: .8rem; color: var(--muted); font-weight: 600; }

.note { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 10px 14px; margin-bottom: 8px; }
.note .meta { font-size: .78rem; color: var(--muted); margin-bottom: .2em; }
.note p { margin: 0; white-space: pre-wrap; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
.modal { position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal-head, .modal-foot { display: flex; align-items: center; gap: .6em; padding: 14px 18px; }
.modal-head { border-bottom: 1px solid var(--border); justify-content: space-between; }
.modal-foot { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-body { padding: 16px 18px; }

/* ---------- Toast ---------- */
.toast { position: fixed; z-index: 50; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* ---------- App del paciente ---------- */
.pac-app { max-width: 720px; margin: 0 auto; padding: 16px 16px 60px; }
.hello { margin: 8px 0 16px; }
.hello h2 { font-size: 1.5rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h3 { margin-bottom: .6em; }
.card-soon { background: var(--brand-soft); border-color: transparent; box-shadow: none; }
.card-soon h3 { color: var(--brand-strong); }
.tiempo { padding: 8px 0; border-bottom: 1px solid var(--border); }
.tiempo:last-child { border-bottom: 0; }
.tiempo strong { display: block; font-size: .9rem; }
.tiempo span { color: var(--muted); font-size: .9rem; white-space: pre-wrap; }
.menu-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.menu-tabs .btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.pre { white-space: pre-wrap; margin: 0; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  .panel-layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; max-height: none; }
  .panel-layout[data-mobile="detail"] .sidebar { display: none; }
  .panel-layout[data-mobile="list"] .detail { display: none; }
  .detail { padding: 16px 16px 60px; overflow: visible; }
  .grid-2, .menu-grid { grid-template-columns: 1fr; }
  .topbar .user-chip { display: none; }
}
.only-mobile { display: none; }
@media (max-width: 760px) { .only-mobile { display: inline-flex; } }
