* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
}

/* ───────── Login ───────── */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #004e92 0%, #000428 100%);
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 400px;
}

.login-card h1 {
  margin: 0 0 8px;
  color: #004e92;
}

.login-card p {
  color: #666;
  margin: 0 0 24px;
}

.login-card input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 16px;
  font-family: ui-monospace, monospace;
}

.login-card button {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  background: #004e92;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.login-card button:hover { background: #003a6e; }

.error {
  color: #c62828;
  margin-top: 12px;
  font-size: 14px;
  min-height: 20px;
}

/* ───────── Workspace layout ───────── */

#workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: white;
  border-bottom: 1px solid #e5e5e7;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  flex: 1;
}

.counts { display: flex; gap: 6px; }

.view-toggle {
  display: flex;
  gap: 4px;
  background: #f0f0f0;
  border-radius: 8px;
  padding: 2px;
}

.view-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #555;
}

.view-btn.active {
  background: white;
  color: #004e92;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.master-prompt-panel {
  background: #fffaf2;
  border-bottom: 2px solid #b76e00;
  padding: 16px 20px;
}

.mp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.mp-header h3 {
  margin: 0;
  font-size: 14px;
  color: #333;
}

.master-prompt-panel label {
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  display: block;
  margin: 8px 0 4px;
}

.master-prompt-panel textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  resize: vertical;
}

.mp-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.topic-item {
  display: block;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 2px solid transparent;
}

.topic-item:hover { background: #f0f0f0; }
.topic-item.active { background: #e8f0f8; border-color: #004e92; }

.topic-item-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

.topic-item-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: #888;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.topic-grid-card {
  background: #fafafa;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid #e5e5e7;
}

.topic-grid-card:hover { border-color: #004e92; }

.topic-grid-card img {
  width: 100%;
  height: 140px;
  object-fit: contain;
  background: white;
  display: block;
}

.topic-grid-card-body {
  padding: 8px;
}

.topic-grid-card-title {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-grid-draft {
  position: relative;
}
.topic-grid-draft::before {
  content: "Draft";
  position: absolute;
  top: 4px;
  left: 4px;
  background: #b76e00;
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  z-index: 2;
}
.topic-grid-draft img {
  opacity: 0.3;
}

.suggestion-card {
  background: #fff8f0;
  border: 1px solid #b76e00;
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
}
.suggestion-card h4 { margin: 0 0 6px; font-size: 14px; }
.suggestion-card .rationale {
  font-size: 12px;
  color: #666;
  font-style: italic;
  margin: 4px 0 8px;
}
.suggestion-card textarea {
  width: 100%;
  padding: 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  resize: vertical;
  margin-bottom: 6px;
}
.suggestion-card input[type="text"] {
  width: 100%;
  padding: 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 6px;
}
.suggestion-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.split-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1;
  min-height: 0;
}

@media (max-width: 900px) {
  .split-layout { grid-template-columns: 240px 1fr; }
}

.left-panel {
  background: white;
  border-right: 1px solid #e5e5e7;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.right-panel {
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
}

/* ───────── Badges & buttons ───────── */

.badge {
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.pending  { background: #fff4e5; color: #b76e00; }
.badge.approved, .badge.pass, .badge.passed { background: #e6f7ed; color: #1a7a3e; }
.badge.rejected, .badge.fail, .badge.failed { background: #fdeaea; color: #c62828; }
.badge.review { background: #fff4e5; color: #b76e00; }

.btn-ghost {
  background: none;
  border: 1px solid #ddd;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #333;
}
.btn-ghost:hover { background: #f0f0f0; }

.btn-primary {
  background: #1a7a3e;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.btn-primary:hover { background: #155c2e; }

.btn-danger {
  background: #c62828;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.btn-danger:hover { background: #a01e1e; }

.btn-warning {
  background: #b76e00;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.btn-warning:hover { background: #955800; }
.btn-warning:disabled { background: #ccc; cursor: not-allowed; }

/* ───────── Filter bar ───────── */

.filter-bar {
  display: flex;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid #e5e5e7;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.filter-btn {
  background: white;
  border: 1px solid #ddd;
  padding: 5px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
}

.filter-btn.active {
  background: #004e92;
  color: white;
  border-color: #004e92;
}

/* ───────── List column ───────── */

.list-column {
  overflow-y: auto;
  padding: 8px;
  flex: 1;
  min-height: 0;
}

.list-item {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  align-items: center;
  transition: background 0.1s;
  border: 2px solid transparent;
}

.list-item:hover { background: #f0f0f0; }
.list-item.active { background: #e8f0f8; border-color: #004e92; }

.list-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fafafa;
  border-radius: 6px;
  flex-shrink: 0;
}

.list-item-body { flex: 1; min-width: 0; }

.list-item-title {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-cat {
  color: #888;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-badges {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.list-item-badges .badge {
  font-size: 10px;
  padding: 2px 6px;
}

/* ───────── Right panel / detail ───────── */

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #888;
  font-size: 16px;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-header h2 {
  margin: 0;
  font-size: 22px;
  flex: 1;
}

.images-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 1200px) {
  .images-panel { grid-template-columns: 1fr; }
}

.image-block {
  background: white;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.image-block h3 {
  margin: 0 0 10px;
  font-size: 12px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.image-block img {
  width: 100%;
  max-height: 400px;
  object-fit: contain;
  background: #fafafa;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
  transition: transform 0.1s;
}

.image-block img:hover {
  transform: scale(1.02);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 95vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.25); }

.muted {
  color: #888;
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.info-section {
  background: white;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  margin-bottom: 16px;
}

.info-section h3 {
  margin: 0 0 10px;
  font-size: 12px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.meta-row {
  display: flex;
  padding: 4px 0;
  font-size: 14px;
  border-bottom: 1px solid #f0f0f0;
}

.meta-row label {
  font-weight: 600;
  min-width: 110px;
  color: #666;
}

.meta-row span {
  flex: 1;
  word-break: break-word;
}

.prompt-box {
  background: #f8f9fb;
  border-radius: 6px;
  padding: 10px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  margin: 6px 0 0;
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid #e5e5e7;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.score-box {
  background: #f8f9fb;
  padding: 8px 10px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-box label {
  font-size: 10px;
  color: #666;
  font-weight: 600;
  text-transform: uppercase;
}

.score-box span:first-of-type {
  font-size: 16px;
  font-weight: 700;
}

.score-hint {
  font-size: 10px;
  color: #888;
}

.score-box span.good { color: #1a7a3e; }
.score-box span.bad { color: #c62828; }
.score-box span.warn { color: #b76e00; }

.context-section {
  background: #f7fbff;
  border-left: 3px solid #004e92;
}

.spec-section {
  background: #fff8f0;
  border-left: 3px solid #b76e00;
}

.spec-visual {
  margin: 4px 0 8px;
  font-size: 13px;
  color: #333;
  line-height: 1.5;
  font-style: italic;
}

.facts-list {
  margin: 6px 0 8px;
  padding-left: 18px;
  font-size: 13px;
  color: #333;
}
.facts-list li {
  margin-bottom: 3px;
}
.facts-list:empty::after {
  content: "—";
  color: #aaa;
}

.ctx-details {
  margin-top: 8px;
}
.ctx-details summary {
  cursor: pointer;
  font-size: 12px;
  color: #004e92;
  font-weight: 600;
  padding: 4px 0;
}
.ctx-details[open] summary {
  margin-bottom: 6px;
}

.issues-block { margin-top: 10px; }

.issues-block label {
  font-size: 12px;
  color: #666;
  font-weight: 600;
}

.issues-block ul {
  margin: 4px 0 0;
  padding-left: 18px;
  font-size: 13px;
  color: #444;
}

.issues-block li { margin-bottom: 2px; }

#comment-input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  margin-bottom: 10px;
}

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

.msg {
  margin-top: 10px;
  font-size: 13px;
  min-height: 18px;
}

.msg.success { color: #1a7a3e; }
.msg.error { color: #c62828; }
