/* ============================================================
   SPASIBO CLINIC — DESIGN SYSTEM
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  /* Color System */
  --bg:           #F8F9FA;
  --surface:      #FFFFFF;
  --surface-2:    #F3F4F6;
  --text-primary: #1A1A1A;
  --text-secondary: #6B7280;
  --text-muted:   #9CA3AF;
  --border:       #E5E7EB;
  --border-focus: #1A1A1A;
  --accent-red:   #C9A84C;
  --accent-red-hover: #B8922E;
  --accent-red-glow: rgba(201, 168, 76, 0.28);
  --success:      #10B981;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg:    0 20px 60px rgba(0,0,0,0.12), 0 8px 24px rgba(0,0,0,0.06);

  /* Typography */
  --font-body:    'Inter', -apple-system, sans-serif;
  --font-heading: 'DM Sans', -apple-system, sans-serif;

  /* Spacing */
  --radius-sm:    6px;
  --radius-md:    12px;
  --radius-lg:    20px;
  --radius-xl:    28px;

  /* Transitions */
  --ease:         cubic-bezier(0.4, 0, 0.2, 1);
  --transition:   200ms var(--ease);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   VIEWS — ROUTING
   ============================================================ */
.view { display: none; }
.view.active { display: block; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
#login-view {
  display: none;
  min-height: 100vh;
  place-items: center;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
#login-view.active { display: grid; }

#login-view::before {
  content: '';
  position: absolute;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(239,68,68,0.04) 0%, transparent 70%);
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 56px 48px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.5s var(--ease) both;
}

.login-logo {
  text-align: center;
  margin-bottom: 40px;
}

.login-logo-dots {
  display: inline-flex;
  gap: 5px;
  margin-bottom: 16px;
}

.login-logo-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-primary);
  display: block;
}

.login-logo-dots span:last-child { background: var(--accent-red); }

.login-wordmark {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--text-primary);
  text-transform: uppercase;
}

.login-tagline {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  margin-top: 4px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.form-input {
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,26,26,0.06);
}

.form-input.error { border-color: var(--accent-red); }

.login-error {
  font-size: 12px;
  color: var(--accent-red);
  text-align: center;
  min-height: 16px;
  transition: opacity var(--transition);
}

.btn-primary {
  padding: 14px 24px;
  background: var(--text-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  margin-top: 8px;
}

.btn-primary:hover {
  background: #333;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active { transform: translateY(0); }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(248, 249, 250, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 40px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.header-dots {
  display: flex;
  gap: 4px;
}

.header-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-primary);
  display: block;
}

.header-dots span:last-child { background: var(--accent-red); }

.header-wordmark {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.28em;
  color: var(--text-primary);
  text-transform: uppercase;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-date {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.btn-logout {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all var(--transition);
}

.btn-logout:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

/* ============================================================
   WORKSPACE LAYOUT
   ============================================================ */
#workspace-view.active { display: flex; flex-direction: column; }

.workspace-main {
  flex: 1;
  padding: 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   SECTION CARDS
   ============================================================ */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.section-card:hover { box-shadow: var(--shadow-md); }

.section-title {
  font-family: var(--font-heading);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ============================================================
   INPUT PANEL
   ============================================================ */
.input-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.textarea-wrapper { position: relative; }

.clinical-textarea {
  width: 100%;
  min-height: 220px;
  padding: 18px 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg);
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.clinical-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,26,26,0.05);
}

.clinical-textarea::placeholder { color: var(--text-muted); }

.textarea-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.textarea-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* Voice Button */
.voice-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.voice-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-red);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 12px var(--accent-red-glow);
  position: relative;
  flex-shrink: 0;
}

.voice-btn:hover {
  background: var(--accent-red-hover);
  transform: scale(1.06);
  box-shadow: 0 4px 20px var(--accent-red-glow);
}

.voice-btn:active { transform: scale(0.97); }

.voice-btn svg { width: 20px; height: 20px; fill: #fff; pointer-events: none; }

.voice-btn.recording {
  background: var(--accent-red);
  animation: pulse-ring 1.5s ease infinite;
}

.voice-btn.recording::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent-red);
  animation: pulse-expand 1.5s ease infinite;
}

.voice-status {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.voice-status.active { color: var(--accent-red); font-weight: 500; }

/* Submit Button */
.submit-area { margin-top: 8px; }

.btn-generate {
  width: 100%;
  padding: 16px 24px;
  background: var(--text-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-generate:hover {
  background: #333;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-generate:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-generate svg { width: 16px; height: 16px; fill: #fff; }

/* Loading State */
.loading-indicator {
  display: none;
  width: 100%;
  padding: 16px 24px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: 0.04em;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.loading-indicator.active { display: flex; }

.loader-dots {
  display: flex;
  gap: 4px;
}

.loader-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: dot-bounce 1.2s ease infinite;
}

.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================================
   ODONTOGRAM
   ============================================================ */
.odontogram-panel { overflow: visible; }

.odontogram-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.odonto-row {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.odonto-arch-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  text-align: center;
  padding: 4px 0;
}

.odonto-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.odonto-midline {
  width: 2px;
  height: 100%;
  background: var(--border);
  flex-shrink: 0;
}

.tooth-cell {
  position: relative;
  width: 36px;
  height: 54px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: all var(--transition);
  user-select: none;
}

.tooth-cell:hover {
  border-color: var(--text-primary);
  background: var(--surface-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.tooth-cell.has-status {
  border-color: var(--text-primary);
  background: var(--surface-2);
}

.tooth-cell.selected {
  border-color: var(--text-primary);
  background: var(--text-primary);
}

.tooth-cell.selected .tooth-number { color: #fff; }

.tooth-number {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1;
}

.tooth-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tooth-icon svg { width: 100%; height: 100%; }

.tooth-status-badge {
  font-size: 7.5px;
  font-weight: 700;
  color: var(--accent-red);
  line-height: 1;
  min-height: 10px;
  text-align: center;
  max-width: 34px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}

/* Status dropdown */
.tooth-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  min-width: 240px;
  z-index: 1000;
  animation: fadeIn 0.15s var(--ease) both;
}

.tooth-dropdown.below {
  bottom: auto;
  top: calc(100% + 8px);
}

.tooth-dropdown-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.status-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.status-tag {
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}

.status-tag:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.status-tag.active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: #fff;
}

.status-tag[data-status="C"].active  { background: #F59E0B; border-color: #F59E0B; }
.status-tag[data-status="P"].active  { background: #EF4444; border-color: #EF4444; }
.status-tag[data-status="Pt"].active { background: #8B5CF6; border-color: #8B5CF6; }
.status-tag[data-status="R"].active  { background: #10B981; border-color: #10B981; }
.status-tag[data-status="X"].active  { background: #6B7280; border-color: #6B7280; }
.status-tag[data-status="Cr"].active { background: #3B82F6; border-color: #3B82F6; }
.status-tag[data-status="M"].active  { background: #1A1A1A; border-color: #1A1A1A; }

.tooth-note-input {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  resize: none;
  transition: border-color var(--transition);
  height: 56px;
}

.tooth-note-input:focus { border-color: var(--border-focus); }

.tooth-note-input::placeholder { color: var(--text-muted); }

.dropdown-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.btn-tooth-clear {
  font-size: 11px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  transition: color var(--transition);
}

.btn-tooth-clear:hover { color: var(--accent-red); }

.btn-tooth-done {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  transition: color var(--transition);
}

.btn-tooth-done:hover { color: var(--success); }

/* Odontogram legend */
.odonto-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============================================================
   MODAL — PDF PREVIEW
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.6);
  backdrop-filter: blur(6px);
  z-index: 2000;
  place-items: center;
  padding: 24px;
  animation: fadeIn 0.2s var(--ease);
}

.modal-overlay.active { display: grid; }

.modal-panel {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s var(--ease) both;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 18px;
  transition: all var(--transition);
  line-height: 1;
}

.modal-close:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: var(--surface-2);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

/* PDF Preview inside modal */
.pdf-preview-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #525659;
  height: 480px;
}

.pdf-preview-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.modal-footer {
  display: flex;
  gap: 12px;
  padding: 20px 32px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-download {
  flex: 1;
  padding: 13px 24px;
  background: var(--text-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-download:hover {
  background: #333;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-edit {
  padding: 13px 24px;
  background: none;
  color: var(--text-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: all var(--transition);
}

.btn-edit:hover {
  border-color: var(--text-primary);
  background: var(--surface-2);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  bottom: 32px;
  right: 32px;
  padding: 14px 20px;
  background: var(--text-primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: slideRight 0.3s var(--ease) both;
  max-width: 320px;
}

.toast.error { background: var(--accent-red); }
.toast.success { background: var(--success); }

.toast.fade-out { animation: fadeOut 0.3s var(--ease) both; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateX(10px); }
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201,168,76,0.55); }
  50% { box-shadow: 0 0 0 10px rgba(201,168,76,0); }
}

@keyframes pulse-expand {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .workspace-main { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .workspace-main { padding: 20px 16px; gap: 16px; }
  .app-header { padding: 0 20px; }
  .section-card { padding: 20px; }
  .login-card { padding: 40px 28px; }
  .modal-header, .modal-body, .modal-footer { padding-left: 20px; padding-right: 20px; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
