:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-strong: #f9fbfd;
  --text: #15212f;
  --muted: #627184;
  --line: #d9e2ec;
  --green: #0f766e;
  --blue: #315cfd;
  --amber: #b86b00;
  --red: #c24133;
  --ink: #243b53;
  --violet: #6d5bd0;
  --soft-green: #e6f5f2;
  --soft-blue: #e8efff;
  --soft-amber: #fff3d8;
  --soft-red: #ffede9;
  --soft-violet: #f0edff;
  --shadow: 0 16px 34px rgba(36, 59, 83, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #eef4fb 0, var(--bg) 280px);
  color: var(--text);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.5;
}

.app-header {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 18px 24px 14px;
  position: relative;
  z-index: 10;
}

.eyebrow {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  margin: 0 0 2px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 24px;
  margin-bottom: 0;
}

h2 {
  font-size: 17px;
  margin-bottom: 0;
}

h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.header-tools,
.toolbar,
.panel-title,
.form-row,
.inline-form {
  align-items: center;
  display: flex;
  gap: 10px;
}

.access-badge {
  background: var(--soft-blue);
  border: 1px solid #c9d7ff;
  border-radius: 999px;
  color: #2446b8;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 10px;
  white-space: nowrap;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.sync-badge[data-status="online"] { border-color: #86bda7; background: #edf8f3; color: #176348; }
.sync-badge[data-status="loading"],
.sync-badge[data-status="syncing"] { border-color: #90b8d4; background: #eef6fb; color: #245b7a; }
.sync-badge[data-status="error"] { border-color: #dfa09a; background: #fff1ef; color: #9d2d28; }

body[data-role="admin"] .access-badge {
  background: var(--soft-green);
  border-color: #b8ddd6;
  color: var(--green);
}

.auth-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  max-width: min(420px, calc(100vw - 32px));
  padding: 0;
  width: 100%;
}

.auth-dialog::backdrop {
  backdrop-filter: blur(3px);
  background: rgba(21, 33, 47, 0.48);
}

.auth-dialog form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-title {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
}

.dialog-description {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 0;
}

button,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

input,
select,
textarea {
  background: #fff;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(25, 107, 79, 0.14);
  outline: none;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

textarea {
  resize: vertical;
}

button {
  background: #fff;
  cursor: pointer;
  min-height: 38px;
  padding: 8px 12px;
}

button:hover {
  border-color: #9aa9b1;
}

button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 700;
}

button.primary:hover {
  background: #0b625c;
  border-color: #0b625c;
}

.icon-button {
  aspect-ratio: 1;
  font-size: 18px;
  padding: 0;
  width: 40px;
}

.tabs {
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 9;
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  min-width: max-content;
}

.tab.is-active {
  border-bottom-color: var(--blue);
  color: var(--text);
  font-weight: 700;
}

main {
  margin: 0 auto;
  max-width: none;
  padding: 18px 18px 36px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.summary-grid,
.settings-grid {
  display: grid;
  gap: 14px;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.summary-card,
.panel,
.list-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-card,
.panel {
  box-shadow: var(--shadow);
}

.summary-card {
  border-left: 4px solid var(--green);
  padding: 16px;
}

.summary-card strong {
  display: block;
  font-size: 30px;
  line-height: 1.1;
}

.summary-card span {
  color: var(--muted);
  font-size: 13px;
}

.two-column,
.split {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.split {
  align-items: start;
  grid-template-columns: 420px minmax(0, 1fr);
}

.reservation-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: 360px minmax(0, 1fr);
}

.reservation-calendar-panel,
.reservation-list-panel {
  min-width: 0;
}

.reservation-calendar-panel {
  grid-column: 1 / -1;
  grid-row: 1;
}

.reservation-list-panel {
  grid-column: 2;
}

.panel {
  padding: 16px;
}

.panel-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-title h2 {
  flex: 0 0 auto;
  white-space: nowrap;
}

.reservation-calendar-panel .panel-title {
  align-items: center;
  margin-bottom: 8px;
}

.list {
  display: grid;
  gap: 10px;
}

.list.compact {
  gap: 8px;
}

.list-item {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.list-item header {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 6px 8px;
}

.badge.red {
  background: var(--soft-red);
  color: var(--red);
}

.badge.amber {
  background: var(--soft-amber);
  color: var(--amber);
}

.badge.green {
  background: var(--soft-green);
  color: var(--green);
}

.badge.blue {
  background: var(--soft-blue);
  color: var(--blue);
}

.badge.violet {
  background: var(--soft-violet);
  color: var(--violet);
}

.asset-list {
  display: grid;
  gap: 10px;
}

.asset-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(36, 59, 83, 0.08);
  display: grid;
  gap: 14px;
  grid-template-columns: 76px minmax(220px, 1.5fr) repeat(4, minmax(116px, 0.72fr)) 112px;
  min-height: 92px;
  padding: 12px;
}

.asset-row:hover {
  border-color: #b8c7d9;
  box-shadow: 0 18px 36px rgba(36, 59, 83, 0.13);
}

.asset-photo {
  align-items: center;
  aspect-ratio: 1;
  background: var(--soft-blue);
  border: 1px solid #cad8f5;
  border-radius: 8px;
  color: var(--blue);
  display: flex;
  font-weight: 900;
  justify-content: center;
  overflow: hidden;
  width: 68px;
}

.asset-photo img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.asset-name-line {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.asset-name-line h3 {
  margin: 0;
}

.asset-subline {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}

.asset-metric {
  display: grid;
  gap: 2px;
}

.asset-metric span,
.asset-metric small {
  color: var(--muted);
  font-size: 12px;
}

.asset-metric strong {
  color: var(--ink);
  font-size: 15px;
}

.asset-photo-actions {
  display: grid;
  gap: 7px;
}

.photo-button,
.text-button {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  justify-content: center;
  min-height: 34px;
  padding: 7px 9px;
}

.photo-button {
  overflow: hidden;
  position: relative;
}

.photo-button input {
  cursor: pointer;
  height: 100%;
  inset: 0;
  opacity: 0;
  position: absolute;
  width: 100%;
}

.photo-button:focus-within {
  box-shadow: 0 0 0 3px rgba(20, 104, 112, 0.2);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.text-button {
  background: #fff;
  color: var(--ink);
  width: 100%;
}

.remove-photo {
  color: var(--red);
}

.form-panel {
  display: grid;
  gap: 12px;
}

.asset-editor-panel {
  margin-bottom: 14px;
}

.button-row,
.history-tools {
  align-items: center;
  display: flex;
  gap: 8px;
}

.button-row {
  justify-content: flex-end;
}

.master-file-actions,
.master-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.master-file-actions input {
  min-width: 0;
}

.master-file-actions button {
  flex: 0 0 auto;
}

.master-row {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

.master-row .meta {
  grid-column: 1;
}

.master-actions {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.master-actions .text-button {
  min-width: 64px;
}

.history-tools select {
  min-width: 190px;
}

.danger-button {
  background: var(--soft-red);
  border-color: #f4b5ad;
  color: var(--red);
  font-weight: 800;
}

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

.log-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.danger-text {
  color: var(--red);
}

.employee-combobox {
  position: relative;
}

.employee-results {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  left: 0;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 20;
}

.employee-results.is-open {
  display: grid;
  gap: 4px;
}

.employee-option {
  align-items: center;
  background: transparent;
  border: 0;
  display: flex;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 10px;
  text-align: left;
}

.employee-option:hover,
.employee-option.is-active {
  background: var(--soft-green);
}

.employee-option small {
  color: var(--muted);
}

.input-with-unit {
  align-items: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  position: relative;
}

.input-with-unit input {
  border-bottom-right-radius: 0;
  border-right: 0;
  border-top-right-radius: 0;
}

.input-with-unit span {
  align-items: center;
  align-self: stretch;
  background: #eef3f1;
  border: 1px solid var(--line);
  border-bottom-right-radius: 6px;
  border-left: 0;
  border-top-right-radius: 6px;
  color: var(--muted);
  display: inline-flex;
  font-weight: 700;
  min-width: 48px;
  padding: 0 12px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 5px;
}

.form-row > label,
.inline-form > * {
  flex: 1;
}

.role-note {
  color: var(--muted);
  font-size: 13px;
}

.form-error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 0;
  min-height: 20px;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar input {
  max-width: 420px;
}

.toolbar select {
  max-width: 180px;
}

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

.settings-grid > :first-child {
  grid-column: 1 / -1;
}

.settings-grid .inline-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rule-row {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 120px 120px;
  margin-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.calendar-controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.calendar-controls input[type="month"] {
  min-height: 34px;
  min-width: 138px;
  width: 138px;
}

.calendar-controls select {
  min-height: 34px;
  min-width: 220px;
  width: 220px;
}

.calendar-controls button {
  min-height: 34px;
}

.calendar-controls .icon-button {
  width: 36px;
}

.reservation-calendar {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: calc(100vh - 250px);
  overflow: auto;
  position: relative;
}

.calendar-grid {
  display: grid;
  grid-template-columns: 160px repeat(var(--reservation-days), minmax(0, 1fr));
  min-width: 0;
}

.calendar-header-row {
  background: #f8fbff;
  position: sticky;
  top: 0;
  z-index: 6;
}

.calendar-asset-header,
.calendar-asset-cell {
  background: #fff;
  border-right: 1px solid var(--line);
  left: 0;
  position: sticky;
  z-index: 5;
}

.calendar-asset-header {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  font-weight: 800;
  padding: 10px 12px;
  z-index: 7;
}

.calendar-day-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  display: grid;
  justify-items: center;
  min-height: 44px;
  min-width: 0;
  padding: 5px 2px;
}

.calendar-day-head span {
  color: var(--muted);
  font-size: 12px;
}

.calendar-day-head.saturday,
.calendar-cell.saturday {
  background: #f2f6ff;
}

.calendar-day-head.sunday,
.calendar-cell.sunday {
  background: #fff4ef;
}

.calendar-day-head.today,
.calendar-cell.today {
  box-shadow: inset 2px 0 0 var(--blue), inset -2px 0 0 var(--blue);
}

.calendar-asset-row {
  border-bottom: 1px solid var(--line);
}

.calendar-asset-cell {
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 8px 10px;
}

.calendar-asset-cell strong {
  font-size: 14px;
}

.calendar-asset-cell span,
.calendar-asset-cell div {
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  border-radius: 999px;
  display: inline-block;
  height: 8px;
  margin-right: 5px;
  width: 8px;
}

.status-dot.red {
  background: var(--red);
}

.status-dot.amber {
  background: var(--amber);
}

.status-dot.blue {
  background: var(--blue);
}

.status-dot.green {
  background: var(--green);
}

.calendar-cell {
  background: #fff;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  min-height: 58px;
  min-width: 0;
  overflow: hidden;
  padding: 5px 2px;
}

.calendar-cell.empty:hover {
  background: var(--soft-green);
}

.calendar-cell.booked {
  background: #dff7f1;
}

.calendar-cell.booked.start {
  border-bottom-left-radius: 8px;
  border-top-left-radius: 8px;
}

.calendar-cell.booked.end {
  border-bottom-right-radius: 8px;
  border-top-right-radius: 8px;
}

.calendar-cell.booked.continuation {
  color: transparent;
}

.calendar-cell.booked span {
  background: var(--green);
  border-radius: 6px;
  color: #fff;
  display: block;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.3;
  overflow: hidden;
  padding: 5px 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

.empty-table {
  color: var(--muted);
  padding: 24px 10px;
  text-align: center;
}

.demo-only {
  display: none !important;
}

body.is-demo .demo-only {
  display: inline-flex !important;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.is-hidden {
  display: none !important;
}

body[data-role="viewer"] .writable-only,
body[data-role="staff"] .admin-only,
body[data-role="viewer"] .admin-only,
body[data-role="accounting"] .admin-only,
body[data-role="staff"] .accounting-only,
body[data-role="viewer"] .accounting-only {
  display: none !important;
}

body[data-role="viewer"] form input,
body[data-role="viewer"] form select,
body[data-role="viewer"] form textarea {
  pointer-events: none;
}

@media (max-width: 1100px) {
  .summary-grid,
  .settings-grid,
  .two-column,
  .reservation-layout,
  .split {
    grid-template-columns: 1fr 1fr;
  }

  .reservation-calendar-panel,
  .reservation-list-panel {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .reservation-layout {
    grid-template-columns: minmax(300px, 0.55fr) minmax(0, 1fr);
  }

  .reservation-calendar-panel {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .reservation-list-panel {
    grid-column: 2;
  }

  .asset-row {
    grid-template-columns: 68px minmax(220px, 1fr) minmax(140px, 0.7fr);
  }

  .asset-photo-actions {
    grid-column: 2 / -1;
    grid-template-columns: 1fr 1fr;
  }

  .split {
    align-items: stretch;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .tabs {
    padding: 0 14px;
    top: 0;
  }

  .header-tools {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
  }

  .access-badge {
    padding: 5px 8px;
  }

  main {
    padding: 14px;
  }

  .summary-grid,
  .settings-grid,
  .two-column,
  .reservation-layout,
  .split,
  .form-row,
  .inline-form,
  .rule-row {
    grid-template-columns: 1fr;
  }

  .settings-grid > :first-child {
    grid-column: 1;
  }

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

  .reservation-calendar-panel,
  .reservation-list-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .toolbar,
  .history-tools,
  .button-row,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar input,
  .toolbar select,
  .history-tools select {
    max-width: none;
  }

  .calendar-controls {
    align-items: stretch;
    display: grid;
    grid-template-columns: 42px 1fr 42px;
  }

  .calendar-controls input,
  .calendar-controls select {
    grid-column: 1 / -1;
    width: 100%;
  }

  .calendar-controls button {
    width: 100%;
  }

  button,
  input,
  select {
    min-height: 44px;
  }

  .master-file-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .master-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .master-actions {
    grid-column: 1;
    grid-row: auto;
  }

  .reservation-calendar {
    max-height: 62vh;
  }

  .calendar-grid {
    grid-template-columns: 138px repeat(var(--reservation-days), 54px);
    min-width: max-content;
  }

  .calendar-cell {
    min-width: 54px;
  }
}

@media (min-width: 761px) and (max-width: 1180px) {
  .calendar-grid {
    grid-template-columns: 142px repeat(var(--reservation-days), minmax(0, 1fr));
  }

  .calendar-asset-cell strong {
    font-size: 12px;
  }

  .calendar-asset-cell span,
  .calendar-asset-cell div {
    font-size: 11px;
  }
}

@media (min-width: 1181px) {
  .calendar-cell.booked span {
    font-size: 11px;
  }
}

@media (max-width: 760px) {
  .calendar-grid {
    grid-template-columns: 150px repeat(var(--reservation-days), 58px);
    min-width: max-content;
  }

  .calendar-cell {
    min-width: 58px;
  }

  .asset-row {
    align-items: start;
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .asset-photo {
    width: 58px;
  }

  .asset-main,
  .asset-metric,
  .asset-photo-actions {
    grid-column: 2;
  }

  .asset-photo-actions {
    grid-template-columns: 1fr;
  }
}
