:root {
  --bg: #0c1118;
  --surface: #141b26;
  --border: #243044;
  --text: #e8edf5;
  --muted: #8b9bb3;
  --accent: #3d9cf0;
  --accent-dim: #2563a8;
  --success: #34c759;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2840 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.wrap {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 2rem 1.25rem 4rem;
  box-sizing: border-box;
}

header.site {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0 2rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.1rem;
  color: var(--text);
}

.brand span {
  color: var(--accent);
}

.header-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-user {
  font-size: 0.9rem;
  color: var(--muted);
}

.btn-header {
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
}

h1 {
  font-size: 2rem;
  font-weight: 650;
  margin: 0 0 0.5rem;
}

.lead {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 42rem;
  margin: 0 0 2rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.card p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(180deg, #4aa8ff, var(--accent));
  color: #061018;
}

.btn-primary:hover {
  filter: brightness(1.05);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  border-color: var(--accent-dim);
  text-decoration: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.flash {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.flash-info {
  background: #1a2a3a;
  border: 1px solid var(--border);
}

.flash-success {
  background: #132a1f;
  border: 1px solid #1f4d33;
  color: #b8f0cd;
}

.flash-warning {
  background: #2a2618;
  border: 1px solid #5c4d1f;
  color: #f5e6a8;
}

.flash-danger {
  background: #2a1818;
  border: 1px solid #5c1f1f;
  color: #f5b8b8;
}

form.stacked label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

form.stacked input {
  width: 100%;
  max-width: 22rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0f16;
  color: var(--text);
  margin-bottom: 1rem;
}

form.stacked button {
  margin-top: 0.25rem;
}

.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #1a2a38;
  color: var(--muted);
  border: 1px solid var(--border);
}

footer.site {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
}

.case-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.case-table th,
.case-table td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.case-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.case-table .muted {
  color: var(--muted);
  white-space: nowrap;
}

.btn-sm {
  padding: 0.35rem 0.55rem;
  font-size: 0.85rem;
}

p.muted {
  color: var(--muted);
}

.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;
}

.doc-upload-card.card:hover {
  transform: none;
}

.doc-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 1.5rem 1.25rem;
  text-align: center;
  cursor: pointer;
  background: #0a0f16;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.doc-drop-zone:hover,
.doc-drop-zone:focus {
  border-color: var(--accent-dim);
  outline: none;
}

.doc-drop-zone--drag {
  border-color: var(--accent);
  background: #101820;
}

.doc-drop-zone--ready {
  border-color: var(--success);
  background: rgba(52, 199, 89, 0.08);
}

.doc-drop-zone__prompt {
  margin: 0;
  font-weight: 600;
}

.doc-file-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  text-align: left;
  font-size: 0.9rem;
  color: var(--muted);
  max-height: 10rem;
  overflow-y: auto;
}

.doc-file-list li {
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--border);
}

.doc-file-list li:last-child {
  border-bottom: none;
}

.upload-actions {
  align-items: center;
  gap: 0.75rem 1rem;
}

.upload-inline-success {
  font-size: 0.95rem;
  color: var(--success);
  font-weight: 600;
}

.doc-row {
  cursor: pointer;
}

.doc-row:hover {
  background: rgba(61, 156, 240, 0.06);
}

.doc-table .doc-delete-form {
  margin: 0;
}

.case-row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.case-row-actions__form {
  margin: 0;
  display: inline;
}

.workspace-current-case {
  margin-top: 1rem;
}

.workspace-page-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin: 0 0 0.25rem;
}

.workspace-page-title__text {
  font-size: inherit;
  font-weight: inherit;
}

.ollama-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.ollama-indicator__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}

.ollama-indicator--ready .ollama-indicator__dot {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.25);
}

.ollama-indicator--ready {
  border-color: rgba(52, 199, 89, 0.45);
  color: #b8e6c8;
}

.ollama-indicator--loading .ollama-indicator__dot {
  background: #f0ad4e;
  animation: ollama-pulse 1.2s ease-in-out infinite;
}

.ollama-indicator--loading {
  border-color: rgba(240, 173, 78, 0.5);
  color: #e8c99a;
}

.ollama-indicator--missing .ollama-indicator__dot {
  background: #e8a838;
}

.ollama-indicator--missing {
  border-color: rgba(232, 168, 56, 0.45);
  color: #e8c99a;
}

.ollama-indicator--offline .ollama-indicator__dot {
  background: #c44;
}

.ollama-indicator--offline {
  border-color: rgba(204, 68, 68, 0.45);
  color: #e8a0a0;
}

@keyframes ollama-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.workspace-below-case {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 3fr);
  gap: 1.25rem;
  align-items: stretch;
  margin-top: 1.25rem;
}

.workspace-medchat {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: min(70vh, 560px);
  max-height: min(70vh, 560px);
}

.medchat-title {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.medchat-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0.75rem;
  min-width: 0;
}

.medchat-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0.15rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: stretch;
  scrollbar-gutter: stable;
}

.medchat-empty {
  margin: 0.5rem 0;
  text-align: left;
  font-size: 0.95rem;
}

.medchat-turn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  max-width: 100%;
}

.medchat-turn--user,
.medchat-turn--assistant {
  align-items: flex-start;
}

.medchat-bubble {
  width: 100%;
  max-width: min(100%, 48rem);
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
  align-self: flex-start;
}

.medchat-bubble--user {
  background: rgba(61, 156, 240, 0.1);
  border: 1px solid rgba(61, 156, 240, 0.25);
  color: var(--text);
  border-radius: 0.65rem;
  border-left: 3px solid var(--accent);
}

.medchat-bubble--assistant {
  background: transparent;
  border: none;
  border-left: 2px solid var(--border);
  color: var(--text);
  border-radius: 0;
  padding-left: 0.75rem;
}

.medchat-form {
  flex-shrink: 0;
  margin: 0;
  margin-top: auto;
}

.medchat-composer {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.55rem 0.55rem 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 1.35rem;
  background: #0d131c;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.medchat-composer:focus-within {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 1px rgba(61, 156, 240, 0.2);
}

.medchat-composer__input {
  flex: 1;
  min-height: 44px;
  max-height: 200px;
  padding: 0.5rem 0.25rem 0.5rem 0;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
}

.medchat-composer__input::placeholder {
  color: var(--muted);
}

.medchat-composer__input:focus {
  outline: none;
}

.medchat-composer__send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #061018;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.medchat-composer__send:hover {
  filter: brightness(1.08);
}

.medchat-composer__send:active {
  transform: scale(0.96);
}

.medchat-composer__send-icon {
  display: block;
  margin-left: 2px;
}

.workspace-docs-combined__subhead {
  margin: 1.5rem 0 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

@media (max-width: 768px) {
  .workspace-below-case {
    grid-template-columns: 1fr;
  }
}
