@import url('https://cdnjs.cloudflare.com/ajax/libs/@tabler/icons-webfont/3.1.0/tabler-icons.min.css');

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e4e9;
  --border-strong: #cfd3da;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --accent: #2563eb;
  --accent-bg: #eaf1fd;
  --success: #16794f;
  --success-bg: #e6f5ee;
  --warning: #92651b;
  --warning-bg: #fdf2e1;
  --danger: #b3261e;
  --danger-bg: #fdeceb;
  --gray-bg: #eef0f3;
  --gray-text: #4b5563;
  --radius-md: 8px;
  --radius-lg: 12px;
  --sidebar-width: 220px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  padding: 0 12px 1.5rem;
}

.brand i { font-size: 22px; color: var(--accent); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  text-align: left;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
}

.nav-link i { font-size: 18px; }

.nav-link:hover { background: var(--gray-bg); color: var(--text); }

.nav-link.active {
  background: var(--accent-bg);
  color: var(--accent);
}

.nav-link-sub {
  font-size: 13px;
  padding: 8px 12px 8px 20px;
  color: var(--text-tertiary);
}

.nav-link-sub i { font-size: 15px; }

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

.nav-section-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  text-align: left;
  font-size: 13px;
  color: var(--text-tertiary);
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
}

.nav-section-toggle:hover { background: var(--gray-bg); color: var(--text-secondary); }
.nav-section-toggle i { font-size: 15px; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 12px 0;
  border-top: 1px solid var(--border);
}

.sidebar-footer-label {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

/* Content */

.content {
  flex: 1;
  padding: 2rem;
  max-width: 1100px;
}

h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 18px; font-weight: 600; margin: 0; }
h3 { font-size: 15px; font-weight: 600; margin: 0; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 12px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

/* Buttons */

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.btn:hover { background: var(--gray-bg); }

.btn.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn.btn-primary:hover { background: #1d4ed8; }

.btn.btn-danger {
  color: var(--danger);
  border-color: #f3c9c6;
}

.btn.btn-danger:hover { background: var(--danger-bg); }

.btn.btn-sm { padding: 6px 10px; font-size: 13px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
}

.icon-btn:hover { background: var(--gray-bg); color: var(--text); }

.link-toggle {
  border: none;
  background: none;
  padding: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
}

.link-toggle i { font-size: 16px; }

/* Stat cards */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.stat-label { font-size: 12px; color: var(--text-secondary); margin: 0 0 4px; }
.stat-value { font-size: 24px; font-weight: 600; margin: 0; }
.stat-value.danger { color: var(--danger); }

/* Filters */

.filters-row {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filters-row input[type="text"],
.filters-row select {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
}

.filters-row input[type="text"] { flex: 1; min-width: 180px; }
.filters-row select { width: 170px; }

/* Table / list */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.case-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.case-row:last-child { border-bottom: none; }
.case-row:hover { background: var(--gray-bg); }

.case-row .main { flex: 1; min-width: 0; }
.case-row .main p { margin: 0; }
.case-row .main .name { font-weight: 500; font-size: 14px; }
.case-row .main .meta { font-size: 13px; color: var(--text-secondary); }

.case-row .file-count {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 36px;
}

.empty-state {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: var(--radius-md);
  white-space: nowrap;
}

.badge-gray { background: var(--gray-bg); color: var(--gray-text); }
.badge-blue { background: var(--accent-bg); color: var(--accent); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-teal { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--danger-bg); color: var(--danger); }

/* Modal */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal.modal-wide { max-width: 640px; }

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

/* Forms */

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.field textarea { resize: vertical; min-height: 70px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 1.5rem;
}

.form-actions .btn { flex: 1; justify-content: center; }

/* Detail table */

.detail-table { width: 100%; font-size: 13px; margin-bottom: 1rem; }
.detail-table td { padding: 6px 0; vertical-align: middle; }
.detail-table td:first-child { color: var(--text-secondary); width: 40%; }
.detail-table td:last-child { text-align: right; }

/* Files */

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-bottom: 1rem;
}

.file-tile {
  aspect-ratio: 1;
  background: var(--gray-bg);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.file-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-tile .file-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 9px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tile i { font-size: 22px; color: var(--text-tertiary); }

.file-tile .remove-file {
  position: absolute;
  top: 2px; right: 2px;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  z-index: 2;
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: background 0.1s, border-color 0.1s;
}

.dropzone:hover, .dropzone.dragover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.dropzone i { font-size: 26px; color: var(--text-tertiary); }
.dropzone p { margin: 6px 0 0; font-size: 13px; color: var(--text-secondary); }
.dropzone .hint { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* Notes box */

.notes-box {
  background: var(--gray-bg);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 1rem;
  white-space: pre-wrap;
}

/* Toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.toast.success i { color: #6ee7b7; }
.toast.error i { color: #fca5a5; }

/* Misc */

.text-secondary { color: var(--text-secondary); }
.mb-0 { margin-bottom: 0; }

.status-select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: inherit;
}

/* Audit log */

.audit-entry {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.audit-entry:last-child { border-bottom: none; }

.audit-entry-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.audit-summary {
  margin: 0 0 4px;
  font-size: 14px;
}

.audit-changes {
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--gray-bg);
  border-radius: var(--radius-md);
  font-size: 12px;
}

.audit-change-row { padding: 2px 0; }

.audit-user {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.tooth-btn.locked {
  opacity: 0.25;
  cursor: not-allowed;
  border-style: dashed;
}

.tooth-btn.at-limit {
  opacity: 0.35;
  cursor: not-allowed;
}

.tooth-role-badge {
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

/* Pontic / abutment step */

.pontic-step {
  margin: 8px 0 4px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.pontic-step-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pontic-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pontic-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 8px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  min-width: 40px;
}

.pontic-toggle:hover { border-color: var(--accent); }

.pontic-fdi {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.pontic-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1.4;
}

.pontic-a { background: var(--accent-bg); color: var(--accent); }
.pontic-toggle.pontic-a { border-color: var(--accent); }

.pontic-p { background: var(--warning-bg); color: var(--warning); }
.pontic-toggle.pontic-p { border-color: var(--warning); }

/* Inline chart toggle per row */

.row-chart-toggle {
  font-size: 11px;
  padding: 4px 8px;
  color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid #c3d8fb;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  font-weight: 500;
}

.row-chart-toggle:hover { background: #d6e8fd; }

.row-chart-panel {
  margin-top: 6px;
  margin-bottom: 2px;
}

.dentist-option:last-child { border-bottom: none !important; }
.dentist-option:hover { background: var(--gray-bg); }

/* Sort buttons */
.sort-btn {
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.sort-btn:hover { background: var(--gray-bg); color: var(--text); }

/* Tooth chart */

.tooth-chart-wrap {
  background: var(--gray-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 10px 8px;
  margin-bottom: 8px;
  user-select: none;
}

.tooth-chart-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
  padding: 0 2px;
}

.tooth-chart-arch {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-bottom: 4px;
}

.tooth-chart-midline {
  border-top: 1.5px dashed var(--border-strong);
  margin: 4px 0;
}

.tooth-chart-labels {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-bottom: 2px;
}

.tooth-label {
  width: 26px;
  text-align: center;
  font-size: 9px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.tooth-btn {
  width: 26px;
  height: 28px;
  border-radius: 5px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.08s, border-color 0.08s, color 0.08s;
  font-family: inherit;
  padding: 0;
  line-height: 1;
}

.tooth-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

.tooth-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.tooth-btn.selected:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.tooth-chart-selection {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  min-height: 18px;
  padding: 0 2px;
}

.tooth-chart-selection strong {
  color: var(--accent);
}

.tooth-chart-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

@media (max-width: 768px) {
  .sidebar {
    width: 64px;
    padding: 1rem 0.5rem;
    align-items: center;
  }
  .brand span { display: none; }
  .nav-link span, .nav-link { justify-content: center; }
  .nav-link i { font-size: 20px; }
  .content { padding: 1rem; }
  .field-row { grid-template-columns: 1fr; }
}
