/* ==========================================================================
   Portal de Pacientes — Dr. Juan Carlos Vargas
   Estilo inspirado en sistemas clínicos tipo Orpheus, con la identidad
   plateado / negro / blanco del sitio principal.
   ========================================================================== */

:root {
  --black: #0e2429;
  --charcoal: #143139;
  --charcoal-2: #1a3941;
  --charcoal-3: #204048;
  --navy: #232c58;
  --navy-light: #4a5390;
  --gold: #a67f46;
  --gold-light: #c9a467;
  --gold-dark: #8c6b38;
  --text-soft: #c7c2b3;
  --line: rgba(243, 239, 231, 0.14);
  --white: #ffffff;
  --off-white: #f3efe7;
  --success: #4caf7d;
  --success-bg: rgba(76,175,125,.12);
  --warn: #d1a856;
  --warn-bg: rgba(209,168,86,.12);
  --danger: #c85a5a;
  --danger-bg: rgba(200,90,90,.12);

  --font-display: "Cormorant Garamond", serif;
  --font-body: "Jost", "Helvetica Neue", Arial, sans-serif;
  --radius: 3px;
  --transition: .3s ease;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--black);
  color: var(--off-white);
  font-family: var(--font-body);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { font-family: var(--font-display); color: var(--white); font-weight: 500; margin: 0 0 .4em; }
a { color: inherit; text-decoration: none; }
p { color: var(--text-soft); margin: 0 0 1em; }

/* ---------- Auth screens (login / registro) ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth-visual {
  position: relative;
  background: linear-gradient(160deg, var(--charcoal-3), var(--black) 75%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-right: 1px solid var(--line);
  padding: 60px;
  text-align: center;
}
.auth-visual::before {
  content: "";
  position: absolute; inset: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 56px 56px;
  opacity: .15;
  mask-image: radial-gradient(ellipse at center, black, transparent 75%);
}
.auth-visual .brand-mark {
  position: relative;
  width: min(280px, 60%);
  margin-bottom: 28px;
}
.auth-visual h2 { position: relative; max-width: 380px; }
.auth-visual p { position: relative; max-width: 360px; }

.auth-panel {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card .eyebrow {
  font-size: .7rem; letter-spacing: .28em; text-transform: uppercase; color: var(--gold);
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.auth-card .eyebrow::before { content:""; width: 26px; height: 1px; background: var(--gold); }
.auth-card h1 { font-size: 2.1rem; margin-bottom: 8px; }
.auth-card > p { margin-bottom: 34px; font-size: .92rem; }

.field { margin-bottom: 20px; }
.field label {
  display: block; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 8px;
}
.field input, .field select {
  width: 100%; background: rgba(255,255,255,.03); border: 1px solid var(--line);
  color: var(--white); padding: 13px 15px; font-family: var(--font-body); font-size: .95rem;
  border-radius: var(--radius); transition: var(--transition);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--gold-light); background: rgba(255,255,255,.06); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.check-row { display: flex; align-items: flex-start; gap: 10px; margin: 22px 0; }
.check-row input { margin-top: 3px; }
.check-row label { font-size: .82rem; color: var(--text-soft); }

.form-links { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: .82rem; }
.form-links a { color: var(--gold); border-bottom: 1px solid transparent; }
.form-links a:hover { color: var(--white); border-color: var(--gold); }

.role-tabs { display: flex; gap: 8px; margin-bottom: 28px; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; }
.role-tabs button {
  flex: 1; padding: 10px; background: transparent; border: none; color: var(--gold);
  font-family: var(--font-body); font-size: .78rem; letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer; border-radius: 2px; transition: var(--transition);
}
.role-tabs button.active { background: var(--gold-light); color: var(--black); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 28px; font-size: .8rem; letter-spacing: .1em; text-transform: uppercase;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; transition: var(--transition);
  font-family: var(--font-body);
}
.btn-primary { background: linear-gradient(135deg, var(--gold-light), var(--gold-dark)); color: var(--black); font-weight: 500; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline { background: transparent; border-color: var(--line); color: var(--off-white); }
.btn-outline:hover { border-color: var(--gold-light); background: rgba(255,255,255,.04); }
.btn-block { width: 100%; }
.btn-sm { padding: 9px 16px; font-size: .72rem; }
.btn-danger { background: transparent; border-color: rgba(200,90,90,.4); color: #e08a8a; }

.alert { padding: 12px 16px; border-radius: var(--radius); font-size: .84rem; margin-bottom: 18px; display:none; }
.alert.show { display: block; }
.alert-error { background: var(--danger-bg); color: #e6a1a1; border: 1px solid rgba(200,90,90,.3); }
.alert-success { background: var(--success-bg); color: #9fd8bb; border: 1px solid rgba(76,175,125,.3); }

/* ---------- App shell (dashboards) ---------- */
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.app-sidebar {
  background: var(--charcoal); border-right: 1px solid var(--line);
  padding: 28px 22px; display: flex; flex-direction: column;
}
.app-brand { font-family: var(--font-display); font-size: 1.3rem; color: var(--white); margin-bottom: 4px; }
.app-brand small { display:block; font-family: var(--font-body); font-size: .6rem; letter-spacing: .2em; color: var(--gold); text-transform: uppercase; }
.app-nav { list-style: none; margin: 40px 0 0; padding: 0; flex: 1; }
.app-nav li { margin-bottom: 4px; }
.app-nav a {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  color: var(--off-white); font-size: .86rem; transition: var(--transition);
}
.app-nav a:hover { background: rgba(255,255,255,.04); }
.app-nav a.active { background: rgba(255,255,255,.07); color: var(--white); border-left: 2px solid var(--gold-light); }
.app-nav svg { flex-shrink: 0; opacity: .85; }
.app-user { border-top: 1px solid var(--line); padding-top: 18px; font-size: .82rem; }
.app-user .name { color: var(--white); }
.app-user .role { color: var(--gold); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; margin: 2px 0 12px; }
.app-back-link {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-size: .78rem; color: var(--text-soft); transition: var(--transition);
}
.app-back-link:hover { color: var(--gold-light); }
.app-back-link svg { flex-shrink: 0; }

.app-main { padding: 40px 48px; max-width: 1240px; }
.app-topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 36px; flex-wrap: wrap; gap: 16px; }
.app-topbar h1 { font-size: 2rem; margin-bottom: 6px; }
.app-topbar .sub { color: var(--gold); font-size: .9rem; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 40px; }
.stat-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; background: linear-gradient(180deg, rgba(255,255,255,.02), transparent); }
.stat-card b { display: block; font-family: var(--font-display); font-size: 2rem; color: var(--white); }
.stat-card span { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.015); margin-bottom: 28px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 26px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 1.2rem; }
.panel-body { padding: 26px; }

table.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--gold); padding: 10px 14px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 14px; border-bottom: 1px solid var(--line); font-size: .88rem; color: var(--text-soft); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

.pill { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; }
.pill-success { background: var(--success-bg); color: #9fd8bb; }
.pill-warn { background: var(--warn-bg); color: #e5c98d; }
.pill-danger { background: var(--danger-bg); color: #e6a1a1; }
.pill-neutral { background: rgba(255,255,255,.06); color: var(--text-soft); }

.search-input { position: relative; }
.search-input input {
  background: rgba(255,255,255,.03); border: 1px solid var(--line); color: var(--white);
  padding: 11px 16px; border-radius: var(--radius); font-family: var(--font-body); font-size: .88rem; width: 280px;
}

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-soft); }

/* ---------- Ficha médica ---------- */
.ficha-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 30px; flex-wrap: wrap; }
.ficha-id { display: flex; gap: 20px; align-items: center; }
.ficha-avatar {
  width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-size: 1.5rem; color: var(--gold-light);
  background: var(--charcoal-3);
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 30px; overflow-x: auto; }
.tab-btn {
  padding: 14px 20px; background: none; border: none; color: var(--gold);
  font-family: var(--font-body); font-size: .82rem; letter-spacing: .04em; text-transform: uppercase;
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; transition: var(--transition);
}
.tab-btn.active { color: var(--white); border-bottom-color: var(--gold-light); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.info-item span.label { display: block; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--gold); margin-bottom: 6px; }
.info-item span.value { color: var(--white); font-size: .95rem; }

/* Galería clínica */
.gallery-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.gallery-item {
  aspect-ratio: 4/3; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(150deg, var(--charcoal-3), var(--black));
  position: relative; overflow: hidden; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-soft); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; text-align: center;
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item .tag { position: absolute; bottom: 8px; left: 8px; font-size: .62rem; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 20px; letter-spacing: .06em; }
.gallery-upload {
  aspect-ratio: 4/3; border: 1px dashed var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--gold); cursor: pointer; transition: var(--transition); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase;
}
.gallery-upload:hover { border-color: var(--gold-light); background: rgba(255,255,255,.03); }

/* Notas / historia clínica */
.note-item { border-bottom: 1px solid var(--line); padding: 20px 0; }
.note-item:last-child { border-bottom: none; }
.note-meta { display: flex; justify-content: space-between; font-size: .72rem; color: var(--gold); margin-bottom: 8px; letter-spacing: .04em; text-transform: uppercase; }
.note-body { color: var(--text-soft); font-size: .92rem; white-space: pre-wrap; }

textarea.note-input {
  width: 100%; min-height: 100px; background: rgba(255,255,255,.03); border: 1px solid var(--line);
  color: var(--white); padding: 14px 16px; font-family: var(--font-body); font-size: .92rem; border-radius: var(--radius); resize: vertical;
}

/* ---------- Annotator modal ---------- */
.annotator-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 200;
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.annotator-overlay.open { display: flex; }
.annotator-box { background: var(--charcoal); border: 1px solid var(--line); border-radius: var(--radius); max-width: 920px; width: 100%; max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.annotator-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.annotator-tools { display: flex; gap: 8px; padding: 14px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tool-btn {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: transparent; color: var(--off-white);
  cursor: pointer; transition: var(--transition);
}
.tool-btn.active, .tool-btn:hover { border-color: var(--gold-light); background: rgba(255,255,255,.06); }
.tool-color { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.tool-color.active { border-color: var(--white); }
.annotator-canvas-wrap { flex: 1; overflow: auto; background: repeating-conic-gradient(#111 0% 25%, #161616 0% 50%) 0 0 / 20px 20px; display: flex; align-items: center; justify-content: center; padding: 20px; }
.annotator-canvas-wrap canvas { max-width: 100%; box-shadow: 0 0 0 1px var(--line); }
.annotator-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); }

@media (max-width: 980px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { display: none; }
  .app-main { padding: 24px; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
