:root {
  color-scheme: light;
  --bg: #d5d5d7;
  --panel: #ffffff;
  --panel-deep: #f2f2f4;
  --panel-soft: #f8f8f9;
  --line: #c2c2c8;
  --line-strong: #96969f;
  --text: #00002d;
  --muted: #666672;
  --accent: #ff6600;
  --accent-strong: #d95700;
  --warning: #a85a00;
  --danger: #d72638;
  --live: #0096d6;
  --focus: 0 0 0 3px rgba(255, 102, 0, 0.22);
  font-family: Jost, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(255, 102, 0, 0.12) 0 18px, transparent 18px),
    linear-gradient(180deg, #f6f6f7 0%, var(--bg) 100%);
}

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

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

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

button:disabled:hover {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

button.ghost-button:disabled:hover,
.small-button:disabled:hover {
  color: var(--text);
  border-color: var(--accent);
  background: #fff;
}

button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: var(--focus);
}

button.ghost-button,
.small-button {
  color: var(--text);
  background: #fff;
}

button.ghost-button:hover,
.small-button:hover {
  color: #fff;
  background: var(--accent);
}

.icon-button {
  width: 36px;
  padding: 0;
  border-color: var(--line);
  color: var(--text);
  background: #fff;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

label span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(255, 102, 0, 0.16) 0 22px, transparent 22px),
    linear-gradient(180deg, #ffffff 0%, #ededf0 100%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 45, 0.16);
}

.login-form {
  display: grid;
  gap: 18px;
}

.login-form h1 {
  margin-top: 4px;
  font-size: 32px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(520px, 1fr) minmax(260px, 320px);
  grid-template-rows: 72px minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar topbar"
    "media schedule events";
  height: 100vh;
  overflow: hidden;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 45, 0.08);
}

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

.brand-mark {
  display: block;
  width: 56px;
  height: 42px;
  object-fit: contain;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.channel-strip,
.status-cluster,
.toolbar,
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.channel-strip {
  flex: 1;
}

.channel-strip label {
  min-width: 180px;
}

.channel-strip label:first-child {
  flex: 1;
}

.status-cluster {
  justify-content: flex-end;
}

.metric {
  min-width: 112px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.metric span,
.metric strong {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.metric .overrun,
.overrun {
  color: var(--danger);
}

.media-panel,
.events-panel,
.schedule-panel {
  min-height: 0;
  overflow: hidden;
}

.media-panel {
  grid-area: media;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: var(--panel-deep);
}

.events-panel {
  grid-area: events;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: var(--panel-deep);
}

.schedule-panel {
  background: #e7e7ea;
}

.schedule-panel {
  grid-area: schedule;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.panel-actions,
.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-head h2 {
  font-size: 18px;
}

.panel-head p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  min-height: 38px;
}

.media-controls {
  display: grid;
  gap: 8px;
}

.media-pager {
  display: grid;
  grid-template-columns: 58px minmax(54px, 1fr) 58px;
  gap: 6px;
  align-items: center;
}

.media-pager span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.media-catalog,
.secondary-list,
.schedule-list {
  min-height: 0;
  overflow: auto;
}

.media-catalog {
  display: grid;
  gap: 14px;
  padding-right: 2px;
}

.catalog-empty {
  padding: 10px 0;
}

.media-group {
  display: grid;
  gap: 8px;
}

.media-group h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 0;
  color: var(--muted);
  background: var(--panel-deep);
  font-size: 12px;
  text-transform: uppercase;
}

.media-card,
.secondary-card,
.schedule-row,
.empty-schedule {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(0, 0, 45, 0.04);
}

.media-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border-left: 5px solid var(--type-color, var(--line-strong));
  cursor: grab;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-top > div {
  min-width: 0;
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  border-color: var(--line);
  color: var(--text);
  background: #fff;
  font-size: 12px;
}

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

.danger-button {
  border-color: rgba(215, 38, 56, 0.42);
  color: var(--danger);
}

.danger-button:hover {
  border-color: var(--danger);
  color: #fff;
  background: var(--danger);
}

.media-card.drop-ready,
.schedule-row.drop-ready {
  border-color: var(--accent);
  border-left-color: var(--type-color, var(--accent));
  background: #fff6f0;
}

.schedule-list.drop-ready {
  border-color: var(--accent);
  background: #fff6f0;
}

.media-card strong,
.media-card span,
.schedule-title strong,
.schedule-title span {
  display: block;
  overflow-wrap: anywhere;
}

.media-card span,
.schedule-title span {
  color: var(--muted);
  font-size: 12px;
}

.media-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.media-meta span,
.secondary-chips span {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--text);
  background: #ededf0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.is-live {
  background: #f1fbff;
}

.is-live .media-meta span:nth-child(2) {
  color: #fff;
  background: var(--live);
}

.is-missing {
  background: #fff1f2;
}

.is-forced {
  box-shadow: inset 0 0 0 1px rgba(255, 102, 0, 0.28);
}

.toolbar {
  min-height: 58px;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.toolbar-group {
  flex-wrap: wrap;
}

.toolbar select {
  width: 180px;
}

.toolbar input[type="file"] {
  width: 190px;
  min-height: 36px;
  padding: 6px;
  font-size: 13px;
}

.schedule-list {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  border: 1px solid transparent;
}

.empty-schedule {
  display: grid;
  min-height: 200px;
  place-items: center;
  color: var(--muted);
  border-style: dashed;
  background: rgba(255, 255, 255, 0.72);
}

.schedule-row {
  display: grid;
  grid-template-columns: 28px 124px minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-left: 5px solid var(--type-color, var(--line-strong));
}

.schedule-row.is-selected {
  border-color: var(--accent);
  border-left-color: var(--type-color, var(--accent));
  background: #fff7f1;
  box-shadow: inset 0 0 0 1px rgba(255, 102, 0, 0.24), 0 2px 10px rgba(0, 0, 45, 0.06);
}

.schedule-select-wrap {
  display: grid;
  place-items: center;
}

.schedule-select-wrap input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.schedule-category {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin: 6px 0 0;
  border-left: 5px solid var(--type-color, var(--line-strong));
  padding: 0 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.schedule-category span {
  letter-spacing: 0;
}

.timecode {
  font-variant-numeric: tabular-nums;
}

.start-time-input {
  min-height: 28px;
  padding: 4px 6px;
  color: var(--text);
  border-color: var(--accent);
  background: #fff3eb;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.is-forced-time span {
  color: var(--accent);
}

.timecode strong,
.timecode span {
  display: block;
}

.timecode span {
  color: var(--muted);
  font-size: 13px;
}

.schedule-main {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.schedule-title strong {
  font-size: 15px;
}

.error-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  border: 1px solid var(--danger);
  border-radius: 50%;
  color: var(--danger);
  background: rgba(215, 38, 56, 0.1);
  font-size: 0;
  line-height: 0;
  vertical-align: middle;
}

.error-icon::before {
  content: "!";
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: var(--danger);
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.secondary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.schedule-tools {
  display: grid;
  grid-template-columns: 96px repeat(4, 48px);
  gap: 6px;
  align-items: center;
}

.schedule-tools button {
  min-width: 0;
  padding: 0 6px;
  border-color: var(--line);
  color: var(--text);
  background: #fff;
  font-size: 12px;
}

.schedule-tools button:hover {
  color: #fff;
  background: var(--accent);
}

.schedule-tools input {
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.event-form,
.secondary-list {
  display: grid;
  gap: 8px;
}

.secondary-card {
  display: grid;
  gap: 2px;
  padding: 10px;
  cursor: grab;
}

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

dialog {
  width: min(420px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 45, 0.18);
}

dialog::backdrop {
  background: rgba(0, 0, 45, 0.32);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-form h2 {
  font-size: 20px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.check-row span {
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(0, 0, 45, 0.16);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.dirty {
  border-color: var(--warning);
  background: var(--warning);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(260px, 320px) minmax(460px, 1fr);
    grid-template-rows: auto minmax(260px, 40vh) minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "media events"
      "schedule schedule";
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .channel-strip {
    min-width: min(680px, 100%);
    order: 3;
  }

  .media-panel,
  .events-panel {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "topbar"
      "media"
      "events"
      "schedule";
  }

  .topbar,
  .channel-strip,
  .status-cluster,
  .toolbar,
  .toolbar-group {
    align-items: stretch;
    flex-direction: column;
  }

  .brand,
  .channel-strip label,
  .toolbar select,
  .toolbar input[type="file"] {
    width: 100%;
    min-width: 0;
  }

  .media-panel,
  .events-panel,
  .schedule-panel {
    max-height: none;
    overflow: visible;
  }

  .media-catalog,
  .secondary-list,
  .schedule-list {
    overflow: visible;
  }

  .schedule-row {
    grid-template-columns: 28px 1fr;
  }

  .schedule-tools {
    grid-column: 1 / -1;
    grid-template-columns: minmax(96px, 1fr) repeat(4, 54px);
  }

  .schedule-main {
    grid-column: 1 / -1;
  }
}
