:root {
  --bg-deep: #081826;
  --bg-mid: #102b3b;
  --panel: #f4f8fb;
  --panel-muted: #e5eef4;
  --ink: #10212d;
  --ink-soft: #486375;
  --brand: #0f8b8d;
  --brand-strong: #0b6f71;
  --danger: #b93c2d;
  --shadow: 0 22px 54px rgba(10, 26, 43, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  color: var(--ink);
  min-height: 100vh;
}

.brand-banner {
  position: relative;
  z-index: 3;
  width: min(1150px, calc(100% - 32px));
  margin: 14px auto 10px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #b8ceda;
  background: rgba(255, 255, 255, 0.84);
  color: #1c3f52;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
}

.site-footer {
  position: relative;
  z-index: 3;
  width: min(1150px, calc(100% - 32px));
  margin: 16px auto 12px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #b8ceda;
  background: rgba(255, 255, 255, 0.84);
  color: #1e4255;
  font-size: 0.86rem;
  text-align: center;
}

h1,
h2,
h3 {
  font-family: 'Sora', sans-serif;
  margin: 0;
}

.auth-body {
  background: radial-gradient(circle at 15% 15%, #1d4d66 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, #0f8b8d 0%, transparent 42%),
    linear-gradient(120deg, var(--bg-deep), var(--bg-mid));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.auth-footer {
  width: min(92vw, 640px);
}

.ambient-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at center, black 40%, transparent 85%);
  pointer-events: none;
}

.auth-shell {
  width: min(92vw, 470px);
  position: relative;
  z-index: 2;
}

.auth-panel {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-radius: 22px;
  padding: 34px;
  box-shadow: var(--shadow);
  animation: rise 420ms ease;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.subcopy {
  color: var(--ink-soft);
  margin: 12px 0 20px;
}

.login-eyebrow {
  text-align: center;
}

.login-title {
  text-align: center;
  color: var(--brand-strong);
  font-weight: 700;
}

.auth-form {
  display: grid;
  gap: 9px;
}

label {
  font-size: 0.88rem;
  color: #254457;
}

input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #bed1dd;
  padding: 12px 14px;
  font-size: 0.96rem;
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.2);
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  margin-top: 8px;
  color: #fff;
  background: linear-gradient(120deg, var(--brand), var(--brand-strong));
  box-shadow: 0 14px 28px rgba(11, 111, 113, 0.24);
}

.btn-ghost {
  background: #e8f2f8;
  color: #1f4658;
}

.hint {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.hint code {
  background: #e8f2f8;
  padding: 2px 6px;
  border-radius: 6px;
}

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.alert-error {
  background: #fce8e5;
  color: var(--danger);
}

.alert-info {
  background: #e6f4ea;
  color: #1f6a3d;
}

.auth-page {
  background: linear-gradient(130deg, #eef4f8, #d4e7f0 32%, #c8e0eb 100%);
  padding-bottom: 20px;
}

.activate-shell {
  margin: 12px auto;
}

.activate-card {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 18px;
  border: 1px solid #bfd3de;
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 12px;
}

.license-status-card {
  border: 1px solid #d0e0e8;
  border-radius: 10px;
  background: #f6fbfe;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.license-challenge {
  display: block;
  white-space: normal;
  word-break: break-all;
  background: #eaf4f9;
  border: 1px solid #c7dbe7;
  border-radius: 8px;
  padding: 8px;
  color: #15465f;
}

.activate-divider {
  border: 0;
  border-top: 1px solid #d9e6ee;
  margin: 2px 0;
}

.flash {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.flash-error {
  background: #fce8e5;
  color: var(--danger);
}

.flash-success {
  background: #e6f4ea;
  color: #1f6a3d;
}

.wide {
  grid-column: 1 / -1;
}

.upload-body {
  padding: 26px;
  background: linear-gradient(130deg, #eef4f8, #d4e7f0 32%, #c8e0eb 100%);
  position: relative;
}

.aurora-bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(400px 280px at 15% 20%, rgba(15, 139, 141, 0.2), transparent),
    radial-gradient(440px 300px at 85% 80%, rgba(45, 98, 148, 0.2), transparent);
  pointer-events: none;
}

.app-header,
.upload-layout {
  position: relative;
  z-index: 2;
}

.app-header {
  max-width: 1150px;
  margin: 0 auto 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

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

.chip {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid #c4dae5;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.85rem;
}

.upload-layout {
  max-width: 1150px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 22px;
}

.drop-panel,
.result-panel > div {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #c2d8e3;
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.drop-panel {
  min-height: 400px;
  padding: 30px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
  border-style: dashed;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.drop-panel.drag-over {
  transform: scale(1.01);
  border-color: var(--brand);
  background: rgba(236, 248, 248, 0.95);
}

.drop-panel h2 {
  font-size: clamp(1.2rem, 2vw, 1.7rem);
}

.drop-kicker {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand-strong);
  margin: 0;
}

.drop-panel p {
  color: var(--ink-soft);
  margin: 0;
}

.result-panel {
  display: grid;
  gap: 18px;
}

.admin-layout {
  max-width: 1150px;
  margin: 0 auto;
  display: grid;
  gap: 22px;
}

.users-layout {
  grid-template-columns: minmax(320px, 0.9fr) minmax(480px, 1.1fr);
  align-items: start;
}

.management-tabs-card {
  padding: 14px 20px;
}

.management-tabs {
  display: flex;
  gap: 10px;
}

.tab-btn {
  border: 1px solid #b7cedb;
  background: #edf5fa;
  color: #264b60;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  border-color: var(--brand-strong);
  background: linear-gradient(120deg, var(--brand), var(--brand-strong));
  color: #fff;
}

.tab-panel.is-hidden {
  display: none;
}

.users-create-card,
.users-list-card {
  height: 100%;
}

.users-admin-form {
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  align-items: end;
}

.users-admin-form .field-group {
  display: grid;
  gap: 6px;
}

.users-admin-form input,
.users-admin-form select {
  max-width: 210px;
  padding: 9px 10px;
  font-size: 0.9rem;
}

.users-admin-form .btn-primary {
  margin-top: 0;
  padding: 9px 12px;
  min-height: 39px;
  align-self: end;
}

.branding-form {
  grid-template-columns: minmax(340px, 2fr) auto;
}

.grow-field {
  display: grid;
  gap: 6px;
}

.backup-form {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  align-items: center;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #21465a;
}

.checkbox-line input[type='checkbox'] {
  width: 16px;
  height: 16px;
}

.backup-import-form {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1.4fr 2.6fr auto;
  gap: 10px;
  align-items: end;
}

.modality-form {
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  margin-bottom: 12px;
}

.modality-form input {
  max-width: 100%;
}

.modalities-table {
  min-width: 980px;
}

.dicom-table {
  min-width: 880px;
}

.dicom-table .btn-small {
  padding: 6px 9px;
  font-size: 0.78rem;
  border-radius: 8px;
}

.dicom-actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 190px;
}

.dicom-actions-cell form {
  margin: 0;
}

.dicom-meta-row td {
  background: #f5fafc;
}

.dicom-meta-pre {
  margin: 0;
  white-space: pre-wrap;
  background: #0f2431;
  color: #d8ecf7;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.82rem;
}

.status-led {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.16);
}

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

.analytics-grid-secondary {
  margin-top: 10px;
}

.analytics-kpi {
  border: 1px solid #c9dce7;
  border-radius: 12px;
  padding: 12px;
  background: #f7fbfd;
  display: grid;
  gap: 6px;
}

.analytics-kpi span {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.analytics-kpi strong {
  font-family: 'Sora', sans-serif;
  font-size: 1.45rem;
  color: #173c52;
}

.analytics-latest {
  margin-top: 12px;
}

.led-gray {
  background: #a6b5bf;
}

.led-green {
  background: #2fa75d;
  box-shadow: 0 0 8px rgba(47, 167, 93, 0.55);
}

.led-red {
  background: #cb3e2f;
  box-shadow: 0 0 8px rgba(203, 62, 47, 0.45);
}

.admin-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #c2d8e3;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.muted {
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.admin-form {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #bed1dd;
  padding: 12px 14px;
  font-size: 0.96rem;
  color: var(--ink);
  background: #fff;
}

textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #bed1dd;
  padding: 12px 14px;
  font-size: 0.96rem;
  font-family: inherit;
  resize: vertical;
  min-height: 90px;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

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

.table-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-bar {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1.6fr 0.6fr;
  gap: 10px;
}

.grow {
  flex: 1;
}

.patient-form {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.patient-form textarea,
.patient-form button {
  grid-column: 1 / -1;
}

.patients-table {
  min-width: 1140px;
}

.history-cell {
  max-width: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

.edit-panel summary {
  list-style: none;
  display: inline-block;
}

.patient-context {
  padding: 14px 18px;
}

.patient-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.edit-panel summary::-webkit-details-marker {
  display: none;
}

.edit-form {
  margin-top: 8px;
  padding: 10px;
  border-radius: 10px;
  background: #f3f8fb;
  border: 1px solid #cfe0ea;
  display: grid;
  gap: 8px;
  min-width: 260px;
}

.patient-row td:last-child {
  min-width: 230px;
}

.patients-table .btn-small {
  padding: 7px 11px;
  font-size: 0.8rem;
  border-radius: 8px;
  margin-right: 6px;
  margin-bottom: 6px;
}

.patients-table .table-actions,
.patients-table .inline-form {
  gap: 8px;
}

.patient-actions {
  align-items: flex-start;
}

.send-status {
  margin-top: 6px;
  max-width: 280px;
  word-break: break-word;
}

.result-thumb-link {
  display: inline-block;
  margin-top: 8px;
  border-radius: 10px;
  border: 1px solid #c9dce7;
  overflow: hidden;
  background: #eef5f9;
}

.result-thumb {
  display: block;
  width: 130px;
  height: 84px;
  object-fit: contain;
  background: #edf4f8;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

.users-table th,
.users-table td {
  border-bottom: 1px solid #d8e5ec;
  text-align: left;
  padding: 10px 8px;
  vertical-align: top;
}

.badge {
  background: #e9f3f8;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.locked {
  color: #a04e00;
}

.ok {
  color: #1f6a3d;
}

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

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input {
  min-width: 180px;
}

.btn-small {
  padding: 9px 12px;
  border-radius: 10px;
  background: #d9e9f2;
  color: #21465a;
}

.btn-danger {
  background: #f6dfdc;
  color: #8f2e24;
}

.preview-card,
.inference-card {
  padding: 18px;
}

.preview-box {
  margin-top: 10px;
  min-height: 260px;
  border-radius: 14px;
  border: 1px solid #cadce6;
  background: #eff5f8;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  overflow: hidden;
}

.preview-box img {
  width: 100%;
  max-height: 560px;
  object-fit: contain;
  background: #eff5f8;
}

.result-box img {
  width: 100%;
  max-height: 680px;
  object-fit: contain;
  cursor: zoom-in;
}

pre {
  margin-top: 10px;
  border-radius: 14px;
  padding: 14px;
  max-height: 260px;
  overflow: auto;
  background: #0f2431;
  color: #d8ecf7;
}

.progress-wrap {
  width: 100%;
  max-width: 400px;
  display: none;
  margin-top: 12px;
}

.progress-wrap.active {
  display: block;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #d3e4ec;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0f8b8d, #266aa8);
  transition: width 260ms ease;
}

#progressText {
  display: block;
  margin-top: 6px;
  color: var(--ink-soft);
}

.meta-grid {
  margin-top: 10px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.meta-item {
  background: #eff5f8;
  border: 1px solid #cfdee8;
  border-radius: 10px;
  padding: 8px 10px;
}

.meta-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #557181;
}

.meta-value {
  margin-top: 3px;
  font-size: 0.9rem;
  color: #173345;
  word-break: break-word;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
}

.viewer[hidden] {
  display: none !important;
}

.viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 17, 26, 0.76);
}

.viewer-panel {
  width: min(96vw, 1280px);
  height: min(92vh, 940px);
  background: #0e2230;
  border: 1px solid #2f4959;
  border-radius: 14px;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.viewer-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid #2f4959;
  background: #133042;
}

.viewer-canvas {
  overflow: auto;
  padding: 18px;
  display: grid;
  place-items: start center;
}

.viewer-canvas img {
  transform-origin: top center;
  max-width: none;
  width: auto;
  height: auto;
}

@keyframes rise {
  from {
    transform: translateY(14px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

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

  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-form {
    grid-template-columns: 1fr;
  }

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

  .users-admin-form input,
  .users-admin-form select {
    max-width: 100%;
  }

  .modality-form {
    grid-template-columns: 1fr;
  }

  .backup-form,
  .backup-import-form {
    grid-template-columns: 1fr;
  }

  .patient-form {
    grid-template-columns: 1fr;
  }

  .patient-grid {
    grid-template-columns: 1fr;
  }

  .table-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .inline-form {
    flex-direction: column;
    width: 100%;
  }

  .upload-body {
    padding: 16px;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .management-tabs {
    width: 100%;
    flex-wrap: wrap;
  }
}
