:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #f0f3f5;
  --line: #d8dee4;
  --line-strong: #b8c2cc;
  --text: #17202a;
  --muted: #667280;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f4ef;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warning: #b7791f;
  --weekend: #f9f2e7;
  --today: #fff0c2;
  --day-width: 54px;
  --room-width: 220px;
  --row-height: 52px;
  font-family: "Inter", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), transparent 260px),
    var(--bg);
  font-size: 15px;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0 18px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 2px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.top-actions,
.toolbar-right,
.date-controls,
.inline-form,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 0 11px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.save-status[data-tone="ok"] {
  border-color: #b7ddd6;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.save-status[data-tone="warn"] {
  border-color: #f5d49a;
  background: #fff7df;
  color: #8a5a00;
}

.save-status[data-tone="error"] {
  border-color: #f5b5ae;
  background: var(--danger-soft);
  color: var(--danger);
}

.button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 40px;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.button.compact {
  min-height: 36px;
  padding-inline: 12px;
}

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

.button.secondary {
  background: #fff;
}

.button.danger {
  border-color: #f5b5ae;
  background: var(--danger-soft);
  color: var(--danger);
}

.logout-button {
  color: var(--muted);
}

.button:hover,
.icon-button:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  box-shadow: none;
}

.inline-form {
  min-width: 0;
}

.inline-form input {
  min-width: 0;
}

.inline-form .button {
  flex: 0 0 auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  min-height: 78px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 25px;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.room-manager,
.schedule-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
}

.room-manager {
  padding: 16px;
}

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

.count-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

.add-room-form {
  display: grid;
  gap: 7px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

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

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

.room-list {
  display: grid;
  gap: 8px;
  max-height: 650px;
  overflow: auto;
  padding-top: 14px;
}

.room-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
}

.room-item input {
  min-width: 0;
}

.room-item .button {
  min-width: 58px;
}

.schedule-area {
  min-width: 0;
  overflow: hidden;
}

.schedule-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.date-controls {
  flex-wrap: wrap;
}

.date-controls label {
  margin-left: 4px;
}

#viewStartInput {
  width: 150px;
}

.range-toggle,
.sort-toggle {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.range-toggle {
  grid-template-columns: repeat(3, 62px);
}

.sort-toggle {
  grid-template-columns: 56px 76px 88px;
}

.range-toggle button,
.sort-toggle button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.range-toggle button:last-child,
.sort-toggle button:last-child {
  border-right: 0;
}

.range-toggle button.active,
.sort-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.search-field {
  display: grid;
  grid-template-columns: auto minmax(170px, 220px);
  align-items: center;
  gap: 8px;
}

.chart-frame {
  overflow-x: auto;
  overflow-y: visible;
  max-height: none;
  min-height: 0;
}

.chart {
  width: max-content;
  min-width: calc(var(--room-width) + var(--days, 28) * var(--day-width));
}

.chart-header,
.chart-row {
  display: grid;
  grid-template-columns: var(--room-width) minmax(calc(var(--days, 28) * var(--day-width)), 1fr);
}

.chart-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
  border-bottom: 1px solid var(--line-strong);
}

.room-head,
.room-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--line-strong);
  background: #fff;
}

.room-head {
  min-height: 54px;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 800;
}

.day-header,
.timeline-row {
  display: grid;
  grid-template-columns: repeat(var(--days, 28), minmax(var(--day-width), 1fr));
}

.day-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 54px;
  padding: 6px 2px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.day-cell.weekend {
  background: var(--weekend);
}

.day-cell.today {
  background: var(--today);
  color: #7a5206;
}

.date-main {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.chart[data-range="42"] .day-cell {
  font-size: 12px;
  padding-inline: 2px;
}

.chart[data-range="42"] .date-main {
  font-size: 13px;
}

.chart-row {
  min-height: var(--row-height);
  border-bottom: 1px solid var(--line);
  align-items: stretch;
}

.room-cell {
  min-height: var(--row-height);
  padding: 9px 12px;
  font-weight: 800;
}

.room-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
  width: 100%;
}

.room-name {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.28;
}

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

.timeline-row {
  position: relative;
  height: 100%;
  min-height: var(--row-height);
  grid-template-rows: repeat(var(--lanes, 1), minmax(var(--row-height), auto));
  background: #fff;
}

.timeline-row.move-target {
  box-shadow: inset 0 0 0 3px rgba(15, 118, 110, 0.22);
}

.timeline-day {
  grid-row: 1;
  height: 100%;
  min-height: var(--row-height);
  border-right: 1px solid var(--line);
  pointer-events: none;
}

.timeline-day.weekend {
  background: rgba(249, 242, 231, 0.7);
}

.timeline-day.today {
  background: rgba(255, 240, 194, 0.9);
  box-shadow: inset 2px 0 0 #d79712;
}

.stay-bar {
  position: relative;
  grid-row: 1;
  align-self: center;
  z-index: 2;
  min-width: 0;
  height: 36px;
  margin: 0 3px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--bar-color, var(--accent));
  box-shadow: 0 5px 12px rgba(23, 32, 42, 0.14);
  overflow: hidden;
  text-align: left;
  cursor: grab;
  user-select: none;
}

.stay-bar.resizing {
  opacity: 0.82;
  outline: 3px solid rgba(15, 118, 110, 0.28);
}

.stay-bar.moving {
  opacity: 0.86;
  outline: 3px solid rgba(15, 118, 110, 0.22);
  cursor: grabbing;
}

.resize-handle {
  position: absolute;
  top: 6px;
  right: 4px;
  bottom: 6px;
  width: 16px;
  border-radius: 999px;
  cursor: ew-resize;
}

.resize-handle::before {
  content: "";
  position: absolute;
  top: 5px;
  right: 6px;
  bottom: 5px;
  width: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
}

.resize-handle:hover {
  background: rgba(255, 255, 255, 0.18);
}

.is-resizing-stay,
.is-resizing-stay * {
  cursor: ew-resize !important;
}

.is-moving-stay,
.is-moving-stay * {
  cursor: grabbing !important;
}

.stay-bar-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 100%;
  padding: 0 24px 0 8px;
}

.stay-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.stay-days {
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 800;
}

.chart[data-range="42"] .stay-bar-inner {
  gap: 4px;
  padding-inline: 6px;
}

.chart[data-range="42"] .stay-days {
  padding-inline: 5px;
  font-size: 11px;
}

.stay-bar.outside-start .stay-bar-inner {
  padding-left: 16px;
}

.stay-bar.outside-end .stay-bar-inner {
  padding-right: 16px;
}

.stay-bar.conflict {
  outline: 3px solid #fbbf24;
}

.empty-state {
  margin: 14px;
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  text-align: center;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 28, 36, 0.42);
}

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

.modal {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.stay-form {
  padding: 18px;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
}

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

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.swatch {
  width: 32px;
  height: 32px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--swatch);
}

.swatch[data-color="#0f766e"] {
  --swatch: #0f766e;
}

.swatch[data-color="#2563eb"] {
  --swatch: #2563eb;
}

.swatch[data-color="#e11d48"] {
  --swatch: #e11d48;
}

.swatch[data-color="#7c3aed"] {
  --swatch: #7c3aed;
}

.swatch[data-color="#f97316"] {
  --swatch: #f97316;
}

.swatch[data-color="#16a34a"] {
  --swatch: #16a34a;
}

.swatch.active {
  border-color: #111827;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.12);
}

.form-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--warning);
  font-weight: 800;
}

.modal-actions {
  margin-top: 14px;
}

.modal-spacer {
  flex: 1;
}

.login-page {
  min-height: 100vh;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  padding: 26px;
  box-shadow: 0 18px 60px rgba(23, 32, 42, 0.12);
}

.login-panel h1 {
  font-size: 25px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

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

.login-form .button {
  width: 100%;
  margin-top: 2px;
}

.login-error {
  margin: 0;
  border: 1px solid #f5b5ae;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  padding: 10px 12px;
  font-weight: 800;
}

@media (max-width: 1050px) {
  .topbar,
  .schedule-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .toolbar-right {
    flex-wrap: wrap;
  }

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

  .room-list {
    max-height: 280px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 14px;
  }

  h1 {
    font-size: 23px;
  }

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

  .top-actions,
  .date-controls,
  .toolbar-right {
    width: 100%;
  }

  .top-actions .button,
  .file-button {
    flex: 1 1 130px;
  }

  .search-field {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .range-toggle,
  .sort-toggle {
    width: 100%;
  }

  .range-toggle {
    grid-template-columns: repeat(3, 1fr);
  }

  .sort-toggle {
    grid-template-columns: repeat(3, 1fr);
  }

  .chart-frame {
    overflow-x: auto;
    overflow-y: visible;
  }

  :root {
    --room-width: 172px;
    --day-width: 48px;
  }

  .chart[data-range="42"] .day-cell {
    font-size: 11px;
  }

  .chart[data-range="42"] .date-main {
    font-size: 12px;
  }

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