:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #17211b;
  --muted: #637066;
  --line: #d8dfd8;
  --accent: #0f766e;
  --accent-strong: #0b5d57;
  --warn: #9a5b00;
  --danger: #a42424;
  --chip: #e7f2ef;
  --shadow: 0 10px 24px rgba(18, 31, 26, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.screen {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.hidden {
  display: none !important;
}

.auth-screen,
#profileView {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: #fff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.login-form,
.other-form {
  display: grid;
  gap: 10px;
}

label,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input {
  height: 46px;
  padding: 0 13px;
}

textarea {
  min-height: 44px;
  max-height: 150px;
  resize: none;
  padding: 11px 12px;
  line-height: 1.35;
}

.login-form button,
.other-form button,
.composer button,
.search-row button,
.quick-filters button,
.summary-actions button,
.status-panel button,
.library-upload-panel button,
.icon-text {
  min-height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  padding: 0 16px;
}

.login-form button:active,
.composer button:active,
.search-row button:active,
.quick-filters button:active,
.summary-actions button:active,
.status-panel button:active,
.library-upload-panel button:active,
.icon-text:active {
  background: var(--accent-strong);
}

.error {
  min-height: 20px;
  color: var(--danger);
}

.version-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.version-label.in-app {
  margin-top: -6px;
  text-align: left;
}

.version-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #b8d8d1;
  border-radius: 8px;
  background: #e7f2ef;
  box-shadow: var(--shadow);
}

.version-banner span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.3;
}

.version-banner-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.version-banner-actions button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 850;
}

#versionReloadBtn {
  background: var(--accent);
  color: #fff;
}

#versionDismissBtn {
  background: #d9e6e2;
  color: var(--accent-strong);
}

.top-copy {
  display: grid;
  gap: 8px;
}

.person-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.person-card {
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 18px;
  font-weight: 900;
}

.app-screen {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  padding-bottom: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: env(safe-area-inset-top);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

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

.header-logo {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid var(--accent);
  background: #fff;
}

.app-header h1 {
  font-size: 24px;
}

.header-actions .icon-text {
  padding: 0 12px;
}

.icon-text.secondary {
  background: #d9e6e2;
  color: var(--accent-strong);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.tab {
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: var(--accent);
  color: white;
}

.tab-panel {
  min-height: 0;
}

#chatTab {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto auto;
  gap: 10px;
  height: calc(100vh - 148px);
}

.case-banner,
.details-card,
.summary-panel,
.status-panel,
.manual-panel,
.library-upload-panel,
.library-list-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.case-banner {
  display: grid;
  gap: 3px;
  padding: 12px;
}

.case-banner span {
  color: var(--muted);
  font-size: 14px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.mode-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 900;
}

.mode-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 0 8px;
}

.message {
  width: fit-content;
  max-width: 92%;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.42;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: #dff0ec;
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
}

.message.system {
  align-self: center;
  background: #fff7e6;
  color: var(--warn);
  font-size: 13px;
}

.message.job-log.user {
  background: #eef3e7;
}

.message.job-log.assistant {
  background: #fbfdf7;
}

.working-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 8px 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 750;
}

.spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 3px solid #d9e6e2;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.source-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
}

.source-list a {
  color: var(--accent-strong);
  overflow-wrap: anywhere;
}

.composer {
  display: grid;
  grid-template-columns: 44px 44px 1fr auto;
  gap: 8px;
  align-items: end;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.file-button,
.voice-button {
  display: grid;
  place-items: center;
  height: 44px;
  border-radius: 8px;
  background: #d9e6e2;
  color: var(--accent-strong);
  font-size: 28px;
  line-height: 1;
  text-transform: none;
}

.voice-button {
  color: var(--accent-strong);
  font-size: 16px;
  padding: 0;
}

.voice-button.active {
  background: var(--accent);
  color: #fff;
}

.voice-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

#fileInput {
  display: none;
}

.voice-panel {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.voice-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--danger);
  animation: voicePulse 1s ease-in-out infinite;
}

@keyframes voicePulse {
  50% {
    opacity: 0.35;
    transform: scale(1.25);
  }
}

.voice-panel button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 900;
}

#voiceCancelBtn {
  background: #f4dddd;
  color: var(--danger);
}

#voiceAcceptBtn {
  background: var(--accent);
  color: #fff;
}

.file-preview {
  min-height: 0;
  color: var(--muted);
  font-size: 13px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.quick-filters {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.quick-filters button {
  background: #d9e6e2;
  color: var(--accent-strong);
}

.quick-filters button.active {
  background: var(--accent);
  color: #fff;
}

.case-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  padding-bottom: 16px;
}

.case-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 8px;
  align-items: stretch;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 10px;
  box-shadow: var(--shadow);
}

.case-item.delete-pending {
  grid-template-columns: 1fr;
}

.case-item-main {
  display: grid;
  gap: 6px;
  width: 100%;
  min-width: 0;
  background: transparent;
  color: var(--ink);
  padding: 2px;
  text-align: left;
}

.case-item-main strong {
  font-size: 15px;
}

.case-delete {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 8px;
  background: #eef4f2;
  color: var(--accent-strong);
}

.case-delete:active {
  background: #d9e6e2;
}

.case-delete svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.delete-confirm {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.delete-confirm span {
  color: var(--danger);
  font-weight: 900;
}

.delete-confirm button {
  min-height: 40px;
  border-radius: 8px;
  font-weight: 850;
  padding: 0 12px;
}

.delete-confirm .secondary-action {
  background: #d9e6e2;
  color: var(--accent-strong);
}

.delete-confirm .danger-action {
  background: var(--danger);
  color: #fff;
}

.case-meta,
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border-radius: 8px;
  background: var(--chip);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 7px;
}

.details-card,
.summary-panel,
.status-panel,
.manual-panel,
.library-upload-panel,
.library-list-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.library-upload-panel p {
  font-size: 14px;
}

.library-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, 1fr);
}

.library-grid select {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
}

#libraryFile {
  height: auto;
  padding: 12px;
}

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

.detail-row {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 10px;
  font-size: inherit;
  line-height: 1.42;
}

.detail-row span:first-child {
  color: var(--muted);
  font-weight: 800;
}

.status-panel {
  grid-template-columns: 1fr;
}

.status-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.status-panel button {
  width: 100%;
}

.status-panel button.active {
  background: var(--accent-strong);
}

.status-panel.status-saved {
  animation: savedPulse 0.75s ease-out;
}

.status-note {
  min-height: 20px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

@keyframes savedPulse {
  0% {
    border-color: var(--accent);
    box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.35);
  }
  100% {
    border-color: var(--line);
    box-shadow: 0 0 0 12px rgba(15, 118, 110, 0);
  }
}

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

.panel-head select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
  padding: 0 10px;
}

#summaryText {
  min-height: 285px;
  max-height: none;
  resize: vertical;
  white-space: pre-wrap;
  font-size: inherit;
  line-height: 1.42;
}

.summary-actions {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 8px;
}

.summary-actions .secondary-action {
  background: #d9e6e2;
  color: var(--accent-strong);
}

.manual-item {
  display: grid;
  gap: 4px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.manual-item a {
  color: var(--accent-strong);
  overflow-wrap: anywhere;
  font-weight: 800;
}

@media (max-width: 520px) {
  .version-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .version-banner-actions button {
    flex: 1;
  }
}

@media (min-width: 760px) {
  .screen {
    padding: 24px;
  }

  #chatTab {
    height: calc(100vh - 170px);
  }

  .detail-row {
    grid-template-columns: 128px 1fr;
  }
}
