* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

.container {
  max-width: 720px;
  margin: 16px auto;
  padding: 0 12px 40px;
}

.view.hidden {
  display: none !important;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.hint {
  color: #94a3b8;
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
}

.card {
  background: #111827;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.stack,
.entry-stack,
.actions.stacked,
.day-list,
.machine-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -2px 0 8px;
}

.inline-actions input {
  flex: 1;
  min-width: 160px;
}

.entry-form h3 {
  margin: 14px 0 8px;
  font-size: 15px;
  color: #cbd5e1;
}

.entry-form h3:first-of-type {
  margin-top: 0;
}

.filter-label {
  margin: 10px 0 6px;
  color: #94a3b8;
  font-size: 12px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 36px;
  min-height: 36px;
  padding: 0 14px;
  box-sizing: border-box;
  line-height: 1;
  white-space: nowrap;
  background: #0b1220;
  border: 1px solid #334155;
  font-size: 14px;
}

.chip.active {
  border-color: #38bdf8;
  background: #0c4a6e;
}

.preset-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 10px;
}

.preset-list button {
  width: auto;
  min-height: 34px;
}

button.small {
  width: auto;
  min-height: 34px;
  padding: 7px 10px;
  font-size: 12px;
}

.stats-bar {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.menu-grid {
  display: grid;
  gap: 12px;
}

.sync-settings code {
  font-size: 0.9em;
}

.sync-status {
  min-height: 1.2em;
  margin-top: 8px;
}

.menu-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 108px;
  padding: 18px;
  background: #0b1220;
  border: 1px solid #334155;
  text-align: left;
}

.menu-title {
  font-size: 1.4rem;
  font-weight: 800;
}

.menu-desc {
  color: #94a3b8;
  font-size: 14px;
}

.nav-button {
  margin-bottom: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 13px;
  color: #94a3b8;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #38bdf8;
}

.machine-card,
.day-card,
.machine-option {
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  color: inherit;
}

.machine-card.empty {
  border-style: dashed;
}

.machine-card .name,
.day-card .name,
.machine-option .name {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 6px;
}

.machine-card .meta,
.day-card .meta,
.machine-option .meta {
  margin: 0;
  color: #94a3b8;
  font-size: 13px;
}

.machine-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.machine-image-option {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  padding: 8px;
  overflow: hidden;
  color: inherit;
  text-align: left;
  background: #0b1220;
  border: 2px solid #334155;
  border-radius: 12px;
}

.machine-image-option img,
.machine-image-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #fff;
  border-radius: 7px;
}

.machine-image-placeholder {
  display: grid;
  place-items: center;
  color: #64748b;
  font-size: 12px;
  background: #020617;
}

.machine-image-option.selected {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px #38bdf8 inset;
}

.machine-image-name {
  font-weight: 700;
  line-height: 1.35;
}

.machine-image-meta {
  color: #94a3b8;
  font-size: 11px;
}

.manual-machine {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #334155;
  border-radius: 10px;
}

.manual-machine summary {
  cursor: pointer;
  color: #cbd5e1;
  font-weight: 600;
}

.manual-machine[open] summary {
  margin-bottom: 12px;
}

.day-card {
  cursor: pointer;
  width: 100%;
}

.day-card:hover,
.machine-option:hover {
  border-color: #38bdf8;
}

.kind-badge {
  display: inline-block;
  margin: 0 0 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #1e3a5f;
  color: #7dd3fc;
  font-size: 12px;
  font-weight: 700;
}

.kind-badge.p {
  background: #3f1d2e;
  color: #fda4af;
}

.context-picker h3,
#context_picker h3 {
  margin: 16px 0 10px;
  font-size: 1rem;
}

#context_picker h3:first-of-type {
  margin-top: 0;
}

#context_picker .full-width {
  margin-bottom: 8px;
}

.kind-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.machine-option.selected {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px #38bdf8 inset;
}

input[readonly] {
  opacity: 0.85;
  cursor: default;
}

.kind-tab {
  flex: 1;
  background: #1e293b;
  border: 1px solid #475569;
}

.kind-tab.active {
  background: #1d4ed8;
  border-color: #3b82f6;
}

.entry-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.selected-context-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #0b1220;
}

.selected-context-label {
  align-self: start;
  padding: 3px 7px;
  border-radius: 999px;
  background: #064e3b;
  color: #6ee7b7;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.selected-context-lines {
  min-width: 0;
  font-size: 14px;
  line-height: 1.55;
}

.selected-context-lines > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-separator {
  color: #64748b;
}

.context-edit-button {
  min-height: auto;
  padding: 6px 9px;
  background: transparent;
  color: #94a3b8;
  font-size: 12px;
}

.selected-summary {
  display: grid;
  gap: 10px;
}

.selected-summary > div {
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 12px;
}

.summary-label {
  display: block;
  margin-bottom: 4px;
  color: #94a3b8;
  font-size: 12px;
}

.selected-summary strong {
  font-size: 1.05rem;
}

.entry-block {
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px;
}

.primary-entry-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.primary-entry-row .entry-block {
  min-width: 0;
}

.primary-entry-row input,
.primary-entry-row select {
  width: 100%;
  min-width: 0;
}

.primary-entry-row button {
  padding-inline: 6px;
  font-size: 14px;
}

.entry-block.editing-target {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px #38bdf8 inset;
}

.entry-block.dimmed {
  opacity: 0.45;
  pointer-events: none;
}

.edit-banner {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #172554;
  color: #bfdbfe;
  font-size: 13px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  margin-bottom: 10px;
}

input,
select,
textarea,
button {
  border-radius: 10px;
  border: 1px solid #475569;
  padding: 12px;
  background: #0b1220;
  color: #e2e8f0;
  font-size: 16px;
}

textarea {
  width: 100%;
  resize: vertical;
}

.full-width {
  width: 100%;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 0;
}

button {
  cursor: pointer;
  min-height: 44px;
}

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

button.secondary {
  background: #1e293b;
}

button.danger {
  border-color: #7f1d1d;
  color: #fecaca;
}

.hidden {
  display: none !important;
}

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

.screen-group-label {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.02em;
}

.screen-ref-image {
  grid-column: 1 / -1;
  width: 100%;
  border-radius: 8px;
  border: 1px solid #334155;
}

.screen-card,
.screen-chip {
  background: #020617;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  padding: 8px;
  text-align: left;
  min-height: 44px;
}

.screen-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.screen-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #020617;
}

.screen-card.selected,
.screen-chip.selected {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px #38bdf8 inset;
}

.screen-label {
  font-size: 13px;
  font-weight: 600;
}

.screen-hint {
  font-size: 11px;
  color: #94a3b8;
}

.screen-chip {
  padding: 12px;
  font-size: 13px;
}

.screen-selected {
  margin: 0 0 10px;
  color: #7dd3fc;
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 520px;
}

th,
td {
  border-bottom: 1px solid #334155;
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

tr.editing {
  background: #172554;
}

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.row-actions button {
  min-height: 36px;
  padding: 8px 10px;
  font-size: 13px;
}

#summary {
  margin: 0;
  padding-left: 18px;
  line-height: 1.7;
}

#json_preview {
  background: #020617;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
  font-size: 12px;
}

@media (min-width: 640px) {
  .menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .screen-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .entry-header {
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }
}
