/* ===== CRM Grupo Ágata — identidad basada en agataesteticadental.mx ===== */
:root {
  --primary: #9C7094;
  --primary-dark: #7d5876;
  --primary-soft: #E5DAE3;
  --bg: #faf5f9;
  --ink: #222222;
  --muted: #6a6c72;
  --white: #ffffff;
  --ok: #1ebe5d;
  --warn: #e6a23c;
  --bad: #d9534f;
  --radius: 14px;
  --shadow: 0 6px 24px #9C709430;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-brand: 'Cormorant Garamond', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-ui); background: var(--bg); color: var(--ink); font-size: 14px; }
.hidden { display: none !important; }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #faf5f9 0%, #E5DAE3 55%, #9C7094 160%);
}
.login-card {
  background: var(--white); border-radius: 22px; box-shadow: var(--shadow);
  padding: 44px 40px; width: 380px; max-width: 92vw;
}
.brand { text-align: center; margin-bottom: 28px; }
.brand-logo { width: 180px; max-width: 70%; display: block; margin: 0 auto 12px; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; font-family: var(--font-brand); font-size: 38px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.brand-mark.sm { width: 42px; height: 42px; font-size: 24px; margin: 0; }
.brand-name { font-family: var(--font-brand); font-size: 42px; font-weight: 500; letter-spacing: 1px; }
.brand-sub { font-size: 10px; letter-spacing: 4px; color: var(--primary); font-weight: 600; margin-top: 2px; }
.login-foot { text-align: center; color: var(--muted); font-size: 11px; margin-top: 22px; }

label { display: block; font-weight: 600; font-size: 12px; color: var(--ink); margin-bottom: 14px; }
input, select, textarea {
  width: 100%; margin-top: 5px; padding: 10px 12px; border: 1.5px solid var(--primary-soft);
  border-radius: 10px; font: inherit; font-size: 13.5px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #9C709430; }
textarea { resize: vertical; min-height: 70px; }

.btn {
  padding: 10px 18px; border: none; border-radius: 10px; font: inherit; font-weight: 600;
  cursor: pointer; transition: all .15s; font-size: 13.5px;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 4px 14px #9C709460; }
.btn-ghost { background: transparent; color: var(--primary-dark); border: 1.5px solid var(--primary-soft); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: #fbeaea; color: var(--bad); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 15px; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.btn-icon:hover { background: var(--primary-soft); color: var(--primary-dark); }
.error { background: #fbeaea; color: var(--bad); padding: 9px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }

/* ===== Layout app ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--white); border-right: 1px solid var(--primary-soft);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; gap: 8px; align-items: flex-end; padding: 16px 16px 12px; }
.side-logo { height: 40px; width: auto; display: block; }
.side-crm {
  font-size: 9px; letter-spacing: 2px; color: var(--primary); font-weight: 700;
  border: 1px solid var(--primary-soft); padding: 2px 7px; border-radius: 20px; margin-bottom: 3px;
}
.nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--muted); cursor: pointer; font-weight: 500; margin-bottom: 2px; font-size: 13.5px;
  border: none; background: none; width: 100%; text-align: left; font-family: inherit;
}
.nav-item:hover { background: var(--bg); color: var(--primary-dark); }
.nav-item.active { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.nav-item .ico { width: 20px; display: flex; align-items: center; justify-content: center; }
.nav-item .ico svg, .btn-icon svg { display: block; }
.btn svg, .badge svg, td svg { vertical-align: -2px; }
.side-user {
  display: flex; align-items: center; gap: 9px; padding: 14px; border-top: 1px solid var(--primary-soft);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.side-user-info { flex: 1; min-width: 0; }
.side-user-name { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-role { font-size: 10.5px; color: var(--primary); text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 14px;
  padding: 18px 28px; background: var(--white); border-bottom: 1px solid var(--primary-soft);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-family: var(--font-brand); font-size: 26px; font-weight: 500; overflow-wrap: anywhere; }
.topbar-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.content { padding: 24px 28px; flex: 1; }

/* ===== Cards / stats ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 18px; box-shadow: 0 2px 10px #9C709418; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--primary-dark); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card { background: var(--white); border-radius: var(--radius); padding: 20px; box-shadow: 0 2px 10px #9C709418; margin-bottom: 18px; }
.card h3 { font-family: var(--font-brand); font-size: 20px; margin-bottom: 14px; font-weight: 600; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; background: var(--white); border-radius: var(--radius); box-shadow: 0 2px 10px #9C709418; }
.table-scroll { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 12px 14px; background: var(--primary-soft); color: var(--primary-dark);
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px; white-space: nowrap;
}
td { padding: 11px 14px; border-top: 1px solid #f3ebf2; vertical-align: middle; }
tr:hover td { background: var(--bg); }
.t-actions { display: flex; gap: 6px; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.b-purple { background: var(--primary-soft); color: var(--primary-dark); }
.b-green { background: #e6f8ed; color: #148f45; }
.b-yellow { background: #fdf3e3; color: #b47716; }
.b-red { background: #fbeaea; color: var(--bad); }
.b-gray { background: #eee; color: #666; }

/* ===== Toolbar / filters ===== */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; margin-top: 0; }
.spacer { flex: 1; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: #00000055; display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--white); border-radius: 18px; width: 560px; max-width: 100%;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px #00000040;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 12px;
}
.modal-head h3 { font-family: var(--font-brand); font-size: 22px; font-weight: 600; }
.modal-body { padding: 10px 22px 22px; overflow-y: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ===== Tabs (expediente) ===== */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--primary-soft); margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 9px 16px; border: none; background: none; font: inherit; font-weight: 600; font-size: 13px;
  color: var(--muted); cursor: pointer; border-bottom: 2.5px solid transparent; margin-bottom: -2px;
}
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ===== Odontograma ===== */
.odonto-grid { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.odonto-scroll {
  max-width: 100%; overflow-x: auto; display: flex; flex-direction: column;
  gap: 8px; padding-bottom: 6px;
}
.odonto-row { display: flex; gap: 5px; width: max-content; margin: 0 auto; }
.diente {
  width: 34px; height: 44px; border: 1.5px solid var(--primary-soft); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; font-size: 10px; background: #fff; transition: all .1s;
}
.diente:hover { border-color: var(--primary); }
.diente .num { font-weight: 700; font-size: 11px; }
.diente .est { display: flex; align-items: center; justify-content: center; margin-top: 2px; }
.diente.sano .est { color: var(--primary); }
.diente.caries .est { color: #b47716; }
.diente.restaurado .est { color: #4a7fd4; }
.diente.corona .est { color: var(--primary-dark); }
.diente.extraccion .est { color: var(--bad); }
.diente.ausente .est { color: #999; }
.diente.sano { background: #fff; }
.diente.caries { background: #fdf3e3; border-color: var(--warn); }
.diente.restaurado { background: #e3edfd; border-color: #4a7fd4; }
.diente.ausente { background: #f2f2f2; border-color: #bbb; opacity: .6; }
.diente.corona { background: #f3e8fb; border-color: var(--primary); }
.diente.extraccion { background: #fbeaea; border-color: var(--bad); }
.odonto-leyenda { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; font-size: 11.5px; color: var(--muted); }
.odonto-leyenda span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; border: 1px solid #ccc; }

/* ===== Importar expediente ===== */
.import-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.import-row input, .import-row select { margin-top: 0; }
.import-alerta {
  background: #fdf3e3; color: #7a5210; border-radius: 10px; padding: 10px 14px;
  font-size: 12.5px; margin-top: 10px; display: flex; gap: 8px; align-items: flex-start;
}
.import-alerta svg { flex-shrink: 0; margin-top: 1px; }
.import-alerta.roja { background: #fbeaea; color: #8f2f2c; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto; border-radius: 50%;
  border: 3.5px solid var(--primary-soft); border-top-color: var(--primary);
  animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ===== Misc ===== */
.empty { text-align: center; color: var(--muted); padding: 42px 20px; }
.empty .big { margin-bottom: 10px; display: flex; justify-content: center; color: var(--primary-soft); }
.empty .big svg { stroke-width: 1.3; }
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 12px; font-size: 13px; z-index: 100; box-shadow: 0 8px 24px #00000040;
}
.toast.ok { background: #148f45; }
.toast.err { background: var(--bad); }
.muted { color: var(--muted); font-size: 12px; }
.link { color: var(--primary-dark); cursor: pointer; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.item-row { display: grid; grid-template-columns: 2fr 70px 110px 34px; gap: 8px; margin-bottom: 8px; align-items: center; }
.item-row input { margin-top: 0; }
h4.sec { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--primary); margin: 18px 0 10px; }

@media (max-width: 860px) {
  .sidebar { width: 60px; }
  .side-crm, .side-user-info, .nav-item .txt { display: none; }
  .side-brand { justify-content: center; padding: 14px 6px 10px; }
  .side-logo { height: 28px; }
  .nav { padding: 6px; }
  .nav-item { justify-content: center; padding: 10px 8px; }
  .side-user { flex-direction: column; gap: 6px; padding: 10px 6px; }
  .topbar { padding: 12px 16px; }
  .topbar h2 { font-size: 21px; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .item-row { grid-template-columns: 1.5fr 54px 84px 30px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .stat-value { font-size: 21px; }
  .modal { border-radius: 14px; }
  .modal-head { padding: 14px 16px 8px; }
  .modal-body { padding: 8px 16px 16px; }
}
