:root {
  color-scheme: light;
  --bg: #f7f2ea;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #6f675e;
  --accent: #c2542a;
  --accent-2: #1f5f5b;
  --line: #e1d8cc;
  --shadow: 0 20px 50px rgba(44, 36, 26, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background: #f2ede3;
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-family: "IBM Plex Serif", "Times New Roman", serif;
  margin: 0 0 12px;
}

h1 {
  font-size: clamp(1.8rem, 2.4vw, 2.6rem);
}

h2 {
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

h3 {
  margin-top: 24px;
  font-size: 1rem;
}

p {
  margin: 0 0 12px;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 40px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.eyebrow {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--accent-2);
  letter-spacing: 0.3em;
}

.lead {
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 12px;
}

button {
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(29, 20, 10, 0.15);
}

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

button.secondary {
  border-style: dashed;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.1fr);
  gap: 24px;
}

.panel {
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.file-button {
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.file-button input {
  display: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

label.block {
  margin-top: 12px;
}

input,
textarea {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
}

textarea {
  resize: vertical;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schedule {
  background: #fff;
  border: 2px solid #111;
  padding: 8px;
  font-family: "Times New Roman", "IBM Plex Serif", serif;
  min-height: 520px;
  max-width: 640px;
  margin: 0 auto;
}

.schedule-pages {
  display: grid;
  gap: 16px;
}

.schedule-page {
  border: 1px solid #111;
  padding: 6px 8px 10px;
  background: #fff;
}

.schedule-header {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.8fr 0.9fr;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 2px solid #111;
  margin-bottom: 6px;
}

.header-left,
.header-center,
.header-times,
.header-right {
  border: 1px solid #111;
  padding: 4px 6px;
}

.header-left {
  display: grid;
  gap: 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-left .value {
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.left-top,
.left-bottom {
  display: grid;
  gap: 2px;
}

.left-bottom {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  font-size: 0.68rem;
}

.left-bottom div {
  display: flex;
  justify-content: space-between;
}

.header-center,
.header-times {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-center .value,
.header-times .value {
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.header-row {
  display: flex;
  justify-content: space-between;
}

.header-right {
  text-align: right;
}

.header-right .line {
  font-size: 1.3rem;
  font-weight: 700;
}

.header-right .subtitle {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}


.schedule-body {
  padding-top: 2px;
}

.table-wrap {
  border: 1px solid #111;
}

.divider {
  height: 8px;
}

.schedule table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}

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

.schedule th:first-child,
.schedule td:first-child {
  text-align: left;
  width: 46%;
}

.schedule th:nth-child(2),
.schedule td:nth-child(2) {
  width: 10%;
}

.schedule .line-label {
  background: #e6e6e6;
  font-weight: 700;
}

.schedule .km-label {
  background: #f1f1f1;
  font-weight: 700;
}

.schedule .footer-box {
  border: 1px solid #111;
  margin-top: 8px;
  padding: 6px;
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: pre-line;
}

.grid-editor {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fffbf3;
  overflow-x: auto;
}

.grid-editor table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 620px;
}

.grid-editor th,
.grid-editor td {
  border: 1px solid var(--line);
  padding: 6px;
  text-align: left;
  vertical-align: top;
  overflow: hidden;
}

.grid-editor th:first-child,
.grid-editor td:first-child {
  width: 35%;
}

.grid-editor th:nth-child(2),
.grid-editor td:nth-child(2) {
  width: 12%;
}

.cell-editor {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.cell-editor select,
.cell-editor input {
  font-size: 0.78rem;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  max-width: 100%;
}

.cell-editor input {
  width: 70px;
}

.grid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.grid-copy {
  padding: 2px 6px;
  border-radius: 8px;
  font-size: 0.7rem;
}

.stop-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loop-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--muted);
}

.loop-row {
  font-weight: 700;
}

.grid-placeholder {
  min-height: 80px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fffaf0;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 24, 18, 0.5);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(1100px, 90vw);
  max-height: 90vh;
  background: #fff;
  border-radius: 16px;
  border: 2px solid #111;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.modal-body {
  overflow: auto;
  padding-right: 4px;
}

.line-block {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 16px;
  background: #fffdf7;
}

.line-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.line-block-header h4 {
  margin: 0;
  font-size: 0.95rem;
}

.line-return {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.preview-footer {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

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

  .schedule-header {
    grid-template-columns: 1fr;
  }

  .header-right {
    text-align: left;
  }
}
