/* ════════════════════════════════════════════════════════════════════════
   ECOM CCA · Gestión de Usuarios — Hoja de estilos
   Estética: clean corporativo blanco + azul de marca.
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* Surfaces & text */
  --bg:            #f8fafc;
  --surface:       #ffffff;
  --text:          #0f172a;
  --text-soft:     #475569;
  --text-mute:     #94a3b8;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;

  /* Brand azul (del logo) */
  --brand:         #1e40af;
  --brand-light:   #3b82f6;
  --brand-soft:    #eff6ff;
  --brand-ring:    rgba(59, 130, 246, .18);

  /* Accents */
  --success:       #059669;
  --success-dark:  #047857;
  --danger:        #dc2626;
  --danger-soft:   #fef2f2;

  /* Radius & shadows */
  --radius:        14px;
  --radius-sm:     10px;
  --shadow-sm:     0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow:        0 4px 12px rgba(15, 23, 42, .05), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg:     0 12px 32px rgba(15, 23, 42, .12);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.topbar__logo {
  height: 68px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.topbar__brand {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  border-left: 2px solid var(--brand-light);
  padding-left: 24px;
}
.topbar__name { font-size: 1.5rem; font-weight: 700; color: var(--brand); }
.topbar__org  { font-size: 1rem; color: var(--text-soft); margin-top: 2px; }

/* ── Layout ──────────────────────────────────────────────────────────── */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 16px 56px; flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 22px;
}
.card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 20px;
}
.card__head .card__title { margin-bottom: 0; }
.card__title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card__title::before {
  content: '';
  width: 4px;
  height: 20px;
  background: var(--brand-light);
  border-radius: 4px;
  flex-shrink: 0;
}

/* ── Form grid ───────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.field { display: flex; flex-direction: column; gap: 7px; }

label, .label-block {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-soft);
}
.label-block { display: block; margin-bottom: 7px; }
.req { color: var(--danger); }

input, textarea, select {
  font: inherit;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand-light);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
input.invalid, textarea.invalid, select.invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}
textarea { resize: vertical; }
.field__error { color: var(--danger); font-size: .75rem; min-height: 1em; }

/* ── Segmented control (TIPO DE GESTION) ─────────────────────────────── */
.segmented {
  display: flex;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}
.segmented__option {
  flex: 1;
  position: relative;
  cursor: pointer;
}
.segmented__option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented__option span {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 11px 14px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-soft);
  transition: background .15s, color .15s;
}
.segmented__option input:checked + span {
  background: var(--brand);
  color: #fff;
}
.segmented__option input:focus-visible + span {
  box-shadow: inset 0 0 0 2px var(--brand-light);
}

/* ── Botones ─────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 11px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover:not(:disabled) { background: #1e3a8a; }

.btn--success { background: var(--success); color: #fff; }
.btn--success:hover:not(:disabled) { background: var(--success-dark); }

.btn--add {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--brand-light);
}
.btn--add:hover:not(:disabled) { background: var(--brand-soft); }

.btn--ghost { background: transparent; color: var(--text-soft); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--bg); }

.btn--remove {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 6px 10px;
  font-size: .82rem;
  border-radius: 8px;
}
.btn--remove:hover { background: var(--danger-soft); }

/* ── Tarjetas de usuario ─────────────────────────────────────────────── */
.users { display: flex; flex-direction: column; gap: 16px; }

.user-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.user-card:hover { border-color: var(--brand-light); box-shadow: var(--shadow-sm); }

.user-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.user-card__title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.user-card__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.user-card__grid .field { gap: 6px; }
.user-card__grid label { font-size: .76rem; }

.users-empty {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-mute);
  font-size: .9rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.counter {
  margin-top: 16px;
  font-size: .85rem;
  color: var(--text-soft);
  font-weight: 600;
}

/* ── Acciones del formulario ─────────────────────────────────────────── */
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ── Alerta global ───────────────────────────────────────────────────── */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 22px;
  font-size: .9rem;
  display: flex;
  gap: 10px;
  align-items: center;
}
.alert--error   { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; }
.alert--success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.alert--hidden  { display: none; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 100; }
.modal[aria-hidden="false"] { display: flex; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.modal__dialog {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px;
  max-width: 440px;
  width: calc(100% - 32px);
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop .2s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal__icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal__dialog h3 { margin-bottom: 10px; }
.modal__dialog p  { color: var(--text-soft); margin-bottom: 22px; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-mute);
  font-size: .8rem;
}

/* ── Spinner en botón ────────────────────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsivo ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr; }
  .user-card__grid { grid-template-columns: 1fr; }
  .topbar__brand { display: none; }
  .card { padding: 20px; }
}

@media (max-width: 480px) {
  .container { padding: 16px 12px 40px; }
  .card { padding: 16px; border-radius: 12px; }
  .actions { flex-direction: column-reverse; }
  .actions .btn { width: 100%; justify-content: center; }
  .topbar__logo { height: 52px; }
  .topbar__name { font-size: 1.2rem; }
  .topbar__org { font-size: .85rem; }
  .topbar__inner { padding: 16px 16px; gap: 16px; }
  .segmented__option span { padding: 10px 8px; font-size: .85rem; }
}
