:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --border: #e5e5ea;
  --border-soft: #ececef;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #f3a9ba;
  --accent-hover: #ec93a8;
  --accent-soft: #fbe6ec;
  --accent-pale: #fdf5f7;
  --accent-strong: #d6537d;
  --danger: #ff3b30;
  --ok: #34c759;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.12);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Malgun Gothic", sans-serif;
  --font-serif: "Frank Ruhl Libre", Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
}

body.theme-gray {
  --accent: #b0b0b8;
  --accent-hover: #9a9aa4;
  --accent-soft: #eceef0;
  --accent-pale: #f7f8f9;
  --accent-strong: #5b5b66;
}

body.theme-blue {
  --accent: #a9c9e0;
  --accent-hover: #93b8d4;
  --accent-soft: #e6f0f7;
  --accent-pale: #f5fafd;
  --accent-strong: #4a7a9e;
}

body.theme-coral {
  --accent: #f3a58f;
  --accent-hover: #ec8c72;
  --accent-soft: #fce8e1;
  --accent-pale: #fdf6f3;
  --accent-strong: #d1613f;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 13px;
}

.app {
  padding: 10px;
}

.rules-header {
  margin-bottom: 8px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-soft);
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

.tab-panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}

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

select, textarea, input[type="text"], input[type="password"] {
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  background: var(--panel);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus, textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: var(--bg);
}

button:active {
  transform: scale(0.98);
}

button.primary {
  background: var(--accent-pale);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

button.primary:hover {
  background: var(--accent-soft);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mic-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
}

.mic-btn:hover {
  background: var(--accent-soft);
}

.mic-btn svg {
  width: 15px;
  height: 15px;
  fill: var(--muted);
  transition: fill 0.15s ease;
}

.mic-btn.recording {
  border-color: var(--danger);
  background: #ffece9;
}

.mic-btn.recording:hover {
  background: #ffe2dd;
}

.mic-btn.recording svg {
  fill: var(--danger);
}

.rec-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
}

.mic-btn.recording .rec-dot {
  background: var(--ok);
  animation: rec-pulse 1s infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.mic-btn-lg {
  width: 44px;
  height: 44px;
  min-width: 44px;
}

.mic-btn-lg svg {
  width: 19px;
  height: 19px;
}

.bottom-status {
  margin-top: 6px;
  min-height: 0;
}

.bottom-status:empty {
  display: none;
}

.transcript-wrap {
  position: relative;
  /* Establishes a local stacking context so .line-preview-highlight's negative z-index below
     stays scoped to this box (behind the textarea's own painted text) instead of escaping to
     compete with unrelated content elsewhere on the page. */
  z-index: 0;
  margin-bottom: 8px;
}

#transcript-text {
  width: 100%;
  height: 200px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.6;
  border-radius: var(--radius-md);
  margin-bottom: 0;
  /* Transparent so .line-preview-highlight (a sibling positioned behind it) shows through
     around the text -- a native textarea can't have a child overlay painted under its own
     text, so the highlight lives outside it instead and relies on this. */
  background: transparent;
  /* Reserve room on the right so wrapped text never runs under the copy-mark column. */
  padding-right: 30px;
  scrollbar-gutter: stable;
}

#transcript-text::selection {
  background: var(--accent-soft);
}

.line-preview-highlight {
  position: absolute;
  /* A plain (non-positioned) <textarea> always paints above a positioned sibling regardless of
     DOM order or z-index -- except a negative z-index, which paints even earlier than that.
     This is what actually puts the highlight behind the textarea's text instead of over it. */
  z-index: -1;
  left: 1px;
  right: 1px;
  display: none;
  background: var(--accent-soft);
  border-radius: 3px;
  pointer-events: none;
}

.line-copy-overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
}

.line-copy-handle {
  position: absolute;
  left: 1px;
  right: 1px;
  border-radius: 3px;
  background: var(--border);
  cursor: ns-resize;
  touch-action: none;
  transition: background 0.1s ease;
}

.line-copy-handle:hover,
.line-copy-handle.active {
  background: var(--accent);
}

.status-msg {
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.action-sm {
  flex: 0 0 auto;
  padding: 5px 10px;
  font-size: 11px;
}

#settings-btn {
  margin-left: auto;
}

.modality-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.context-menu {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 200;
  min-width: 84px;
}

.context-menu.hidden {
  display: none;
}

.context-menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.context-menu button:hover {
  background: var(--bg);
}

#template-edit-text {
  width: 100%;
  height: 140px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.5;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.check-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.checkpoint-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkpoint-card {
  background: var(--accent-pale);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
}

.checkpoint-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.checkpoint-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.checkpoint-chevron {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.checkpoint-card.expanded .checkpoint-chevron {
  transform: rotate(90deg);
}

.checkpoint-summary {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  margin-top: 3px;
}

.checkpoint-detail {
  display: none;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
}

.checkpoint-card.expanded .checkpoint-detail {
  display: block;
}

.checkpoint-list-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 6px 2px;
}

.rules-desc {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 8px 0;
}

.rule-row {
  display: grid;
  grid-template-columns: 1fr 14px 1fr 44px 22px;
  gap: 5px;
  align-items: center;
  padding: 4px 0;
}

.rule-row input[type="text"] {
  width: 100%;
  padding: 5px 7px;
  font-size: 12px;
}

.rule-arrow {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.rule-active-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.rule-delete-btn {
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.rule-delete-btn:hover {
  background: #ffece9;
  border-color: var(--danger);
}

/* Settings modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 29, 31, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 18px;
  width: min(340px, 100%);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-box-lg {
  width: min(560px, 100%);
}

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

.modal-header h2 {
  font-family: var(--font-serif);
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
}

.modal-close:hover {
  background: var(--bg);
}

.settings-field {
  margin-bottom: 10px;
}

.settings-field label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 4px;
}

.settings-field input,
.settings-field select,
.settings-field textarea {
  width: 100%;
}

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

.settings-note {
  font-size: 10px;
  color: var(--muted);
  margin: -4px 0 10px 0;
  line-height: 1.4;
}

/* AI 문의 (consult) page -- a separate standalone page/app (docs/consult.html) from the main
   SH Rad dictation app, so both can be open side by side at once. Unlike the dictation app
   (kept small and compact to dock beside a PACS viewer), this one fills its own window like a
   normal desktop chat app. */
.consult-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.consult-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  flex: 0 0 auto;
}

.consult-provider-tabs {
  display: flex;
  gap: 4px;
}

.check-tab, .consult-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
}

.check-tab.active, .consult-tab.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent-strong);
}

.consult-conv-select {
  display: none;
  margin-left: auto;
  max-width: 160px;
}

.consult-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.consult-sidebar {
  width: 230px;
  flex: 0 0 230px;
  border-right: 1px solid var(--border-soft);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.consult-conversation-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
}

.consult-conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: left;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  font-size: 12.5px;
  cursor: pointer;
  width: 100%;
}

.consult-conv-item:hover {
  background: var(--bg);
}

.consult-conv-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}

.consult-conv-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.consult-conv-item-delete {
  flex-shrink: 0;
  color: var(--muted);
  padding: 0 2px;
}

.consult-conv-item-delete:hover {
  color: var(--danger);
}

.consult-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 16px;
  gap: 8px;
}

.consult-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

/* Tucked into the header corner, next to the settings gear -- small and out of the way since
   the default per-provider model is right for almost everyone almost all the time. */
.consult-model-select {
  font-size: 10px;
  color: var(--muted);
  border: none;
  background: transparent;
  padding: 2px 4px;
  max-width: 130px;
}

.consult-model-select:focus {
  box-shadow: none;
}

.consult-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 2px;
}

.consult-msg {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.consult-msg.user {
  align-self: flex-end;
  background: var(--accent-pale);
  border: 1px solid var(--accent-soft);
}

.consult-msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
}

.consult-msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.consult-msg-images img {
  max-width: 140px;
  max-height: 140px;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  cursor: zoom-in;
}

.consult-msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.consult-msg-actions button {
  font-size: 10px;
  padding: 3px 8px;
}

.consult-attachments {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.consult-attachment-chip {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.consult-attachment-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
}

.consult-attachment-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.consult-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  flex: 0 0 auto;
}

.consult-input-row textarea {
  flex: 1;
  height: 56px;
  resize: vertical;
  font-size: 13.5px;
}

.ppt-slide-card {
  background: var(--accent-pale);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.ppt-slide-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

.ppt-slide-bullets {
  margin: 0 0 8px 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.6;
}

.ppt-slide-image-slot:empty {
  display: none;
}

.ppt-slide-image {
  display: block;
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  margin-bottom: 8px;
}

@media (max-width: 680px) {
  .consult-sidebar {
    display: none;
  }
  .consult-conv-select {
    display: inline-block;
  }
}
