:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --text: #17211d;
  --muted: #66756f;
  --line: #d9e0dc;
  --accent: #126c5a;
  --accent-strong: #0d4e42;
  --warning: #a85d18;
  --shadow: 0 10px 30px rgba(23, 33, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1,
.topbar p,
.section-header h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 18px;
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.topbar button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  font-size: 14px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
}

.topbar button:hover {
  background: var(--accent-strong);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tabs-nav {
  display: flex;
  padding: 4px 8px;
  gap: 4px;
  background: #fdfdfd;
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  background: #f4f6f5;
  color: var(--text);
}

.tab-btn.active {
  border-color: var(--line);
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.view-content[hidden] {
  display: none;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-actions span {
  font-weight: 600;
  color: var(--muted);
  font-size: 13px;
}

.section-actions button {
  height: 24px;
  border: 0;
  border-radius: 4px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
}

.section-actions button:hover {
  background: var(--accent-strong);
}

.topbar-actions .secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: #ffffff;
}

.topbar-actions .secondary-button:hover {
  border-color: var(--accent);
  background: #ffffff;
}

.layout {
  display: grid;
  grid-template-columns: minmax(200px, 240px) minmax(300px, 1fr) minmax(340px, 1.2fr);
  gap: 8px;
  padding: 8px;
}

.filters,
.reports-panel,
.detail-panel {
  min-height: calc(100vh - 81px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.filters {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 12px;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 14px;
  color: var(--text);
  background: #ffffff;
}

textarea {
  min-height: 80px;
  padding: 6px 8px;
  resize: vertical;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.section-header h2 {
  font-size: 14px;
}

.section-header span {
  color: var(--muted);
  font-size: 12px;
}

.reports-list {
  display: grid;
  gap: 4px;
  padding: 8px;
}

.report-card {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  text-align: left;
  color: var(--text);
  background: #ffffff;
  cursor: pointer;
}

.report-card:hover,
.report-card.is-active {
  border-color: var(--accent);
}

.report-card-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.report-card-meta {
  color: var(--muted);
  font-size: 12px;
}

.empty-state,
.detail-content {
  padding: 12px;
  color: var(--muted);
}

.detail-content {
  display: grid;
  gap: 12px;
  color: var(--text);
}

.detail-heading,
.button-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.detail-heading h3,
.detail-heading p {
  margin: 0;
}

.detail-heading h3 {
  font-size: 16px;
}

.detail-heading p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 32px;
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  cursor: pointer;
}

.primary-button {
  border: 0;
  color: #ffffff;
  background: var(--accent);
}

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: #ffffff;
}

.secondary-button:hover {
  border-color: var(--accent);
}

.danger-button {
  border: 1px solid #d8a4a4;
  color: #8f1d1d;
  background: #fff5f5;
}

.danger-button:hover {
  border-color: #b42323;
  color: #711515;
}

.edit-form {
  display: grid;
  gap: 12px;
}

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

.inline-edit-title {
  display: block;
  width: 100%;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  transition: border-color 0.2s, background-color 0.2s;
}

.inline-edit-title:hover,
.inline-edit-title:focus {
  border-color: var(--line);
  background: #ffffff;
}

.inline-edit-description {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  resize: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.inline-edit-description:hover,
.inline-edit-description:focus {
  border-color: var(--line);
  background: #ffffff;
  color: var(--text);
}

.autosave-indicator {
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-self: center;
}

.autosave-indicator[hidden] {
  visibility: hidden;
  display: block;
}

.autocomplete-field {
  position: relative;
  display: block;
}

.regex-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  position: absolute;
  top: -20px;
  right: 0;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.regex-toggle input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.autocomplete-list {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: grid;
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.autocomplete-list[hidden] {
  display: none;
}

.autocomplete-option {
  min-height: 36px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
  cursor: pointer;
}

.autocomplete-option:hover {
  background: #edf7f3;
}

.autocomplete-empty {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
}

.trailer-list {
  display: grid;
  gap: 4px;
}

.trailer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.trailer-row.is-clickable,
.attachment-row.is-clickable {
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.1s;
}

.trailer-row.is-clickable:hover,
.attachment-row.is-clickable:hover {
  border-color: var(--accent);
  background-color: #f9fbfb;
}

.trailer-row div {
  display: grid;
  gap: 2px;
}

.trailer-row strong {
  font-size: 14px;
}

.trailer-row span {
  color: var(--muted);
  font-size: 12px;
}

.subsection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.subsection-heading h3 {
  margin: 0;
  font-size: 14px;
}

.subsection-heading span {
  color: var(--muted);
  font-size: 12px;
}

.file-upload-container {
  margin-bottom: 8px;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 60px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fdfdfd;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}

.drop-zone:hover,
.drop-zone.is-dragover {
  border-color: var(--accent);
  background: #f7faf9;
  color: var(--accent);
}

.drop-zone p {
  margin: 0;
  font-size: 13px;
  pointer-events: none;
}

.drop-zone span {
  font-size: 11px;
  opacity: 0.8;
  pointer-events: none;
}

.drop-zone[disabled] {
  cursor: wait;
  opacity: 0.6;
}

.attachment-list {
  display: grid;
  gap: 4px;
}

.attachment-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

/* Comments styling */
.comments-list {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.comment-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #ffffff;
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.comment-author {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 13px;
}

.comment-author strong {
  color: var(--text);
}

.comment-body {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--text);
  white-space: pre-wrap;
}

.comment-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.comment-actions .plain-button {
  padding: 4px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 6px;
}

.comment-actions .plain-button:hover {
  color: var(--accent-strong);
  background: #f4f7f6;
}

.comment-actions .danger-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

/* Remove border/background for the pencil edit button and keep it minimal */
.comment-actions .edit-comment {
  background: transparent;
  border: none;
  padding: 2px 4px;
  margin: 0;
  outline: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
/* Reuse delete-button hover animation (background fade) but keep the edit color */
.comment-actions .edit-comment:hover,
.comment-actions .edit-comment:focus {
  background: rgba(180, 35, 35, 0.06);
  color: var(--accent-strong);
}

/* Small red X button for delete actions */
.x-button {
  background: transparent;
  border: none;
  color: #b42323; /* danger */
  padding: 2px 4px;
  font-size: 12px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
}
.x-button:hover {
  background: rgba(180, 35, 35, 0.06);
  color: #8f1d1d;
}

.icon {
  font-size: 12px;
  line-height: 1;
}

.comment-form textarea {
  min-height: 64px;
  border-radius: 6px;
}

.comment-form .button-row {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
}

.attachment-thumbnail {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg);
  cursor: zoom-in;
}

.attachment-row a {
  overflow: hidden;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-row strong {
  font-size: 13px;
}

.attachment-row span {
  font-size: 11px;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-button:hover {
  text-decoration: underline;
}

.lightbox {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-content {
  max-width: 90%;
  max-height: 90%;
}

.lightbox-content img {
  display: block;
  max-width: 100%;
  max-height: 90vh;
  border-radius: 4px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

@media (max-width: 980px) {
.empty-inline {
  color: var(--muted);
  font-size: 12px;
}

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

.field {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.field span {
  color: var(--muted);
  font-size: 11px;
}
}

.trailer-timeline {
  display: grid;
  gap: 0;
  padding-left: 8px;
  border-left: 1px solid var(--line);
  margin-left: 4px;
}

.timeline-event {
  position: relative;
  padding: 8px 0 8px 16px;
  border-bottom: 1px solid rgba(217, 224, 220, 0.5);
}

.timeline-event:last-child {
  border-bottom: 0;
}

.timeline-event.is-clickable {
  cursor: pointer;
  transition: background 0.1s;
}

.timeline-event.is-clickable:hover {
  background: rgba(18, 108, 90, 0.04);
}

.timeline-event-marker {
  position: absolute;
  left: -13px;
  top: 13px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--accent);
}

.timeline-event-content {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.timeline-event-type {
  font-size: 16px;
  min-width: 24px;
  text-align: center;
}

.timeline-event-date {
  color: var(--muted);
  font-size: 12px;
  min-width: 130px;
}

.timeline-event-title {
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-event-detail {
  color: var(--muted);
  font-size: 12px;
}

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

  .filters,
  .reports-panel,
  .detail-panel {
    min-height: auto;
  }

  .detail-heading,
  .button-row,
  .topbar-actions,
  .trailer-row {
    align-items: stretch;
  }

  .detail-heading,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .detail-heading {
    display: grid;
  }

  .topbar,
  .topbar-actions,
  .trailer-row,
  .file-upload-form,
  .attachment-row {
    display: grid;
  }

  .file-upload-form,
  .attachment-row {
    grid-template-columns: 1fr;
  }

  .timeline-event-content {
    flex-wrap: wrap;
    gap: 4px 12px;
  }

  .timeline-event-title {
    width: 100%;
    flex: none;
  }
}

/* Utility classes to replace inline styles for CSP compliance */
.flex-1 {
  flex: 1;
}

.grid-min-0 {
  display: grid;
  min-width: 0;
}

.font-13-muted {
  font-size: 13px;
  color: var(--muted);
  padding: 0 6px;
}

.attachment-thumbnail.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: default;
}

