* {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
  background: #1e1f22;
  color: #fff;
  padding: 20px;
  margin: 0;
  background-image:
    radial-gradient(circle at top left, rgba(88, 101, 242, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(35, 165, 90, 0.08), transparent 24%);
}

.container {
  max-width: 1200px;
  margin: auto;
}

.hero {
  margin-bottom: 24px;
}

.hero h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.hero p {
  margin: 0;
  color: #b5bac1;
  max-width: 720px;
}

.panel {
  background: rgba(43, 45, 49, 0.9);
  border: 1px solid #3a3d44;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
}

.panel h3 {
  margin: 0 0 14px;
}

input, textarea, select {
  width: 100%;
  padding: 8px;
  margin-bottom: 10px;
  background: #2b2d31;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(88, 101, 242, 0.65);
  outline-offset: 1px;
}

button {
  padding: 8px 12px;
  background: #5865F2;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  margin: 5px 5px 10px 0;
}

button:hover { background: #4752C4; }
button.danger { background: #ed4245; }

.row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 120px 120px;
  gap: 10px;
  align-items: start;
  margin-bottom: 6px;
}

.row.dragging {
  opacity: 0.48;
}

.row input {
  margin-bottom: 0;
}

.name-cell {
  position: relative;
}

.name-cell input {
  padding-right: 42px;
}

.name-drag-handle {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  color: #b5bac1;
  border-left: 1px solid #444;
  border-radius: 0 6px 6px 0;
  cursor: grab;
  touch-action: none;
}

.name-drag-handle:hover {
  background: #34373e;
  color: #fff;
}

.name-drag-handle:active {
  cursor: grabbing;
}

.row.name-drop-target .name-input {
  outline: 2px solid rgba(35, 165, 90, 0.85);
  outline-offset: 1px;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(3, 36px);
  gap: 6px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  background: #3a3d44;
  color: #fff;
}

.icon-button:hover {
  background: #4752C4;
}

.icon-button.danger:hover {
  background: #c93437;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.drag-handle {
  cursor: grab;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.section { margin-top: 30px; }

.output {
  white-space: pre-wrap;
  background: #2b2d31;
  padding: 10px;
  border-radius: 6px;
  min-height: 78px;
  border: 1px solid #3f434d;
}

.setup-grid {
  display: grid;
  gap: 20px;
}

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

.field-full {
  grid-column: 1 / -1;
}

.field label,
.stack label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.helper {
  margin: -2px 0 10px;
  color: #b5bac1;
  font-size: 0.92rem;
}

.stack {
  display: flex;
  flex-direction: column;
}

.schedule-card {
  margin-top: 20px;
}

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

.schedule-head p {
  margin: 4px 0 0;
  color: #b5bac1;
  font-size: 0.92rem;
}

.schedule-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, 38px);
  gap: 0;
  overflow: hidden;
  border: 1px solid #3a3d44;
  border-radius: 10px;
  background: #24262b;
}

.view-toggle .icon-button {
  width: 38px;
  height: 38px;
  border-radius: 0;
  background: #34373e;
}

.view-toggle .icon-button + .icon-button {
  border-left: 1px solid #3a3d44;
}

.view-toggle .icon-button.active {
  background: #202226;
  color: #fff;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
}

.schedule-wrap {
  background: rgba(30, 31, 34, 0.72);
  border: 1px solid #3a3d44;
  border-radius: 12px;
  padding: 14px;
}

.schedule-list {
  display: grid;
  gap: 8px;
  min-height: 72px;
}

.schedule-table-wrap {
  display: none;
  overflow-x: auto;
}

.schedule-table-wrap.active {
  display: block;
}

.schedule-list.hidden {
  display: none;
}

.row-header.hidden {
  display: none;
}

.schedule-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: fixed;
}

.schedule-table th,
.schedule-table td {
  border-bottom: 1px solid #3a3d44;
  padding: 6px;
  text-align: center;
}

.schedule-table th {
  color: #b5bac1;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.schedule-table th:first-child,
.schedule-table td:first-child {
  width: 180px;
  text-align: left;
}

.schedule-table input {
  margin: 0;
  min-width: 0;
  text-align: center;
}

.schedule-table .table-name-input {
  text-align: left;
}

.schedule-table .readonly-time {
  border-radius: 6px;
  padding: 8px 4px;
  background: rgba(43, 45, 49, 0.68);
  color: #f2f3f5;
}

.schedule-table .source-col {
  background: rgba(88, 101, 242, 0.12);
}

.schedule-table .rollover-forward {
  background: rgba(35, 165, 90, 0.14);
}

.schedule-table .rollover-back {
  background: rgba(237, 66, 69, 0.12);
}

.row-header {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 120px 120px;
  gap: 10px;
  margin-bottom: 10px;
  color: #b5bac1;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* checkboxes */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  text-align: center;
}

.checkbox-grid > div {
  background: rgba(30, 31, 34, 0.72);
  border: 1px solid #3a3d44;
  border-radius: 10px;
  padding: 10px 8px;
}

.checkbox-grid input {
  width: auto;
  margin: 0 0 6px;
}

.output-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.output-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.78fr) minmax(0, 1.22fr);
  gap: 20px;
  align-items: start;
}

.stack-column {
  display: grid;
  gap: 20px;
  width: 100%;
}

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

.card-head h3 {
  margin-bottom: 4px;
}

.card-head p {
  margin: 0;
  color: #b5bac1;
  font-size: 0.92rem;
}

/* flyer layout */
.flyer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
  align-items: flex-start;
}

.flyer-row.names-times,
.flyer-row.times-only {
  justify-content: flex-start;
}

.tz-block {
  background: #2b2d31;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  height: 100%;
  flex: 0 0 auto;
}

.inner {
  display: grid;
  gap: 2px;
  align-items: stretch;
  flex: 1;
}

.tz-block strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.86rem;
}

.flyer-col {
  display: grid;
  grid-template-rows: auto auto;
  gap: 2px;
}

.flyer-col button,
.flyer-col textarea {
  margin-bottom: 0;
}

.flyer-col textarea {
  min-height: 0;
  height: auto;
  resize: none;
  overflow: hidden;
  padding: 3px;
  font-size: 0.82rem;
  line-height: 1.22;
}

.names-block .flyer-col textarea {
  font-size: 0.84rem;
  white-space: pre;
  overflow-x: auto;
  overflow-y: hidden;
}

.names-block {
  width: 208px;
}

.time-block .flyer-col textarea {
  font-size: 0.8rem;
}

.time-block {
  width: 120px;
}

.flyer-copy {
  min-width: 0;
  padding: 3px 4px;
  font-size: 0.78rem;
  line-height: 1;
}

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

.actions button {
  margin: 0;
}

.message {
  min-height: 20px;
  margin-top: 8px;
  color: #ffcc66;
}

.flyer-controls {
  width: 100%;
  max-width: none;
  padding: 12px;
  align-self: stretch;
}

.flyer-output {
  margin-top: 20px;
}

.flyer-controls .card-head {
  margin-bottom: 8px;
}

.flyer-controls .card-head h3 {
  margin-bottom: 2px;
}

.flyer-controls .card-head p {
  font-size: 0.88rem;
}

.flyer-controls .field {
  max-width: 160px;
}

.flyer-controls .field label {
  margin-bottom: 4px;
}

.flyer-controls .field select {
  margin-bottom: 0;
}

.flyer-controls .actions {
  margin-bottom: 0;
}

.flyer-controls-body {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 320px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(237, 66, 69, 0.96);
  color: #fff;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 1000;
}

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

.field-error {
  outline: 2px solid rgba(237, 66, 69, 0.85);
  outline-offset: 1px;
}

@media (max-width: 980px) {
  .flyer-row {
    flex-wrap: wrap;
  }

  .names-block,
  .time-block {
    width: 100%;
  }

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

@media (max-width: 720px) {
  body {
    padding: 14px;
  }

  .field-grid,
  .row-header,
  .row {
    grid-template-columns: 1fr;
  }

  .row {
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid #3a3d44;
  }

  .drag-handle {
    width: 100%;
  }

  .row-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .icon-button {
    width: 100%;
  }

  .row-header {
    display: none;
  }

  .schedule-head,
  .card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .schedule-tools,
  .view-toggle {
    align-self: flex-start;
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 14px;
    max-width: none;
  }
}
