/* ============================================================
   style.css — DentalSys (Cloudflare)
   ============================================================ */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f5f0;
  height: 100vh;
  overflow: hidden;
}

/* ── Layout ── */
.app { display: flex; height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: #fafaf8;
  border-right: 1px solid #e5e5e0;
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}
.sidebar-header {
  padding: 14px 16px; border-bottom: 1px solid #e5e5e0;
  display: flex; align-items: center; gap: 10px;
}
.logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: #1D9E75; display: flex; align-items: center;
  justify-content: center; color: white; font-size: 17px; flex-shrink: 0;
}
.sidebar-title { font-size: 13px; font-weight: 600; }
.sidebar-sub   { font-size: 11px; color: #888; }

.search-box { padding: 10px 12px; border-bottom: 1px solid #e5e5e0; }
.search-box input {
  width: 100%; padding: 6px 10px; font-size: 12px;
  border-radius: 7px; border: 1px solid #ddd;
  background: white; color: #1a1a1a;
}
.search-box input:focus { outline: none; border-color: #1D9E75; }

.patient-list { flex: 1; overflow-y: auto; }
.patient-item {
  padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid #f0f0ec;
  display: flex; align-items: center; gap: 10px;
  transition: background 0.1s;
}
.patient-item:hover  { background: white; }
.patient-item.active { background: white; border-left: 3px solid #1D9E75; }
.patient-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #E1F5EE; display: flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 600;
  color: #0F6E56; flex-shrink: 0;
}
.patient-name { font-size: 12px; font-weight: 600; }
.patient-meta { font-size: 10px; color: #888; }

.new-btn {
  margin: 10px 12px; padding: 8px; border-radius: 8px;
  background: #1D9E75; color: white; border: none;
  font-size: 12px; font-weight: 500; cursor: pointer;
}
.new-btn:hover { background: #178a63; }
.loading-msg { padding: 16px 12px; font-size: 12px; color: #999; text-align: center; }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: white; }

.header-bar {
  padding: 10px 18px; border-bottom: 1px solid #e5e5e0;
  display: flex; align-items: center; justify-content: space-between;
  background: #fafaf8; flex-shrink: 0;
}
.header-name  { font-size: 15px; font-weight: 600; }
.header-meta  { font-size: 11px; color: #888; }
.historia-num {
  font-size: 10px; padding: 2px 7px; border-radius: 99px;
  background: #E1F5EE; color: #0F6E56; font-weight: 600; margin-left: 8px;
}

.tabs {
  display: flex; border-bottom: 1px solid #e5e5e0;
  padding: 0 16px; background: #fafaf8;
  flex-shrink: 0; overflow-x: auto;
}
.tab {
  padding: 10px 13px; font-size: 12px; cursor: pointer;
  color: #888; border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active       { color: #1D9E75; border-bottom-color: #1D9E75; }
.tab:hover:not(.active) { color: #1a1a1a; }

.content { flex: 1; overflow-y: auto; padding: 18px; }

/* ── Empty state ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; color: #aaa; gap: 8px;
}
.empty-icon  { font-size: 40px; }
.empty-title { font-size: 14px; font-weight: 600; color: #999; }
.empty-sub   { font-size: 12px; }

/* ── Forms ── */
.section-title {
  font-size: 10px; font-weight: 700; color: #888;
  text-transform: uppercase; letter-spacing: 0.08em;
  margin: 16px 0 10px; padding-bottom: 5px;
  border-bottom: 1px solid #e5e5e0;
}
.form-grid       { display: grid; grid-template-columns: 1fr 1fr;     gap: 12px; }
.form-grid.cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-group      { display: flex; flex-direction: column; gap: 3px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label {
  font-size: 10px; font-weight: 600; color: #888;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 6px 9px; border-radius: 7px;
  border: 1px solid #ddd; background: white;
  color: #1a1a1a; font-size: 12px; font-family: inherit;
}
.form-group textarea { resize: vertical; min-height: 54px; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: #1D9E75; }

/* ── Buttons ── */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.save-btn {
  padding: 8px 16px; background: #1D9E75; color: white;
  border: none; border-radius: 8px; font-size: 12px; font-weight: 500; cursor: pointer;
}
.save-btn:hover { background: #178a63; }

.export-btn {
  padding: 8px 16px; background: #f0f0ec; color: #1a1a1a;
  border: 1px solid #ddd; border-radius: 8px; font-size: 12px; font-weight: 500; cursor: pointer;
}
.export-btn:hover { background: #e8e8e4; }

.danger-btn {
  padding: 8px 16px; background: #fff0f0; color: #a32d2d;
  border: 1px solid #f5c1c1; border-radius: 8px; font-size: 12px; font-weight: 500; cursor: pointer;
}
.danger-btn:hover { background: #ffe0e0; }

.icon-btn { background: none; border: none; cursor: pointer; font-size: 13px; color: #aaa; padding: 2px 4px; }
.icon-btn:hover { color: #e24b4a; }

.small-btn {
  padding: 3px 8px; font-size: 11px; border-radius: 6px;
  border: 1px solid #ddd; cursor: pointer; background: white; color: #1a1a1a;
}
.small-btn.danger { border-color: #f5c1c1; color: #a32d2d; background: #fff0f0; }

/* ── Odontograma ── */
.odontogram-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; margin: 12px 0; }
.jaw-title  { font-size: 10px; color: #aaa; }
.tooth-row  { display: flex; gap: 2px; align-items: center; }
.teeth-group { display: flex; gap: 2px; }
.jaw-label  { font-size: 9px; color: #aaa; min-width: 50px; text-align: right; }
.jaw-label.right { text-align: left; }
.odon-divider { height: 10px; width: 1px; background: #ddd; margin: 0 3px; }

.tooth {
  width: 26px; height: 26px; border-radius: 4px;
  border: 1px solid #ddd; background: white;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; user-select: none;
  transition: border-color 0.1s; position: relative;
}
.tooth:hover { border-color: #1D9E75; }
.tooth-num   { font-size: 7px; color: #bbb; }

.tooth.extracted { background: #fce4e4; border-color: #e24b4a; }
.tooth.extracted .tooth-num  { display: none; }
.tooth.extracted::after { content: '✕'; color: #e24b4a; font-size: 12px; font-weight: bold; }

.tooth.filled { background: #E1F5EE; border-color: #1D9E75; }
.tooth.filled .tooth-num { display: none; }
.tooth.filled::after { content: '●'; color: #1D9E75; font-size: 10px; }

.tooth.crown { background: #E6F1FB; border-color: #185FA5; }
.tooth.crown .tooth-num { display: none; }
.tooth.crown::after { content: '♦'; color: #185FA5; font-size: 10px; }

.tooth.cavity { background: #FAEEDA; border-color: #BA7517; }
.tooth.cavity .tooth-num { display: none; }
.tooth.cavity::after { content: '○'; color: #BA7517; font-size: 10px; }

.tooth-tools { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.tool-btn {
  padding: 4px 10px; border-radius: 6px; font-size: 11px;
  border: 1px solid #ddd; cursor: pointer; background: white; color: #1a1a1a;
}
.tool-btn.active { border-color: #1D9E75; background: #E1F5EE; color: #0F6E56; }

.tooth-legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.legend-item  { display: flex; align-items: center; gap: 4px; font-size: 10px; color: #888; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; border: 1px solid; }

/* ── Historial ── */
.nueva-visita-form {
  background: #fafaf8; border: 1px solid #e5e5e0;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 14px;
}
.visita-card {
  background: white; border: 1px solid #e5e5e0;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
}
.visita-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.visita-fecha  { font-size: 12px; font-weight: 600; }
.visita-tipo   { font-size: 10px; padding: 2px 8px; border-radius: 99px; background: #E6F1FB; color: #0C447C; font-weight: 600; }
.visita-tipo.tratamiento { background: #E1F5EE; color: #085041; }
.visita-tipo.urgencia    { background: #FCEBEB; color: #791F1F; }
.visita-desc    { font-size: 12px; color: #555; line-height: 1.5; }
.visita-actions { display: flex; gap: 6px; margin-top: 7px; }
.empty-list     { text-align: center; padding: 20px; font-size: 12px; color: #aaa; }

/* ── Presupuesto ── */
.metric-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 14px; }
.metric-card  { background: #fafaf8; border-radius: 8px; padding: 10px 12px; }
.metric-label { font-size: 10px; color: #888; margin-bottom: 3px; }
.metric-val   { font-size: 20px; font-weight: 600; }
.metric-val.green { color: #1D9E75; }
.metric-val.amber { color: #BA7517; }

.presupuesto-table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.presupuesto-table th {
  text-align: left; padding: 7px 8px; font-size: 10px; font-weight: 700;
  color: #888; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid #e5e5e0;
}
.presupuesto-table td { padding: 7px 8px; border-bottom: 1px solid #f0f0ec; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-badge { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 99px; font-size: 10px; font-weight: 600; cursor: pointer; }
.badge-pagado    { background: #E1F5EE; color: #085041; }
.badge-pendiente { background: #FAEEDA; color: #633806; }

.add-item-row { display: flex; gap: 6px; margin-top: 10px; }
.add-item-row input {
  flex: 1; min-width: 0; padding: 6px 8px; border-radius: 7px;
  border: 1px solid #ddd; background: white; color: #1a1a1a; font-size: 12px;
}
.add-item-row input:focus { outline: none; border-color: #1D9E75; }
.add-item-row input.price { width: 75px; flex: none; }

/* ── Citas ── */
.cita-card {
  background: white; border: 1px solid #e5e5e0;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
}
.cita-date-box {
  width: 44px; height: 44px; border-radius: 8px;
  background: #E1F5EE; display: flex; flex-direction: column;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.cita-day      { font-size: 18px; font-weight: 700; color: #0F6E56; line-height: 1; }
.cita-month    { font-size: 9px; color: #0F6E56; text-transform: uppercase; }
.cita-info     { flex: 1; min-width: 0; }
.cita-paciente { font-size: 12px; font-weight: 600; }
.cita-detalle  { font-size: 11px; color: #888; }
.cita-hora     { font-size: 12px; font-weight: 600; color: #1D9E75; white-space: nowrap; }

/* ── Toast ── */
.toast {
  display: none; position: fixed; bottom: 20px; right: 20px;
  background: #1D9E75; color: white; padding: 9px 16px;
  border-radius: 8px; font-size: 12px; z-index: 1000;
  font-weight: 500; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.toast.show { display: block; }

/* ── Login ── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: #f5f5f0;
}
.login-card {
  background: white; border-radius: 16px; padding: 40px 36px;
  width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  display: flex; flex-direction: column; align-items: center;
}
.login-logo  { font-size: 40px; margin-bottom: 10px; }
.login-title { font-size: 22px; font-weight: 700; }
.login-sub   { font-size: 13px; color: #888; margin-bottom: 4px; }
.login-btn {
  width: 100%; margin-top: 18px; padding: 11px;
  background: #1D9E75; color: white; border: none;
  border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.login-btn:hover { background: #178a63; }
.login-btn:disabled { background: #aaa; cursor: not-allowed; }
.login-error { color: #e24b4a; font-size: 12px; margin-top: 8px; min-height: 16px; text-align: center; }
.login-hint  { font-size: 11px; color: #bbb; margin-top: 14px; text-align: center; }
.login-card .form-group { width: 100%; }
.login-card .form-group input {
  width: 100%; padding: 9px 10px; border-radius: 8px;
  border: 1px solid #ddd; font-size: 13px;
}
.login-card .form-group label {
  font-size: 11px; font-weight: 600; color: #888;
  text-transform: uppercase; letter-spacing: 0.05em;
  display: block; margin-bottom: 4px;
}

/* ── User bar ── */
.user-bar {
  position: fixed; top: 10px; right: 16px;
  display: flex; align-items: center; gap: 8px;
  z-index: 999; background: white;
  padding: 5px 10px; border-radius: 99px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
  font-size: 12px;
}
.logout-btn {
  padding: 3px 10px; border-radius: 99px; font-size: 11px;
  border: 1px solid #ddd; cursor: pointer; background: #f5f5f0; color: #555;
}
.logout-btn:hover { background: #ffe0e0; border-color: #f5c1c1; color: #a32d2d; }

/* ── Role badges ── */
.role-badge  { padding: 2px 8px; border-radius: 99px; font-size: 10px; font-weight: 700; }
.badge-admin { background: #E6F1FB; color: #0C447C; }
.badge-user  { background: #F0F0EC; color: #555; }

/* ── Readonly ── */
.readonly-badge {
  font-size: 9px; padding: 1px 6px; border-radius: 99px;
  background: #FAEEDA; color: #633806; font-weight: 600;
  text-transform: none; letter-spacing: 0; margin-left: 6px; vertical-align: middle;
}
.readonly-notice {
  font-size: 11px; color: #aaa; background: #fafaf8;
  border: 1px solid #e5e5e0; border-radius: 8px;
  padding: 8px 12px; margin-bottom: 10px;
}
.tooth-readonly { cursor: default !important; }
.tooth-readonly:hover { border-color: #ddd !important; }

input[readonly], textarea[readonly] {
  background: #fafaf8 !important;
  color: #888 !important;
  cursor: default;
}
select[disabled] { background: #fafaf8; color: #888; cursor: default; }
