* { box-sizing: border-box; }

:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --border: #e2e2e6;
  --text: #1a1a1d;
  --muted: #6c6c73;
  --accent: #1976d2;
  --accent-hover: #1565c0;
  --warn: #c62828;
  --ok: #2e7d32;
  --done-bg: #f0f5f0;
  --header-bg: #1a1a1d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1d;
    --card: #2a2a2e;
    --border: #3a3a40;
    --text: #ececef;
    --muted: #9a9aa0;
    --accent: #64b5f6;
    --accent-hover: #90caf9;
    --warn: #ef5350;
    --ok: #66bb6a;
    --done-bg: #232a23;
    --header-bg: #0e0e10;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--header-bg);
  color: #fff;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 15px;
  margin-right: 4px;
}

.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
}

.filters { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.filters select, .filters button {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: transparent;
  color: #fff;
  cursor: pointer;
}

main { padding: 16px; max-width: 900px; margin: 0 auto; padding-bottom: 120px; }

#auth-gate {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin: 40px auto;
  max-width: 480px;
}
#auth-gate h2 { margin: 0 0 8px 0; }
#auth-gate input {
  width: 100%;
  padding: 10px;
  margin: 12px 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  font: inherit;
}
#auth-gate button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
}

.case {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  position: relative;
}
.case.done {
  background: var(--done-bg);
}

.case-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.case-head .id {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
}
.case-head .meta {
  font-size: 12px;
  color: var(--muted);
}
.case-head .badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--border);
  color: var(--text);
}
.case-head .badge.re-report { background: #f9a825; color: #000; }
.case-head .badge.done { background: var(--ok); color: #fff; }
.case-head label.select {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.case-section {
  margin-bottom: 10px;
}
.case-section label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
  letter-spacing: 0.6px;
}

pre.input, pre.original {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin: 0;
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
}
pre.original { opacity: 0.7; }

textarea.corrected, textarea.notes-input, input.tag-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
textarea.corrected { min-height: 120px; }
textarea.notes-input { min-height: 50px; font-family: inherit; }
input.tag-input { font-family: inherit; }

.case-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.case-actions button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.case-actions button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.case-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.case-actions .save-status {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  align-self: center;
}
.case-actions .save-status.saved { color: var(--ok); }

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.att {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  background: var(--bg);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
  max-width: 160px;
  align-items: center;
}
.att-thumb {
  width: 130px;
  height: 90px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  overflow: hidden;
}
.att-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.att-meta {
  color: var(--muted);
  text-align: center;
  word-break: break-all;
  line-height: 1.3;
}
.att-download {
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
}
.att-download:hover {
  background: var(--accent);
  color: #fff;
}

.export-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 4;
}
.export-bar #export-btn {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
}
.bundle-hint { font-size: 12px; color: var(--muted); }
.bundle-hint.over { color: var(--warn); }

.export-output {
  position: fixed;
  inset: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 10;
  padding: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.export-output-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
#export-close {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
#export-text {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font: 12px ui-monospace, monospace;
  white-space: pre-wrap;
  overflow: auto;
  margin: 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 14px;
}

.error { color: var(--warn); }
.hidden { display: none !important; }
