:root {
  --bg: #111a2b;
  --surface: #1a2842;
  --surface-2: #243659;
  --navy-brand: #294371;
  --border: #314873;
  --text: #FFFFFF;
  --text-muted: #b4c2dc;
  --accent: #8DF226;
  --accent-text: #0f1829;
  --accent-hover: #7ce019;
  --danger: #ff5c5c;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* Splash Screen de Abertura */
.splash-screen {
  position: fixed;
  inset: 0;
  background-color: var(--navy-brand);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.splash-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.splash-logo {
  width: 112px;
  height: 112px;
}

.splash-title {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #FFFFFF;
  text-transform: lowercase;
}

/* Header */
.app-header {
  padding: calc(var(--safe-top) + 10px) 18px 12px;
  background: var(--navy-brand);
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand-mark-lg {
  width: 76px;
  height: 76px;
  margin: 0 auto 8px;
  display: block;
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #FFFFFF;
}

.header-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.offline-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(141, 242, 38, 0.14);
  padding: 1px 8px;
  border-radius: 99px;
}

.icon-btn-sq {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

/* Main Content */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(84px + var(--safe-bottom));
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Filter & Action Bar */
.filter-bar, .viewer-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.model-actions-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
}

.action-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
}

.action-pill.danger {
  color: var(--danger);
  border-color: rgba(255, 92, 92, 0.35);
}

input[type="text"], input[type="date"], input[type="time"], input[type="file"], select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.75;
}

.primary-btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

.primary-btn:active {
  background: var(--accent-hover);
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.danger-btn {
  background: rgba(255, 92, 92, 0.16);
  color: var(--danger);
  border: 1px solid rgba(255, 92, 92, 0.35);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.full-width {
  width: 100%;
  display: block;
}

.file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Calendário / Agenda */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.cal-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: capitalize;
  flex: 1;
  text-align: center;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 16px;
}

.cal-day {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  position: relative;
  cursor: pointer;
  color: var(--text);
}

.cal-day.empty {
  cursor: default;
}

.cal-day.today {
  border: 1.5px solid var(--accent);
}

.cal-day.selected {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
}

.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-top: 2px;
}

.cal-dot.upcoming {
  background: var(--accent);
}

.cal-dot.past {
  background: #60a5fa;
}

.cal-day.selected .cal-dot {
  background: var(--accent-text);
}

.cal-agenda-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.cal-agenda-header h3 {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.status-pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  margin-left: 6px;
}

.status-pill.upcoming {
  background: rgba(141, 242, 38, 0.16);
  color: var(--accent);
}

.status-pill.past {
  background: rgba(96, 165, 250, 0.16);
  color: #93c5fd;
}

/* Views Bar (3D) */
.views-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
  padding-bottom: 2px;
}

.view-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 99px;
  white-space: nowrap;
  cursor: pointer;
}

.view-chip:active, .view-chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* Cards List (Boletim) */
.cards-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.consulta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.consulta-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.consulta-date {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 700;
}

.consulta-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 2px;
}

.consulta-clinic {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.teeth-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tooth-tag {
  background: rgba(141, 242, 38, 0.14);
  color: var(--accent);
  border: 1px solid rgba(141, 242, 38, 0.35);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.consulta-notes {
  font-size: 0.9rem;
  color: #e5ecf7;
  line-height: 1.45;
  white-space: pre-wrap;
}

.card-actions {
  display: flex;
  gap: 6px;
}

.delete-small {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 4px;
  cursor: pointer;
}

/* 3D Viewer & Tela Cheia */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 46dvh;
  background: radial-gradient(circle at center, #294371 0%, #0d1524 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s ease;
}

.canvas-wrapper.fullscreen-mode {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 300;
  border-radius: 0;
  border: none;
}

.fs-topbar {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 310;
  pointer-events: none;
}

.fs-topbar > * {
  pointer-events: auto;
}

.fs-title {
  background: rgba(17, 26, 43, 0.8);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid var(--border);
}

.fs-btn {
  background: rgba(26, 40, 66, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.fs-btn.close {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.canvas-wrapper.fullscreen-mode .viewer-controls {
  top: calc(var(--safe-top) + 58px);
}

#three-container {
  width: 100%;
  height: 100%;
  touch-action: none;
}

.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
  text-align: center;
  padding: 20px;
}

.viewer-controls {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.viewer-controls button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(26, 40, 66, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.viewer-controls button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.clipping-box {
  position: absolute;
  bottom: 16px;
  left: 12px;
  right: 12px;
  background: rgba(26, 40, 66, 0.92);
  backdrop-filter: blur(8px);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.clipping-box label {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.clipping-box input {
  width: 100%;
  accent-color: var(--accent);
}

.pin-banner {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 58px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
}

.pins-section {
  margin-top: 16px;
}

.pins-section h3 {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.pins-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Imagens & Raio-X */
.images-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.img-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
}

.img-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: #080c14;
}

.img-card-info {
  padding: 10px;
}

.img-card-type {
  font-size: 0.85rem;
  font-weight: 700;
}

.img-card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Bottom Navigation (5 itens) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(26, 40, 66, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 4px calc(8px + var(--safe-bottom));
  z-index: 50;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

.nav-item.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.2rem;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(9, 14, 24, 0.85);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 540px;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

/* Raio-X em Tela Cheia */
.modal-content.xray-fullscreen {
  max-width: 100vw;
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  border-radius: 0;
  padding-top: calc(var(--safe-top) + 12px);
  display: flex;
  flex-direction: column;
}

.modal-content.xray-fullscreen .xray-stage {
  flex: 1;
  height: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 1.05rem;
}

.close-modal {
  background: var(--surface-2);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

form input, form select, form textarea {
  margin-top: 5px;
}

/* X-Ray Viewer */
.xray-stage {
  width: 100%;
  height: 44dvh;
  background: #060910;
  border-radius: 12px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  touch-action: pinch-zoom pan-x pan-y;
}

.xray-stage img {
  max-width: 100%;
  max-height: 100%;
  transition: filter 0.1s ease, transform 0.2s ease;
}

.xray-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.slider-group input {
  width: 100%;
  accent-color: var(--accent);
}

.xray-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.xray-buttons button {
  flex: 1;
  min-width: 72px;
  padding: 9px 8px;
  font-size: 0.82rem;
}

.xray-meta {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.details-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.92rem;
}

.detail-row {
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.detail-row span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.settings-card h3 {
  font-size: 1rem;
  margin-bottom: 6px;
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.45;
}

/* PIN Screen */
.pin-screen {
  position: fixed;
  inset: 0;
  background: var(--navy-brand);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-box {
  text-align: center;
  width: 280px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 20px 0 28px;
}

.pin-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
}

.pin-dots span.filled {
  background: var(--accent);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.pin-keypad button {
  height: 62px;
  border-radius: 50%;
  background: rgba(17, 26, 43, 0.55);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 700;
}

.pin-keypad button.empty {
  background: transparent;
  border: none;
}

.hidden {
  display: none !important;
}
