:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #657282;
  --line: #d9e0e8;
  --accent: #0d7c66;
  --accent-strong: #075f4e;
  --warn: #b54708;
  --shadow: 0 12px 30px rgba(23, 33, 45, 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;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="text"] {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input[type="number"] {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

button {
  cursor: pointer;
  padding: 0 14px;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 14px;
}

.notice {
  margin-bottom: 18px;
  border: 1px solid #f0c36d;
  border-radius: 8px;
  background: #fff8e6;
  padding: 12px 14px;
  color: #6f4c00;
  font-size: 14px;
  line-height: 1.5;
}

.control-panel,
.status-dashboard,
.meeting-panel,
.library,
.source-list,
.preview-area {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
}

.status-card {
  display: grid;
  gap: 5px;
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  background: #f9fbfc;
}

.status-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-card strong {
  font-size: 22px;
  line-height: 1.1;
}

.control-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  align-items: end;
  padding: 16px;
}

/* The action buttons take their own row so they never collapse into a sliver. */
.control-panel .button-row {
  grid-column: 1 / -1;
}

.meeting-panel {
  margin-top: 18px;
  padding: 16px;
}

.meeting-grid {
  display: grid;
  grid-template-columns: minmax(170px, 0.75fr) minmax(180px, 1fr) minmax(170px, 0.9fr) minmax(260px, 1.4fr);
  gap: 14px;
  align-items: end;
}

.meeting-actions {
  justify-content: flex-end;
}

#openMeetingBtn,
#prepareMeetingRecordBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#openMeetingBtn:hover,
#prepareMeetingRecordBtn:hover {
  background: var(--accent-strong);
}

.control-group {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.control-group label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.control-group select,
.control-group input[type="text"] {
  width: 100%;
  padding: 0 10px;
}

.control-group.compact {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.control-group.compact label {
  grid-column: 1 / -1;
}

.control-group.compact input {
  width: 100%;
  accent-color: var(--accent);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

#addScreenBtn,
#newProjectBtn,
#startBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#addScreenBtn:hover,
#newProjectBtn:hover,
#startBtn:hover {
  background: var(--accent-strong);
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.preview-area {
  min-height: 520px;
}

.source-list,
.preview-area,
.library {
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 17px;
}

.section-title span,
#projectSummary {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.source-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 13px 0;
}

.source-card:first-child {
  border-top: 0;
}

.source-name {
  display: block;
  margin-bottom: 4px;
}

.source-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.source-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.source-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.remove-source,
.delete-item,
#deleteProjectBtn {
  color: #8a1f11;
}

.remove-source,
.delete-item {
  min-height: 34px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px;
}

.preview-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
}

.preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0a0f14;
  touch-action: none;
}

.preview-card video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-card.selecting .preview-stage {
  cursor: crosshair;
}

.region-box {
  position: absolute;
  border: 2px solid #49d6b6;
  background: rgba(73, 214, 182, 0.16);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  color: #eef4f8;
  font-size: 13px;
}

.preview-badge {
  color: #9ee2d1;
}

.library {
  margin-top: 18px;
}

#clearLibraryBtn,
#downloadProjectBtn {
  min-height: 34px;
}

.library-actions {
  align-items: center;
  justify-content: flex-end;
}

#libraryFilter {
  min-height: 34px;
  padding: 0 10px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.library-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.library-item img,
.library-item video,
.library-item audio {
  display: block;
  width: 100%;
  background: #eef2f6;
}

.library-item img,
.library-item video {
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.library-item audio {
  padding: 18px 12px;
}

.library-item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
}

.library-item-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.library-item-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.library-item a {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.library-item-meta {
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  display: grid;
  min-height: 170px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(12, 18, 24, 0.62);
  padding: 24px;
}

.editor-modal[hidden] {
  display: none;
}

.editor-panel {
  width: min(980px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.editor-panel video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0a0f14;
}

.editor-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr)) repeat(3, auto);
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

@media (max-width: 1050px) {
  .control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meeting-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button-row {
    justify-content: start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-grid {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }

  .editor-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .button-row {
    flex-direction: column;
    align-items: stretch;
  }

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

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

  .meeting-grid {
    grid-template-columns: 1fr;
  }

  .preview-grid {
    grid-template-columns: 1fr;
  }

  .editor-controls {
    grid-template-columns: 1fr;
  }
}
