:root {
  --color-bg: #dde2e8;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #666;
  --color-border: #aab3c0;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;

  --status-occupied-bg: #ffffff;
  --status-occupied-text: #1a1a1a;
  --status-vacant-bg: #2b2b2b;
  --status-vacant-text: #f5f5f5;
  --status-incoming-bg: #fde047;
  --status-incoming-text: #3f2d00;
  --status-leaving-bg: #9ca3af;
  --status-leaving-text: #1a1a1a;
  --status-storage-bg: #a78bfa;
  --status-storage-text: #ffffff;

  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 12px;
}

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

.header-top h1 {
  font-size: 1.1rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

#currentUserName {
  font-weight: 600;
  color: var(--color-text);
}

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

.floor-jump {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.vacancy-summary {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.vacancy-summary strong {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--color-text);
}

.btn-floor-jump {
  position: relative;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}
.btn-floor-jump:hover { background: var(--color-bg); }

.floor-jump-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.floor-jump-badge-reserved {
  position: absolute;
  top: -6px;
  left: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #fde047;
  color: #3f2d00;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* ---------- buttons ---------- */
.btn-primary, .btn-secondary {
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover { background: var(--color-bg); }

.btn-danger { color: var(--color-danger); border-color: var(--color-danger); }
.btn-primary.btn-danger { background: var(--color-danger); color: #fff; }

/* ---------- board ---------- */
.board {
  padding: 10px 12px 40px;
  max-width: 1500px;
  margin: 0 auto;
}

.floor-section {
  margin-bottom: 28px;
  padding: 14px 14px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

.floor-section h2 {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0 0 12px;
  color: var(--color-text);
}

.floor-label {
  display: none;
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.unit-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  min-width: 0;
}

.unit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 0 2px;
}

.unit-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.unit-rooms {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.unit-name-btn {
  background: none;
  border: none;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--color-primary);
  padding: 0 4px;
  border-radius: 6px;
  line-height: 1.2;
}
.unit-name-btn:hover { background: var(--color-bg); }

.unit-password-btn {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 3px 6px;
}
.unit-password-btn:hover { background: #e0e7ff; }

.room-tile {
  border: 2px solid var(--color-border);
  border-radius: 8px;
  padding: 8px;
  text-align: left;
  position: relative;
  height: 82px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  gap: 2px;
  background: var(--status-occupied-bg);
  color: var(--status-occupied-text);
}

.room-tile.status-VACANT { background: var(--status-vacant-bg); color: var(--status-vacant-text); }
.room-tile.status-INCOMING { background: var(--status-incoming-bg); color: var(--status-incoming-text); }
.room-tile.status-LEAVING { background: var(--status-leaving-bg); color: var(--status-leaving-text); }
.room-tile.status-STORAGE { background: var(--status-storage-bg); color: var(--status-storage-text); }

.room-tile.checkout-overdue { background: var(--color-danger); color: #ffffff; }

.room-tile .resident-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-tile .room-number {
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0.75;
}

.room-tile .room-sublabel {
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.85;
}

.room-tile .room-sublabel-out {
  color: var(--color-danger);
  font-weight: 800;
  opacity: 1;
}

.room-tile .room-sublabel-in {
  color: var(--color-primary);
  font-weight: 800;
  opacity: 1;
}

.room-tile .tile-badges {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
  max-width: calc(100% - 8px);
}

.tile-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  color: #fff;
}
.tile-badge.badge-issue { background: var(--color-danger); }
.tile-badge.badge-cleaning { background: #ffffff; color: #1a1a1a; border: 1px solid rgba(0,0,0,0.35); }
.tile-badge.badge-ready { background: #16a34a; }
.tile-badge.badge-gogo { background: #2563eb; }
.tile-badge.badge-lexis { background: #2563eb; }
.tile-badge.badge-cp { background: #fde047; color: #3f2d00; }
.tile-badge.badge-reserved { background: #fde047; color: #3f2d00; }

.next-resident-note {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin: 0 0 12px;
}

/* ---------- dorm (相部屋) tile ---------- */
/* 相部屋は人数分カードが伸びるため、サイズ統一の対象外（高さはコンテンツに追従） */
.dorm-tile {
  height: auto;
  min-height: 82px;
  gap: 4px;
}
.dorm-names {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ---------- mobile card size unification (<900px) ---------- */
@media (max-width: 899px) {
  .room-tile {
    height: 100px;
    padding: 26px 8px 8px;
  }

  .dorm-tile {
    height: auto;
    min-height: 120px;
  }
}

@media (min-width: 900px) {
  .floor-section h2 { display: none; }

  .unit-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas:
      "uA uB uC uD"
      "lbl lbl . uE"
      "lbl lbl . uF";
    align-items: stretch;
  }

  .unit-card {
    grid-area: var(--unit-area);
  }

  .floor-label {
    display: flex;
    align-items: center;
    justify-content: center;
    grid-area: lbl;
    min-height: 120px;
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: #ccd4df;
    background: none;
    border: none;
  }

  .unit-rooms {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    flex: 1;
  }

  /* 表示順は部屋番号昇順（r0=x11B等）。配置はExcelの間取り図に合わせる */
  .unit-card[data-unit-label="A"] .unit-rooms,
  .unit-card[data-unit-label="B"] .unit-rooms {
    grid-template-areas: "r1 r2" "r0 .";
  }
  .unit-card[data-unit-label="C"] .unit-rooms {
    grid-template-areas: "r0 r1" ". r1";
  }
  .unit-card[data-unit-label="D"] .unit-rooms {
    grid-template-areas: "r0 r1" ". r2";
  }
  .unit-card[data-unit-label="E"] .unit-rooms {
    grid-template-areas: "r0 r0" ". r1";
  }
  .unit-card[data-unit-label="F"] .unit-rooms {
    grid-template-areas: ". r0" "r2 r1";
  }
}

/* ---------- modal ---------- */
.modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(560px, 92vw);
  max-height: 88vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal::backdrop { background: rgba(0,0,0,0.45); }

.modal-confirm { width: min(320px, 90vw); }

.modal-content {
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  margin: 0;
  padding: 0;
  border: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  padding: 0 16px;
}
.modal-tabs[hidden] { display: none; }

.modal-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.modal-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--color-text-muted);
  padding: 2px 6px;
}

.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
}

.field-row {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-row label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.field-row input[type="text"],
.field-row input[type="date"],
.field-row select,
.field-row textarea {
  padding: 7px 9px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  width: 100%;
}

.field-row textarea { min-height: 56px; resize: vertical; }

.field-row input:disabled,
.field-row select:disabled,
.field-row textarea:disabled {
  background: var(--color-bg);
  color: var(--color-text);
  opacity: 1;
  -webkit-text-fill-color: var(--color-text);
  cursor: default;
}

.password-edit-row { display: flex; gap: 6px; }
.password-edit-row input { flex: 1; font-family: monospace; }

hr { border: none; border-top: 1px solid var(--color-border); margin: 12px 0; }

.comment-section h3, .modal-body h3 { font-size: 0.9rem; margin: 0 0 8px; }

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.comment-item {
  background: var(--color-bg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.comment-body-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.comment-delete-btn {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--color-danger);
  background: none;
  border: 1px solid var(--color-danger);
  border-radius: 6px;
  padding: 2px 6px;
}

.comment-meta {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.comment-empty { font-size: 0.8rem; color: var(--color-text-muted); }

.comment-add { display: flex; flex-direction: column; gap: 6px; }
.comment-add textarea { min-height: 50px; resize: vertical; padding: 7px 9px; border: 1px solid var(--color-border); border-radius: 6px; }

.history-list { display: flex; flex-direction: column; gap: 6px; }
.room-history-list { max-height: 320px; overflow-y: auto; }
.history-item {
  padding: 8px 10px;
  background: var(--color-bg);
  border-radius: 8px;
  font-size: 0.8rem;
}
.history-empty { color: var(--color-text-muted); font-size: 0.85rem; }

/* ---------- login screen ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.login-screen[hidden] { display: none; }

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 28px 24px;
  width: min(360px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.login-card h1 {
  font-size: 1.2rem;
  margin: 0 0 4px;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0 0 20px;
}

.login-error {
  font-size: 0.8rem;
  color: var(--color-danger);
  min-height: 1.2em;
  margin: 4px 0 12px;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

/* PC（マウス環境）ではビューポート切替が効かないため非表示 */
@media (hover: hover) and (pointer: fine) {
  #btnLayoutToggle { display: none; }
}

/* ---------- room hover preview (desktop) ---------- */
.room-preview {
  position: fixed;
  z-index: 60;
  width: 280px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  padding: 12px;
  font-size: 0.82rem;
  pointer-events: none;
}
.room-preview[hidden] { display: none; }

.room-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.room-preview-head strong { font-size: 0.95rem; }

.room-preview-status {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-bg);
  white-space: nowrap;
}
.room-preview-status.status-VACANT { background: var(--status-vacant-bg); color: var(--status-vacant-text); }
.room-preview-status.status-INCOMING { background: var(--status-incoming-bg); color: var(--status-incoming-text); }
.room-preview-status.status-LEAVING { background: var(--status-leaving-bg); color: var(--status-leaving-text); }
.room-preview-status.status-STORAGE { background: var(--status-storage-bg); color: var(--status-storage-text); }

.room-preview-row {
  display: flex;
  gap: 6px;
  margin: 2px 0;
}
.room-preview-row .k {
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.room-preview-row .v { overflow-wrap: anywhere; }

.room-preview-hint {
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-align: right;
}

/* ---------- notifications (master) ---------- */
.notif-wrap { position: relative; }

.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
.notif-badge[hidden] { display: none; }

.notif-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 300px;
  max-width: 88vw;
  max-height: 420px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  z-index: 80;
}
.notif-panel[hidden] { display: none; }

.notif-panel-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  font-weight: 700;
}

.notif-clear-btn {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 3px 8px;
}
.notif-clear-btn:hover { background: var(--color-bg); }

.notif-list { display: flex; flex-direction: column; }

.notif-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}
.notif-item:hover { background: var(--color-bg); }
.notif-item:last-child { border-bottom: none; }

.notif-item-today { border-left: 3px solid #2563eb; }

.notif-item-head { font-size: 0.8rem; font-weight: 700; margin-bottom: 2px; }
.notif-item-body { font-size: 0.8rem; overflow-wrap: anywhere; margin-bottom: 4px; }
.notif-item-meta { font-size: 0.68rem; color: var(--color-text-muted); }

.notif-empty { padding: 16px 12px; font-size: 0.8rem; color: var(--color-text-muted); text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a1a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
