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

:root {
  color-scheme: dark;
  --bg:        #0d0d1a;
  --surface:   #16162a;
  --surface2:  #1f1f38;
  --border:    #2e2e52;
  --accent:      #5b8dee;
  --accent-text: #8ab4ff;
  --danger:    #e05c5c;
  --success:   #4caf7d;
  --text:      #dde0f0;
  --muted:     #a5a5cf;
  --radius:    8px;
}

[data-theme="claro"] {
  color-scheme: light;
  --bg:          #eef0f6;
  --surface:     #ffffff;
  --surface2:    #f4f5fa;
  --border:      #c7cbdc;
  --accent:      #3f6bcf;
  --accent-text: #2a56b8;
  --danger:      #c0392b;
  --success:     #2f8f5b;
  --text:        #1c1e2b;
  --muted:       #5b5f78;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  min-height: 100vh;
}

/* LINKS (color por defecto para cualquier <a> sin estilo propio — nav a,
   .btn, .tab y .back ya fijan su propio color y tienen más especificidad) */
a { color: var(--accent-text); }
a:visited { color: var(--accent-text); }

/* NAV */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  min-height: 52px;
}
nav .brand { font-weight: 700; font-size: 1rem; color: var(--accent-text); letter-spacing: .02em; }
nav .nav-links { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-right: 3.25rem; }
nav a { color: var(--muted); text-decoration: none; font-size: .875rem; transition: color .15s; }
nav a:hover { color: var(--text); }
nav .nav-user { font-size: .8rem; color: var(--muted); }

/* CONTAINER */
.container {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 1rem;
}

/* HEADINGS */
h1 { font-size: 1.5rem; margin-bottom: 1.5rem; color: var(--text); }
h2 { font-size: 1.25rem; margin-bottom: 1rem; color: var(--text); }
h3 { font-size: 1rem; margin-bottom: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* CARD */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

/* FORM */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--muted);
  border-radius: var(--radius);
  color: var(--text);
  padding: .4rem .6rem;
  font-size: .85rem;
  transition: border-color .15s;
  outline: none;
}
select { min-width: max-content; }
input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus { border-color: var(--accent); }

/* PASSWORD FIELD (toggle mostrar/ocultar) */
.password-field { position: relative; }
.password-field input[type="password"],
.password-field input[type="text"] { padding-right: 2.5rem; }
.password-toggle {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  line-height: 1;
}
.password-toggle:hover { color: var(--text); }
.password-toggle.activo { color: var(--accent-text); }

/* CHECKBOX */
input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* BUTTONS */
.btn {
  display: inline-block;
  padding: .45rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
  line-height: 1;
}
.btn:hover { opacity: .85; transform: translateY(-1px); }
.btn-primary { background: var(--accent);  color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm      { padding: .3rem .65rem; font-size: .75rem; }
.btn-events  { background: var(--surface2); color: var(--accent-text); border: 1px solid var(--border); font-size: 1rem; padding: .3rem .6rem; }
.btn + .btn  { margin-left: .5rem; }

/* TABLE */
/* overflow-x visible con scrollbar siempre presente: en macOS/móvil las
   scrollbars se ocultan por defecto hasta que se toca, dando la falsa
   impresión de que faltan columnas en tablas anchas */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--surface);
}
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: var(--surface); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted); }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--surface2); }
th { padding: .5rem .75rem; text-align: left; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: .85rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
.td-actions { display: flex; gap: .5rem; align-items: center; }

/* AVISO TEMPORAL (p.ej. al intentar cambiar un campo bloqueado) */
.aviso-tipo {
  display: none;
  font-size: .75rem;
  color: var(--muted);
  margin-top: .25rem;
}
.aviso-tipo.visible { display: block; }

/* DETAILS / ACCORDION */
details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  overflow: hidden;
}
summary {
  padding: .9rem 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-weight: 600;
  list-style: none;
  user-select: none;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: '▶';
  font-size: .65rem;
  color: var(--muted);
  transition: transform .2s;
  flex-shrink: 0;
}
details[open] > summary::before { transform: rotate(90deg); }
summary:hover { background: var(--surface2); }
.summary-info { flex: 1; }
.summary-meta { font-size: .8rem; color: var(--muted); font-weight: 400; }
.details-body { padding: 1rem 1.25rem 1.25rem; border-top: 1px solid var(--border); }

/* INLINE FORM (for borrar buttons inside tables) */
.form-inline { display: inline; margin: 0; }

/* LISTA DE TELÉFONOS EDITABLE (usuario): guardado unificado */
.save-bar { display: none; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.save-bar.visible { display: flex; }
tr.row-modificada { background: #4a3d10; }
[data-theme="claro"] tr.row-modificada { background: #fff3c4; }
tr.row-nueva { font-style: italic; }
tr.row-borrada td { text-decoration: line-through; opacity: .55; }

/* ERROR / ALERT */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
}
.alert-error { background: #2e1515; border: 1px solid var(--danger); color: #f4a0a0; }
[data-theme="claro"] .alert-error { background: #fdecea; border-color: var(--danger); color: #8f2418; }

/* LOGIN PAGE */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { text-align: center; margin-bottom: .25rem; }
.login-card .subtitle { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 2rem; }

/* INLINE ADD FORM (móviles en admin) */
.add-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.add-row input { flex: 1; min-width: 140px; }

/* SECTION HEADER */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}

/* TABS */
.tabs {
  display: flex;
  gap: .25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.tab {
  padding: .6rem 1.25rem;
  color: var(--muted);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* BACK LINK */
.back { display: inline-block; color: var(--muted); text-decoration: none; font-size: .85rem; margin-bottom: 1.5rem; }
.back:hover { color: var(--text); }

/* RESPONSIVE */
@media (max-width: 600px) {
  .container { margin: 1rem auto; }
  nav { padding: 0 1rem; }
  .card { padding: 1rem; }
  .login-card { padding: 1.75rem 1.25rem; }
  th, td { padding: .4rem .5rem; }
}

/* THEME TOGGLE */
.theme-toggle {
  position: fixed;
  top: .75rem;
  right: .75rem;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  text-decoration: none;
  line-height: 1;
}
.theme-toggle:hover { background: var(--surface); }

/* PAPELERAS DISCRETAS */
.btn-trash { background: transparent; color: var(--muted); border: 1px solid transparent; }
.btn-trash:hover { color: var(--danger); border-color: var(--danger); background: transparent; opacity: 1; transform: none; }

/* CAMPOS TEMPORALMENTE EDITABLES POR SOPORTE (futuro: datos de Soporte4D) */
:root { --campo-temporal-bg: rgba(224, 92, 92, .08); }
[data-theme="claro"] { --campo-temporal-bg: rgba(192, 57, 43, .08); }
.campo-temporal input,
.campo-temporal select { background: var(--campo-temporal-bg); border: 1px solid var(--danger); }
.campo-temporal-valor {
  display: inline-block;
  background: var(--campo-temporal-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: .3rem .5rem;
  font-size: .85rem;
}

/* BLOQUE "+" PARA AÑADIR ELEMENTOS INLINE (Puertas, enlaces...) */
details.add-inline { margin-top: .75rem; margin-bottom: 0; background: none; border: none; }
details.add-inline > summary { padding: 0; display: inline-flex; }
details.add-inline > summary::before { display: none; }
details.add-inline > form { margin-top: .75rem; margin-bottom: 0; }

/* FILAS DE ENLACES (frase en vez de tabla) */
.enlace-list { border: 1px solid var(--border); border-radius: var(--radius); padding: 0 1rem; }
.enlace-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .65rem 0; border-bottom: 1px solid var(--border); font-size: .9rem;
}
.enlace-row:last-child { border-bottom: none; }

/* FILAS DE ENLACES EDITABLES (details con formulario precargado) */
details.enlace-row-edit { background: none; border: none; margin-bottom: 0; border-radius: 0; }
.enlace-list details.enlace-row-edit:last-child .enlace-row { border-bottom: none; }
details.enlace-row-edit > form { margin: 0 0 .75rem; }
