:root {
  --bg: #0b1021;
  --panel: rgba(20, 30, 64, 0.82);
  --panel-2: rgba(27, 40, 84, 0.86);
  --line: rgba(140, 190, 255, 0.2);
  --accent: #6ef3c5;
  --accent-2: #8ac5ff;
  --danger: #ff7b9c;
  --text: #ebf3ff;
  --muted: #a3bddf;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

body.lightbox-open {
  overflow: hidden;
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 520px at 10% -10%, rgba(110, 243, 197, 0.16), transparent 70%),
    radial-gradient(1100px 460px at 90% -20%, rgba(138, 197, 255, 0.18), transparent 75%),
    linear-gradient(180deg, #091022 0%, #0b1021 55%, #0b132a 100%);
  z-index: -1;
}

.topbar {
  max-width: 1480px;
  margin: 0 auto;
  padding: 26px 24px 16px;
}

.home-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  margin-bottom: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.layout {
  max-width: 1480px;
  margin: 0 auto;
  padding: 10px 24px 24px;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: start;
}

.layout.list-collapsed {
  grid-template-columns: 1fr;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}

.list-panel {
  padding: 14px;
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2,
.detail-card h2,
.detail-card h3 {
  margin: 0;
  font-size: 18px;
}

.search-wrap {
  display: grid;
  gap: 8px;
}

.search-wrap span {
  font-size: 12px;
  color: var(--muted);
}

.search-wrap input,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  border: 1px solid rgba(138, 197, 255, 0.28);
  background: rgba(9, 15, 35, 0.8);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}

.search-wrap input:focus,
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 243, 197, 0.2);
}

.meta {
  margin: 12px 0;
  font-size: 12px;
  color: var(--muted);
}

.cats-list {
  display: grid;
  gap: 8px;
}

.advanced-search {
  margin-top: 8px;
  border-top: 1px solid rgba(138, 197, 255, 0.2);
  padding-top: 10px;
}

.advanced-search-dropdown {
  border: 1px solid rgba(138, 197, 255, 0.2);
  border-radius: 12px;
  background: rgba(16, 24, 52, 0.5);
  padding: 8px 10px;
  margin-bottom: 12px;
}

.advanced-search-dropdown > summary {
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.advanced-search-dropdown > summary::-webkit-details-marker {
  display: none;
}

.advanced-search-dropdown > summary::before {
  content: '+';
  font-size: 14px;
  color: var(--accent-2);
}

.advanced-search-dropdown[open] > summary::before {
  content: '-';
}

.advanced-search h3 {
  margin: 0;
  font-size: 15px;
}

.advanced-search-copy {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.advanced-search-form {
  display: grid;
  gap: 10px;
}

.advanced-search-form label {
  display: grid;
  gap: 6px;
}

.advanced-search-form label span {
  font-size: 12px;
  color: var(--muted);
}

.advanced-checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.advanced-checkbox span {
  margin: 0;
}

.advanced-checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.advanced-actions {
  display: flex;
  gap: 8px;
}

.cat-row {
  width: 100%;
  border: 1px solid rgba(138, 197, 255, 0.24);
  border-radius: 12px;
  background: rgba(20, 30, 64, 0.52);
  color: var(--text);
  text-align: left;
  padding: 10px;
  cursor: pointer;
}

.cat-row:hover {
  border-color: rgba(110, 243, 197, 0.8);
}

.cat-row.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(110, 243, 197, 0.45) inset;
  background: rgba(16, 42, 74, 0.8);
}

.cat-name {
  font-weight: 700;
  font-size: 15px;
}

.cat-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-panel {
  padding: 14px;
}

.detail-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.message {
  min-height: 22px;
  font-size: 13px;
  color: var(--muted);
}

.message.success {
  color: var(--accent);
}

.message.error {
  color: var(--danger);
}

.empty-state {
  border: 1px dashed rgba(138, 197, 255, 0.32);
  border-radius: 12px;
  padding: 22px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.mini-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.card-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.card-value {
  font-size: 15px;
  font-weight: 700;
  word-break: break-word;
}

.detail-card {
  border: 1px solid var(--line);
  background: rgba(17, 27, 59, 0.9);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-actions {
  display: flex;
  gap: 8px;
}

.release-current {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
  margin: 10px 0;
  color: var(--muted);
}

.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.view-item {
  border: 1px solid rgba(138, 197, 255, 0.18);
  border-radius: 10px;
  background: rgba(10, 16, 35, 0.58);
  padding: 10px;
}

.computed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
}

.form-grid label span,
.block-head {
  font-size: 12px;
  color: var(--muted);
}

.form-block {
  grid-column: 1 / -1;
  border: 1px solid rgba(138, 197, 255, 0.18);
  border-radius: 10px;
  padding: 10px;
}

.row-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.fvrcp-dates {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.fvrcp-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.dental-profile-card {
  display: grid;
  gap: 12px;
}

.dental-profile-toolbar label,
.dental-profile-note {
  display: grid;
  gap: 6px;
}

.dental-profile-note span {
  font-size: 12px;
  color: var(--muted);
}

.dental-profile-toolbar input,
.dental-profile-note textarea {
  width: 100%;
  border: 1px solid rgba(138, 197, 255, 0.28);
  background: rgba(9, 15, 35, 0.8);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}

.dental-profile-toolbar input:focus,
.dental-profile-note textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 243, 197, 0.2);
}

.save-message {
  min-height: 0;
  margin: 0;
  font-size: 12px;
}

.photo-upload-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.photo-upload-form label {
  display: grid;
  gap: 6px;
}

.photo-upload-form input[type="text"],
.photo-upload-form input[type="file"] {
  width: 100%;
  border: 1px solid rgba(138, 197, 255, 0.28);
  background: rgba(9, 15, 35, 0.8);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}

.photo-upload-form input[type="text"]:focus,
.photo-upload-form input[type="file"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 243, 197, 0.2);
}

.checkbox-wrap {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.checkbox-wrap input {
  width: auto !important;
  accent-color: var(--accent);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  align-items: start;
}

.photo-card {
  border: 1px solid rgba(138, 197, 255, 0.18);
  border-radius: 10px;
  background: rgba(10, 16, 35, 0.64);
  padding: 8px;
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.photo-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(6, 10, 22, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
  position: relative;
}

.photo-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-preview-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-fallback {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 12px;
}

.photo-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.photo-meta div,
.photo-meta strong {
  overflow-wrap: anywhere;
}

.photo-caption {
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.photo-badge {
  display: inline-block;
  width: fit-content;
  font-size: 11px;
  font-weight: 700;
  color: #08211a;
  background: var(--accent);
  border-radius: 999px;
  padding: 3px 8px;
}

.photo-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.photo-actions .btn-secondary,
.photo-actions .btn-danger {
  flex: 1;
  padding: 7px 10px;
  font-size: 12px;
}

.photo-copy-status {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.photo-copy-status.success {
  color: #6ef3c5;
}

.photo-copy-status.error {
  color: #ffd4e1;
}

.files-card {
  margin-top: 4px;
}

.file-upload-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.file-upload-form label {
  display: grid;
  gap: 6px;
}

.file-upload-form input[type="text"],
.file-upload-form input[type="file"] {
  width: 100%;
  border: 1px solid rgba(138, 197, 255, 0.28);
  background: rgba(9, 15, 35, 0.8);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}

.file-upload-form input[type="text"]:focus,
.file-upload-form input[type="file"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 243, 197, 0.2);
}

.upload-status {
  min-height: 20px;
  font-size: 12px;
  color: var(--muted);
}

.upload-status.uploading {
  color: var(--accent);
}

.upload-status.success {
  color: #6ef3c5;
}

.upload-status.error {
  color: #ffd4e1;
}

.btn-primary.uploading {
  opacity: 0.9;
  cursor: progress;
}

.btn-primary.uploading::after {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 8px;
  border-radius: 50%;
  border: 2px solid rgba(10, 17, 37, 0.2);
  border-top-color: rgba(10, 17, 37, 0.85);
  animation: upload-spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes upload-spin {
  to {
    transform: rotate(360deg);
  }
}

.files-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.file-item {
  display: grid;
  gap: 7px;
}

.file-item-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid rgba(138, 197, 255, 0.22);
  background: rgba(6, 10, 22, 0.9);
  overflow: hidden;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-thumb-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-thumb-icon {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.4px;
  padding: 4px;
}

.file-item-name {
  word-break: break-word;
}

.file-description,
.file-meta {
  color: var(--muted);
  font-size: 12px;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.file-actions .btn-secondary,
.file-actions .btn-danger {
  padding: 7px 10px;
  font-size: 12px;
}

.notes-sections {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.note-column {
  margin-bottom: 0;
}

.medical-note-compose {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.medical-note-compose textarea {
  width: 100%;
  border: 1px solid rgba(138, 197, 255, 0.28);
  background: rgba(9, 15, 35, 0.8);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

.medical-note-compose textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 243, 197, 0.2);
}

.note-row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.medical-note-delete {
  padding: 5px 8px;
  font-size: 11px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, #6ef3c5 0%, #8ac5ff 100%);
  color: #0a1125;
}

.btn-secondary {
  background: rgba(138, 197, 255, 0.12);
  border-color: rgba(138, 197, 255, 0.34);
  color: var(--text);
}

.btn-danger {
  background: rgba(255, 123, 156, 0.14);
  border-color: rgba(255, 123, 156, 0.34);
  color: #ffd4e1;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.history-list.compact {
  max-height: 180px;
  overflow: auto;
}

.history-item {
  border: 1px solid rgba(138, 197, 255, 0.18);
  border-radius: 10px;
  background: rgba(10, 16, 35, 0.64);
  padding: 8px;
  font-size: 13px;
  color: #d4e3f8;
}

.note-text {
  white-space: normal;
  word-break: break-word;
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
}

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(4, 8, 18, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
}

.photo-lightbox img,
.photo-lightbox-image {
  max-width: min(94vw, 1280px);
  max-height: 82vh;
  object-fit: contain;
  border-radius: 10px;
  transition: filter 0.25s ease, transform 0.25s ease;
  filter: blur(0);
}

.photo-lightbox img.is-loading {
  filter: blur(12px);
  transform: scale(1.01);
}

.photo-lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 1px solid rgba(138, 197, 255, 0.44);
  border-radius: 8px;
  background: rgba(12, 20, 45, 0.9);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 10px;
}

.photo-lightbox-caption {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: min(94vw, 900px);
  min-height: 20px;
}

.loading-dots {
  display: inline-flex;
  margin-left: 2px;
}

.loading-dots .dot {
  opacity: 0;
  animation: lightbox-dot-pulse 1.3s infinite;
}

.loading-dots .dot:nth-child(1) {
  animation-delay: 0s;
}

.loading-dots .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes lightbox-dot-pulse {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  40% {
    opacity: 1;
  }
  60% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

.file-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(4, 8, 18, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.file-preview-shell {
  width: min(96vw, 1280px);
  height: min(90vh, 960px);
  background: rgba(10, 16, 35, 0.98);
  border: 1px solid rgba(138, 197, 255, 0.3);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr);
  gap: 10px;
}

.file-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.file-preview-close {
  border: 1px solid rgba(138, 197, 255, 0.44);
  border-radius: 8px;
  background: rgba(12, 20, 45, 0.9);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 10px;
}

.file-preview-meta {
  color: var(--muted);
  font-size: 12px;
}

.file-preview-image {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(138, 197, 255, 0.22);
  border-radius: 10px;
  background: rgba(6, 10, 22, 0.95);
  object-fit: contain;
}

.file-preview-frame {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(138, 197, 255, 0.22);
  border-radius: 10px;
  background: #fff;
}

.file-preview-fallback {
  border: 1px dashed rgba(138, 197, 255, 0.28);
  border-radius: 10px;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .list-panel {
    position: static;
    max-height: none;
  }

  .notes-sections {
    grid-template-columns: 1fr;
  }

  .file-preview-shell {
    width: 96vw;
    height: 88vh;
  }
}

@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    color: black;
    background: white;
  }

  .page-bg {
    display: none !important;
  }

  .topbar {
    border-bottom: 2px solid #333;
    padding-bottom: 12px;
    margin-bottom: 16px;
  }

  .home-link {
    display: none;
  }

  .topbar p {
    display: none;
  }

  .layout {
    display: block;
    max-width: 100%;
    padding: 0;
  }

  .list-panel {
    display: none !important;
  }

  .detail-panel {
    padding: 0;
  }

  .section-actions {
    display: none !important;
  }

  .detail-toolbar {
    display: none !important;
  }

  .photo-lightbox,
  .file-preview-modal {
    display: none !important;
  }

  .cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .detail-card {
    border: 1px solid #ccc;
    background: white;
    color: black;
    page-break-inside: avoid;
    margin-bottom: 16px;
  }

  .detail-card h2,
  .detail-card h3 {
    border-bottom: 2px solid #333;
    padding-bottom: 8px;
    margin-top: 0;
  }

  .mini-card {
    border: 1px solid #ccc;
    background: white;
    color: black;
  }

  .card-label {
    color: #666;
  }

  .view-item {
    border: 1px solid #ddd;
    background: #f9f9f9;
    color: black;
  }

  .computed-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .view-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .history-grid {
    display: block;
  }

  .history-grid .detail-card {
    page-break-inside: avoid;
    margin-bottom: 16px;
  }

  .history-list {
    max-height: none !important;
    overflow: visible !important;
  }

  .history-item {
    border: 1px solid #ddd;
    background: white;
    color: black;
  }

  .release-current {
    grid-template-columns: 1fr;
  }

  .empty-state {
    display: none;
  }

  .hidden {
    display: none !important;
  }

  .message {
    display: none !important;
  }

  @page {
    margin: 0.5in;
  }
}
