* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
  background: #1a1a1a;
  color: #e0e0e0;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebars */
aside {
  width: 230px;
  min-width: 180px;
  background: #222;
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
#sidebar-right {
  width: 260px;
  border-right: none;
  border-left: 1px solid #333;
}

aside section {
  padding: 8px 10px;
  border-bottom: 1px solid #333;
}

aside h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
aside h3::before {
  content: "\25BC";
  font-size: 8px;
  transition: transform 0.15s;
}
aside section.collapsed h3::before {
  transform: rotate(-90deg);
}
aside section.collapsed > *:not(h3) {
  display: none;
}

aside ul {
  list-style: none;
  max-height: 40vh;
  overflow-y: auto;
}

aside li {
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
aside li:hover { background: #333; }
aside li.active { background: #3a6ea5; color: #fff; }
aside li.has-annotation { border-left: 3px solid #39FF14; }

/* Canvas area */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 12px;
  font-size: 12px;
  color: #aaa;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
}

#image-info {
  min-width: 0;
  flex: 1;
}

#viewer-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#fit-view-btn {
  padding: 4px 10px;
  border: 1px solid #46617b;
  border-radius: 4px;
  background: #233342;
  color: #dce7f1;
  cursor: pointer;
  font-size: 12px;
}

#fit-view-btn:hover {
  background: #2d4357;
}

#zoom-display {
  min-width: 56px;
  text-align: right;
  color: #9fc1df;
  font-variant-numeric: tabular-nums;
}

#canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #111;
}

#main-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#status-bar {
  padding: 4px 12px;
  font-size: 12px;
  color: #aaa;
  background: #1e1e1e;
  border-top: 1px solid #333;
}

/* Class buttons */
#current-class {
  font-size: 16px;
  font-weight: bold;
  padding: 6px;
  margin-bottom: 6px;
  text-align: center;
  border-radius: 4px;
}

#user-box {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

#user-id-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #181818;
  color: #e0e0e0;
  font-size: 12px;
}

#user-id-input:focus {
  outline: none;
  border-color: #3a6ea5;
}

#user-id-save {
  padding: 6px 10px;
  border: 1px solid #3a6ea5;
  border-radius: 4px;
  background: #274766;
  color: #f4f8fb;
  cursor: pointer;
  font-size: 12px;
}

#user-id-save:hover {
  background: #32597f;
}

#current-user-display {
  font-size: 11px;
  color: #8fa9c0;
  word-break: break-all;
}

.class-btn {
  display: block;
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 3px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: #2a2a2a;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
}
.class-btn:hover { background: #3a3a3a; }
.class-btn.active { border-color: #fff; }

.class-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* Label list */
#label-list {
  max-height: 30vh;
}
#label-list li {
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#label-list li.selected {
  background: #3a6ea5;
  color: #fff;
}
#label-list li .delete-btn {
  background: none;
  border: none;
  color: #e53935;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}

#selection-summary {
  font-size: 11px;
  color: #d7e6f4;
  line-height: 1.5;
  margin-bottom: 6px;
}

#selection-note {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: #8ea0b1;
}

#simplify-label-btn {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #46617b;
  border-radius: 4px;
  background: #233342;
  color: #dce7f1;
  cursor: pointer;
  font-size: 12px;
}

#simplify-label-btn:hover:not(:disabled) {
  background: #2d4357;
}

#simplify-label-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Upload area */
#upload-area {
  padding: 6px 0;
  border-top: 1px solid #333;
  margin-top: 6px;
}
#upload-btn {
  display: block;
  width: 100%;
  padding: 6px;
  background: #2a4a2a;
  color: #8f8;
  border: 1px dashed #4a4;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
#upload-btn:hover { background: #3a5a3a; }
#drop-zone {
  text-align: center;
  padding: 8px;
  margin-top: 4px;
  border: 1px dashed #444;
  border-radius: 4px;
  color: #666;
  font-size: 11px;
  transition: background 0.2s, border-color 0.2s;
}
#drop-zone.drag-over {
  background: #2a3a2a;
  border-color: #4a4;
  color: #8f8;
}

.shortcut-help {
  font-size: 11px;
  line-height: 1.8;
  color: #999;
}
kbd {
  background: #333;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

/* Patient Info Form */
#patient-info-section {
  max-height: 50vh;
  overflow-y: auto;
}
#patient-info-form .form-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
#patient-info-form label {
  font-size: 11px;
  color: #999;
  min-width: 52px;
  flex-shrink: 0;
}
#patient-info-form input,
#patient-info-form select,
#patient-info-form textarea {
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid #444;
  border-radius: 3px;
  background: #181818;
  color: #e0e0e0;
  font-size: 11px;
}
#patient-info-form input:focus,
#patient-info-form select:focus,
#patient-info-form textarea:focus {
  outline: none;
  border-color: #3a6ea5;
}
#patient-info-form textarea {
  resize: vertical;
}
#pi-save-btn {
  display: block;
  width: 100%;
  padding: 5px;
  margin-top: 6px;
  background: #274766;
  color: #f4f8fb;
  border: 1px solid #3a6ea5;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
#pi-save-btn:hover {
  background: #32597f;
}

#image-meta-section .meta-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#image-meta-section .meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid #333;
  border-radius: 4px;
  background: #181818;
}

#image-meta-section .meta-label {
  font-size: 11px;
  color: #8fa9c0;
}

#image-meta-section .meta-value {
  font-size: 12px;
  color: #f2f6fa;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#image-meta-note {
  margin-top: 6px;
  font-size: 11px;
  color: #7f8b96;
  line-height: 1.5;
}

#new-patient-btn {
  display: block;
  width: 100%;
  padding: 5px;
  margin-bottom: 6px;
  background: #2a4a2a;
  color: #8f8;
  border: 1px dashed #4a4;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
#new-patient-btn:hover {
  background: #3a5a3a;
}

/* Patient group tree view */
.patient-group-header {
    font-size: 12px;
    font-weight: bold;
    color: #9fc1df;
    padding: 6px 8px 2px;
    cursor: pointer;
    user-select: none;
}
.patient-group-header::before {
    content: "\25BE ";
    font-size: 10px;
}
.patient-group-header.collapsed::before {
    content: "\25B8 ";
}
.patient-group-header:hover {
    background: #2a2a2a;
}
.patient-region-item {
    padding-left: 24px !important;
    font-size: 12px;
}
.patient-region-item.hidden {
    display: none;
}
