/* ==========================================================
   MySynergy Clinic — Panel de administración
   Mismo branding que el sitio: rojo #EE4323, negro, Archivo.
   ========================================================== */

:root {
  --red: #ee4323;
  --red-dark: #cf3417;
  --red-soft: rgba(238, 67, 35, 0.12);
  --black: #0f0f0f;
  --charcoal: #212121;
  --charcoal-2: #191919;
  --white: #ffffff;
  --gray-soft: #f3f3f3;
  --text-body: #595959;
  --text-heading: #242424;
  --text-on-dark: #e9e9e9;
  --text-muted-dark: #9a9a9a;
  --border: #e4e4e4;
  --border-dark: #2c2c2c;
  --ok: #1f9d55;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --radius-pill: 35px;
  --sidebar-w: 260px;
}

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

body {
  font-family: "Archivo", system-ui, sans-serif;
  background: var(--gray-soft);
  color: var(--text-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--text-heading); line-height: 1.2; font-weight: 700; }
a { color: var(--red); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.hidden { display: none !important; }

/* ---------- Utilidades de marca ---------- */
.brand-mark { font-weight: 800; letter-spacing: -0.02em; }
.brand-mark .accent { color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-pill);
  padding: 12px 22px; font-weight: 700; font-size: 15px;
  background: var(--red); color: #fff; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--red-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-body); border: 1px solid var(--border); }
.btn-ghost:hover { background: #fff; color: var(--text-heading); }
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* ==========================================================
   LOGIN
   ========================================================== */
#login-view {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(238,67,35,.18), transparent 60%),
    var(--black);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--white);
  border-radius: 20px; padding: 40px 34px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.login-logo { font-size: 26px; margin-bottom: 4px; }
.login-sub { font-size: 14px; color: var(--text-body); margin-bottom: 28px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--text-heading); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 13px 14px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 10px; background: #fafafa; color: var(--text-heading);
  transition: border-color .15s, background .15s;
}
.field input:focus { outline: none; border-color: var(--red); background: #fff; }
.login-card .btn { width: 100%; margin-top: 6px; }
.login-link {
  display: block; margin: 14px auto 0; padding: 4px 8px; border: 0;
  background: transparent; color: var(--red); font: inherit; font-size: 13.5px; font-weight: 700;
}
.login-link:hover { text-decoration: underline; }
.login-link:disabled { opacity: .6; cursor: not-allowed; }
.form-msg { font-size: 13.5px; margin-top: 14px; min-height: 18px; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--ok); }

/* ==========================================================
   APP SHELL
   ========================================================== */
#app-view { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--black); color: var(--text-on-dark);
  display: flex; flex-direction: column; padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-logo { font-size: 21px; color: #fff; padding: 6px 10px 22px; }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px; color: var(--text-muted-dark);
  font-weight: 600; font-size: 14.5px; border: none; background: transparent; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--red); color: #fff; }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-lock { margin-left: auto; font-size: 11px; opacity: .5; }

.sidebar-foot { border-top: 1px solid var(--border-dark); padding-top: 14px; margin-top: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--red);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px; flex-shrink: 0;
}
.user-meta { overflow: hidden; }
.user-name { color: #fff; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: var(--red); font-weight: 700; }

/* ---------- Main ---------- */
.main { padding: 34px 40px; overflow-y: auto; height: 100vh; }
.page-head { margin-bottom: 26px; }
.page-head h1 { font-size: 28px; }
.page-head p { font-size: 15px; margin-top: 4px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px;
}
.card h3 { font-size: 16px; margin-bottom: 6px; }
.stat { font-size: 34px; font-weight: 800; color: var(--text-heading); letter-spacing: -.02em; }
.stat-label { font-size: 13px; color: var(--text-body); }

.soon {
  border: 1px dashed var(--border); background: #fff; border-radius: var(--radius);
  padding: 40px; text-align: center; color: var(--text-body);
}
.soon .badge {
  display: inline-block; background: var(--red-soft); color: var(--red);
  font-weight: 700; font-size: 12px; padding: 5px 12px; border-radius: 20px; margin-bottom: 14px;
}
.soon h2 { font-size: 22px; margin-bottom: 8px; }
.soon p { max-width: 460px; margin: 0 auto; font-size: 14.5px; }

/* ---------- Tabla ---------- */
.table-wrap { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 18px; font-size: 14px; }
thead th { background: #fafafa; color: var(--text-heading); font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
.role-pill {
  display: inline-block; padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 700;
  background: var(--red-soft); color: var(--red-dark);
}
.role-pill.usuario { background: #eef1f4; color: #55606c; }
select.role-select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 13px; background: #fff; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; }

/* ---------- Gestión de personas ---------- */
.users-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; }
.users-filters { display: flex; gap: 10px; flex: 1; }
.users-search {
  width: min(420px, 100%); padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: #fff; color: var(--text-heading); font: inherit; font-size: 14px;
}
.users-search:focus { outline: 2px solid var(--red-soft); border-color: var(--red); }
.users-msg { margin: 0 0 12px; }
.users-table td:first-child strong, .users-table td:first-child small { display: block; }
.users-table td:first-child small { color: var(--text-body); font-size: 12.5px; margin-top: 2px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-pill.is-active { color: var(--ok); }
.status-pill.is-inactive { color: var(--danger); }
.row-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.btn-ghost.danger { color: var(--danger); border-color: rgba(220,38,38,.28); }
.btn-ghost.danger:hover { background: rgba(220,38,38,.06); }

.admin-dialog {
  width: min(620px, calc(100% - 32px)); border: 0; border-radius: 18px; padding: 0;
  box-shadow: 0 28px 80px rgba(0,0,0,.34); color: var(--text-body);
}
.admin-dialog::backdrop { background: rgba(15,15,15,.62); backdrop-filter: blur(3px); }
.admin-dialog form { padding: 26px; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.dialog-head h2 { font-size: 22px; }
.dialog-head p { font-size: 13.5px; margin-top: 4px; }
.dialog-close { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--gray-soft); font-size: 24px; line-height: 1; }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.dialog-grid select { width: 100%; padding: 13px 14px; font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.credential-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(15,15,15,.68); }
.credential-card { width: min(440px, 100%); padding: 30px; border-radius: 18px; background: #fff; box-shadow: 0 30px 90px rgba(0,0,0,.4); }
.credential-card .badge { display: inline-block; padding: 5px 11px; border-radius: 20px; background: var(--red-soft); color: var(--red); font-size: 12px; font-weight: 700; }
.credential-card h2 { margin: 10px 0 4px; }
.credential-card p { font-size: 14px; }
.credential-card code { display: block; margin: 18px 0; padding: 14px; border-radius: 10px; background: var(--black); color: #fff; font: 700 18px/1.4 "Space Mono", monospace; overflow-wrap: anywhere; }
.credential-card .btn { width: 100%; margin-top: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  /* Las filas se declaran: sin esto el grid reparte el alto sobrante entre
     las dos y la barra negra se estira hasta media pantalla. */
  #app-view { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  /* Ningun hijo de un grid o flex debe poder ensanchar la pagina: por
     defecto traen min-width:auto y se niegan a encogerse. */
  #app-view, .sidebar, .main { min-width: 0; max-width: 100vw; }
  .sidebar { overflow-x: hidden; }
  .main { overflow-x: hidden; }

  /* En el teléfono el menú deja de ser una barra lateral y se vuelve una
     tira horizontal arriba del contenido.
     Antes intentaba ponerse en fila pero .nav-item conservaba width:100%,
     así que cada sección ocupaba su propio renglón, y .nav conservaba
     flex:1, así que se estiraba y dejaba el logo centrado a un lado con
     media pantalla vacía. */
  .sidebar {
    position: sticky; top: 0; z-index: 20;
    height: auto; flex-direction: column; align-items: stretch;
    padding: 12px 0 10px; gap: 10px;
  }
  .sidebar-logo { padding: 0 16px; font-size: 19px; }

  .nav {
    flex: none;
    flex-direction: row; flex-wrap: nowrap;
    gap: 8px; padding: 0 16px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Sin esto la tira no se desliza: se ensancha. Un hijo flex trae
       min-width:auto, o sea que se niega a encogerse por debajo de su
       contenido --- empujaba la pagina a 2000px de ancho y el telefono
       alejaba todo para que cupiera. De ahi que se viera "como computadora". */
    min-width: 0;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    width: auto; flex: 0 0 auto; white-space: nowrap;
    padding: 9px 15px; font-size: 14px;
  }
  /* Los encabezados de grupo no caben en una tira y la parten en pedazos. */
  .nav-grupo { display: none; }

  /* En el teléfono esta fila está hasta arriba, donde el espacio vale más.
     Va compacta: quien entró se lee de un vistazo y no estorba. */
  .sidebar-foot {
    width: 100%; margin: 0; padding: 8px 16px 0;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
  }
  .user-chip { padding: 0; gap: 8px; }
  .avatar { width: 28px; height: 28px; font-size: 12px; }

  .main { height: auto; padding: 24px 20px; }
  .users-toolbar, .users-filters { align-items: stretch; flex-direction: column; }
  .users-search { width: 100%; }
  .table-wrap { overflow-x: auto; }
  .users-table { min-width: 720px; }
  .dialog-grid { grid-template-columns: 1fr; }
}

/* Pantalla "Necesitas invitación" */
.invite-title { font-size: 1.4rem; margin: 0.4rem 0 0.6rem; color: #EE4323; font-weight: 800; }
#invite-view { }

/* ---- Botones OAuth con logo (Google / Apple) ---- */
.btn-oauth{display:flex;align-items:center;justify-content:center;gap:10px}
.btn-oauth .oauth-ic{width:18px;height:18px;flex:none}
.btn-oauth--apple{background:#000;color:#fff;border:1px solid #000}
.btn-oauth--apple:hover{background:#1a1a1a;color:#fff}

/* ---- Clientes: tarjeta + lucecita de "activo" ---- */
.cli-search{padding:10px 12px;border:1px solid var(--border);border-radius:10px;background:#fafafa;
  color:var(--text-heading);font:inherit;font-size:14px;min-width:220px;flex:1}
.cli-search:focus{outline:none;border-color:var(--red);background:#fff}
.cli-card{transition:transform .12s ease,box-shadow .12s ease}
.cli-card:hover{transform:translateY(-2px);box-shadow:0 8px 22px rgba(0,0,0,.08)}
.cli-card.is-inactivo{opacity:.82}
.cli-light{width:12px;height:12px;border-radius:50%;flex:none;background:#c9c9c9}
.cli-card.is-activo .cli-light{background:#22c55e;animation:cliPulse 1.9s ease-in-out infinite}
@keyframes cliPulse{
  0%,100%{box-shadow:0 0 0 2px rgba(34,197,94,.35)}
  50%{box-shadow:0 0 0 7px rgba(34,197,94,0)}
}

/* ---- Teléfono con lada de país ---- */
.phone-row{display:flex;gap:8px}
.phone-row .cc-select{flex:0 0 150px;padding:13px 8px;font-size:14px;border:1px solid var(--border);
  border-radius:10px;background:#fafafa;font-family:inherit;color:var(--text-heading)}
.phone-row .cc-select:focus{outline:none;border-color:var(--red)}
.phone-row input{flex:1;min-width:0}

/* ---- Chips de servicios en la tarjeta de cliente ---- */
.cli-serv{font-family:inherit;font-size:11.5px;font-weight:700;padding:4px 10px;border-radius:20px;
  border:1px solid var(--border);background:#fafafa;color:var(--text-body);cursor:pointer;transition:all .12s}
.cli-serv.on{background:var(--red);border-color:var(--red);color:#fff}

/* Encabezados de grupo del menú lateral */
.nav-grupo {
  font-family: var(--mono, monospace);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  padding: 16px 14px 6px;
}
.nav-grupo:first-child { padding-top: 4px; }
