/* ============================================================
   app.css — MSDS Generator Rochem/Uniclean
   Paleta: grises, sobrio, industrial/profesional
   ============================================================ */

/* ── Variables ── */
:root {
  --c-bg:        #f4f4f2;
  --c-surface:   #ffffff;
  --c-border:    #d8d8d4;
  --c-border-lt: #e8e8e4;
  --c-text:      #1a1a18;
  --c-text-muted:#666660;
  --c-accent:    #1a1a18;
  --c-accent-lt: #3a3a36;
  --c-danger:    #c0392b;
  --c-warn:      #8a6000;
  --c-success:   #1a6640;
  --c-info:      #1a4066;
  --radius-sm:   4px;
  --radius:      6px;
  --radius-lg:   8px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 3px 8px rgba(0,0,0,.10);
  --font:        'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-mono:   'SF Mono', Consolas, monospace;
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex; flex-direction: column;
}
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.container      { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }
.container--wide{ max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.main { flex: 1; padding: 2rem 0 4rem; }

/* ── Header ── */
.site-header {
  background: var(--c-accent);
  border-bottom: 2px solid #000;
  padding: .75rem 0;
  position: sticky; top: 0; z-index: 100;
}
.site-header__inner {
  max-width: 1200px; margin: 0 auto; padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
}
.site-header__brand { display: flex; align-items: center; gap: .75rem; }
.site-header__logo  { height: 28px; filter: brightness(0) invert(1); }
.site-header__sep   { color: #555; font-size: .9rem; }
.site-header__title { color: #fff; font-size: .9rem; font-weight: 500; letter-spacing: .02em; }
.site-header__nav   { display: flex; gap: .5rem; }
.nav-link           { color: #aaa; font-size: .85rem; padding: .3rem .6rem; border-radius: var(--radius-sm); transition: color .15s; }
.nav-link:hover, .nav-link--active { color: #fff; text-decoration: none; }

/* ── Footer ── */
.site-footer {
  background: var(--c-accent);
  border-top: 1px solid #333;
  padding: .75rem 0;
  margin-top: auto;
}
.site-footer .container {
  display: flex; justify-content: space-between;
  font-size: .78rem; color: #888;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem 1rem; border-radius: var(--radius-sm);
  font-size: .84rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn--primary   { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.btn--primary:hover { background: var(--c-accent-lt); text-decoration: none; }
.btn--secondary { background: #fff; color: var(--c-text); border-color: var(--c-border); }
.btn--secondary:hover { background: var(--c-bg); text-decoration: none; }
.btn--ghost     { background: transparent; color: var(--c-text-muted); border-color: transparent; }
.btn--ghost:hover { background: var(--c-bg); color: var(--c-text); text-decoration: none; }
.btn--danger    { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn--sm  { padding: .3rem .7rem; font-size: .78rem; }
.btn--lg  { padding: .6rem 1.4rem; font-size: .92rem; }

/* ── Alerts ── */
.alert {
  padding: .8rem 1rem; border-radius: var(--radius);
  margin-bottom: 1.25rem; font-size: .85rem;
  border-left: 3px solid transparent;
}
.alert--success { background: #f0faf4; border-color: var(--c-success); color: var(--c-success); }
.alert--error   { background: #fdf0f0; border-color: var(--c-danger);  color: var(--c-danger);  }
.alert--info    { background: #f0f5fa; border-color: var(--c-info);    color: var(--c-info);    }
.alert ul { padding-left: 1.2rem; margin-top: .4rem; }

/* ── Page top ── */
.page-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-top__right { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.page-title    { font-size: 1.35rem; font-weight: 600; }
.page-subtitle { font-size: .83rem; color: var(--c-text-muted); margin-top: .2rem; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: .5rem; margin-bottom: 1.25rem; flex-wrap: wrap; align-items: center; }
.filter-bar__search { flex: 1; min-width: 200px; }
.filter-bar__select { min-width: 160px; }

/* ── Table ── */
.table-wrap  { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--c-border); }
.data-table  { width: 100%; border-collapse: collapse; background: var(--c-surface); font-size: .84rem; }
.data-table th {
  background: #f0f0ee; border-bottom: 1.5px solid var(--c-border);
  padding: .65rem .9rem; text-align: left; font-size: .78rem;
  font-weight: 600; color: var(--c-text-muted); white-space: nowrap;
}
.data-table td { padding: .65rem .9rem; border-bottom: 1px solid var(--c-border-lt); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafaf8; }
.tr--active td { background: #f8f8f0; }
.td-name a { font-weight: 500; }
.ta-right { text-align: right !important; }
.action-group { display: flex; gap: .4rem; justify-content: flex-end; }
.code-cell { font-family: var(--font-mono); font-size: .8rem; background: var(--c-bg); padding: .15rem .4rem; border-radius: var(--radius-sm); }

/* ── Badges ── */
.badge {
  display: inline-block; padding: .18rem .55rem;
  border-radius: 20px; font-size: .72rem; font-weight: 600;
  white-space: nowrap;
}
.badge--activo    { background: #e8f5ee; color: var(--c-success); }
.badge--borrador  { background: #f5f5e8; color: #776600; }
.badge--archivado { background: #f0f0f0; color: #888; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--c-text-muted); }
.empty-state__icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state__text { margin-bottom: 1.5rem; }

/* ── Form cards ── */
.form-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.form-card__header {
  display: flex; align-items: center; gap: .75rem;
  padding: .8rem 1.1rem;
  background: #f5f5f3;
  border-bottom: 1px solid var(--c-border);
}
.form-card__header--toggle {
  width: 100%; text-align: left; cursor: pointer;
  background: none; border: none; font: inherit;
}
.form-card__header--toggle:hover { background: #eeeeec; }
.form-card__num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--c-accent); color: #fff;
  font-size: .78rem; font-weight: 700; flex-shrink: 0;
}
.form-card__title { font-size: .92rem; font-weight: 600; flex: 1; }
.form-card__chevron { color: var(--c-text-muted); font-size: .9rem; transition: transform .2s; }
.form-card__chevron--open { transform: rotate(180deg); }
.form-card__body  { padding: 1.1rem; }
.form-card__body--collapsible { display: none; }
.form-card__body--collapsible.is-open { display: block; }

/* ── Fields ── */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field--full  { grid-column: 1 / -1; }
.field--span2 { grid-column: span 2; }

.field-grid       { display: grid; gap: .85rem; }
.field-grid--2    { grid-template-columns: 1fr 1fr; }
.field-grid--3    { grid-template-columns: 1fr 1fr 1fr; }
.field-grid--4    { grid-template-columns: 1fr 1fr 1fr 1fr; }
.field-grid--5    { grid-template-columns: 1fr 1fr 1fr 1fr 1fr; }

.field__label { font-size: .78rem; font-weight: 600; color: var(--c-text-muted); }
.req { color: var(--c-danger); }

.field__input,
.field__select,
.field__textarea {
  width: 100%; padding: .45rem .7rem;
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  font: inherit; font-size: .85rem; color: var(--c-text);
  background: var(--c-surface);
  transition: border-color .15s, box-shadow .15s;
}
.field__input:focus,
.field__select:focus,
.field__textarea:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 2px rgba(26,26,24,.1);
}
.field__input--sm  { padding: .3rem .5rem; text-align: center; }
.field__textarea   { resize: vertical; min-height: 80px; }
.field__textarea--sm  { min-height: 52px; }
.field__textarea--code { font-family: var(--font-mono); font-size: .78rem; }

.field-note {
  font-size: .75rem; color: var(--c-text-muted);
  background: #f8f8f6; border: 1px solid var(--c-border-lt);
  border-radius: var(--radius-sm); padding: .5rem .75rem;
  margin-top: .75rem;
}

.field-section { margin-bottom: 1.25rem; }
.field-section__title {
  font-size: .84rem; font-weight: 600; color: var(--c-text);
  margin-bottom: .6rem; padding-bottom: .35rem;
  border-bottom: 1px solid var(--c-border-lt);
}

/* ── Picto grid ── */
.picto-grid {
  display: flex; flex-wrap: wrap; gap: .6rem;
  padding: .5rem 0;
}
.picto-card {
  display: flex; flex-direction: column; align-items: center;
  width: 80px; padding: .5rem .3rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  cursor: pointer; transition: border-color .15s, background .15s;
  background: var(--c-surface);
}
.picto-card input[type=checkbox] { display: none; }
.picto-card:hover { border-color: #999; }
.picto-card--selected { border-color: var(--c-accent); background: #f8f8f5; }
.picto-card__img { width: 44px; height: 44px; object-fit: contain; margin-bottom: .3rem; }
.picto-card__placeholder {
  width: 44px; height: 44px; border: 1.5px solid #cc0000;
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; font-weight: bold; color: #cc0000;
  margin-bottom: .3rem;
}
.picto-card__label { font-size: .65rem; text-align: center; color: var(--c-text-muted); line-height: 1.3; }
.picto-card--sm { width: 70px; }
.picto-grid--sm .picto-card { width: 70px; }

/* Pictogramas de órgano diana (HMIS Salud): compactos, 4 por fila, sin texto (tooltip al pasar el mouse) */
#to-grid.picto-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
  width: 100%; max-width: 320px; padding: .3rem 0;
}
#to-grid .picto-card { width: auto; padding: .4rem; }
#to-grid .picto-card__img { width: 36px; height: 36px; margin-bottom: 0; }
#to-grid .picto-card__placeholder { width: 36px; height: 36px; font-size: .55rem; margin-bottom: 0; }
#to-grid .picto-card__label { display: none; }

/* ── Radio cards ── */
.radio-group { display: flex; gap: .75rem; flex-wrap: wrap; }
.radio-card {
  display: flex; flex-direction: column; align-items: center;
  padding: .75rem 2rem; border: 1.5px solid var(--c-border);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.radio-card input[type=radio] { display: none; }
.radio-card:hover { border-color: #999; }
.radio-card--selected { border-color: var(--c-accent); background: #f8f8f5; }
.radio-card__label { font-size: 1rem; font-weight: 700; }
.radio-card__label--danger { color: var(--c-danger); }
.radio-card__label--warn   { color: var(--c-warn); }
.radio-card__sub { font-size: .72rem; color: var(--c-text-muted); }

/* ── Phrase selector ── */
.phrase-selector { position: relative; }
.phrase-selector__input-wrap { position: relative; }
.phrase-selector__search {
  width: 100%; padding: .5rem .8rem;
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  font: inherit; font-size: .85rem;
}
.phrase-selector__search:focus {
  outline: none; border-color: var(--c-accent);
  box-shadow: 0 0 0 2px rgba(26,26,24,.1);
}
.phrase-selector__dropdown {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px);
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  max-height: 240px; overflow-y: auto; z-index: 50;
  display: none;
}
.phrase-selector__dropdown.is-open { display: block; }
.phrase-option {
  padding: .5rem .85rem; cursor: pointer; font-size: .83rem;
  border-bottom: 1px solid var(--c-border-lt);
  transition: background .1s;
}
.phrase-option:last-child { border-bottom: none; }
.phrase-option:hover { background: var(--c-bg); }
.phrase-option--highlighted { background: var(--c-bg); box-shadow: inset 3px 0 0 var(--c-accent); }
.phrase-option__code { font-weight: 600; margin-right: .5rem; font-family: var(--font-mono); }
.phrase-option__desc { color: var(--c-text-muted); }
.phrase-selector__tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; min-height: 24px; }
.phrase-tag {
  display: inline-flex; align-items: center; gap: .35rem;
  background: #f0f0ee; border: 1px solid var(--c-border);
  border-radius: 20px; padding: .2rem .7rem;
  font-size: .78rem; color: var(--c-text);
}
.phrase-tag__code  { font-weight: 600; font-family: var(--font-mono); }
.phrase-tag__desc  { color: var(--c-text-muted); max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phrase-tag__remove {
  background: none; border: none; cursor: pointer;
  color: var(--c-text-muted); font-size: .9rem; padding: 0;
  line-height: 1; transition: color .1s;
}
.phrase-tag__remove:hover { color: var(--c-danger); }

/* ── Component table editor ── */
.comp-table-wrap { overflow-x: auto; margin-bottom: .75rem; }
.comp-editor { width: 100%; border-collapse: collapse; font-size: .82rem; }
.comp-editor th {
  background: #f0f0ee; border: 1px solid var(--c-border);
  padding: .5rem .6rem; font-size: .75rem; font-weight: 600;
  color: var(--c-text-muted); white-space: nowrap;
}
.comp-editor td { border: 1px solid var(--c-border-lt); padding: .3rem .4rem; vertical-align: middle; }
.comp-editor input {
  width: 100%; border: none; background: transparent;
  font: inherit; font-size: .82rem; padding: .15rem .2rem;
}
.comp-editor input:focus { outline: 1px solid var(--c-accent); border-radius: 2px; }
.comp-editor .btn-del { background: none; border: none; cursor: pointer; color: var(--c-text-muted); font-size: 1rem; }
.comp-editor .btn-del:hover { color: var(--c-danger); }

/* ── Form actions ── */
.form-actions {
  display: flex; gap: .75rem; flex-wrap: wrap;
  padding: 1.25rem 0; margin-top: .5rem;
  border-top: 1px solid var(--c-border-lt);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .field-grid--2,
  .field-grid--3,
  .field-grid--4 { grid-template-columns: 1fr; }
  .field--span2  { grid-column: auto; }
  .page-top      { flex-direction: column; }
  .filter-bar    { flex-direction: column; }
  .filter-bar__search { min-width: unset; }
  .two-col, .radio-group { flex-direction: column; }
}

/* ── EPP Grid — secciones horizontales ── */
.epp-sections {
  display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-start;
}
.epp-section {
  background: var(--c-bg);
  border: 1px solid var(--c-border-lt);
  border-radius: var(--radius);
  padding: .5rem .6rem;
  min-width: 0;
}
.epp-section__title {
  font-size: .65rem; font-weight: 600;
  color: var(--c-text-muted); text-transform: uppercase;
  letter-spacing: .05em; margin-bottom: .4rem;
  white-space: nowrap;
}
.epp-grid {
  display: flex; flex-wrap: nowrap; gap: .4rem; align-items: flex-start;
}
.epp-card__text {
  font-size: .68rem; padding: .2rem .35rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  width: 72px; margin-top: .2rem;
  background: #fafaf8;
}
.epp-card__text:focus {
  outline: none; background: #fff;
  border-color: var(--c-accent);
}

/* ── Pictogramas GHS y de transporte más grandes (solo formulario) ── */
#ghs-grid.picto-grid,
#un-grid.picto-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1rem;
}
#ghs-grid .picto-card,
#un-grid .picto-card {
  width: auto;
}
#ghs-grid .picto-card__img,
#un-grid .picto-card__img {
  width: 72px;
  height: 72px;
}
#ghs-grid .picto-card__placeholder,
#un-grid .picto-card__placeholder {
  width: 72px;
  height: 72px;
}
#ghs-grid .picto-card__label,
#un-grid .picto-card__label {
  font-size: 14pt;
}

/* ── Tabla de productos: headers ordenables ── */
.th-sort {
  display: block;
  margin: -.65rem -.9rem;
  padding: .65rem .9rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.th-sort:hover {
  background: rgba(0,0,0,.04);
  text-decoration: underline;
}
