:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b42318;
  --success: #047857;
  --warning: #b45309;
  --shadow: 0 14px 30px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  font-weight: 800;
  letter-spacing: 0;
}

nav {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

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

.narrow {
  width: min(720px, calc(100% - 32px));
}

.hero {
  min-height: calc(100vh - 84px);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  align-items: center;
  gap: 32px;
}

h1,
h2 {
  margin: 0 0 12px;
  line-height: 1.16;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(34px, 5vw, 64px);
}

h2 {
  font-size: 22px;
}

p {
  margin: 0 0 10px;
  color: var(--muted);
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

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

.button.primary:hover {
  background: var(--accent-dark);
}

.button.danger {
  border-color: #fecdca;
  color: var(--danger);
}

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.status-board,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-board {
  display: grid;
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.status-board div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  background: var(--surface);
}

.status-board span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.status-board strong {
  font-size: 42px;
  line-height: 1;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.panel {
  padding: 24px;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: auto;
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.panel-footer {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
}

textarea {
  resize: vertical;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  border: 0;
  padding: 0;
}

.room-grid legend {
  grid-column: 1 / -1;
  margin-bottom: 4px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

.check {
  display: flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}

.check input {
  width: auto;
}

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

.rule-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.table-panel {
  padding: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.chip.approved {
  background: #ecfdf3;
  color: var(--success);
}

.chip.rejected,
.chip.issuing_failed,
.chip.cancel_failed,
.chip.failed {
  background: #fef3f2;
  color: var(--danger);
}

.chip.cancelled {
  background: #f2f4f7;
  color: #475467;
}

.chip.pending,
.chip.issuing {
  background: #fffaeb;
  color: var(--warning);
}

.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.timeline-panel {
  margin-bottom: 20px;
}

.timeline-scroll {
  overflow-x: auto;
}

.timeline-table {
  min-width: 1120px;
  table-layout: fixed;
}

.timeline-table th,
.timeline-table td {
  vertical-align: top;
}

.timeline-table thead th {
  background: #f8fafc;
}

.timeline-table th small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: none;
}

.timeline-room {
  width: 116px;
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
  text-transform: none;
}

.timeline-item {
  display: grid;
  gap: 2px;
  min-height: 70px;
  margin-bottom: 8px;
  border: 1px solid #bfdbfe;
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  padding: 8px;
  background: #eff6ff;
  color: var(--text);
  font-size: 12px;
}

.timeline-item strong {
  font-size: 12px;
}

.timeline-item span {
  font-weight: 800;
}

.timeline-item em {
  color: var(--muted);
  font-style: normal;
}

.timeline-item.own {
  outline: 2px solid #111827;
  outline-offset: 1px;
}

.timeline-item.pending,
.timeline-item.issuing {
  border-color: #fedf89;
  border-left-color: var(--warning);
  background: #fffaeb;
}

.timeline-item.approved {
  border-color: #a7f3d0;
  border-left-color: var(--success);
  background: #ecfdf3;
}

.timeline-item.rejected,
.timeline-item.issuing_failed,
.timeline-item.cancel_failed {
  border-color: #fecdca;
  border-left-color: var(--danger);
  background: #fef3f2;
}

.timeline-item.cancelled {
  border-color: #d0d5dd;
  border-left-color: #667085;
  background: #f2f4f7;
}

.timeline-empty {
  color: var(--muted);
  font-size: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}

.admin-actions {
  display: grid;
  gap: 18px;
}

.purpose-text {
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  color: var(--text);
}

.notice.warning {
  border-color: #fedf89;
  background: #fffaeb;
  color: var(--warning);
}

.log-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.log-list span,
.muted {
  color: var(--muted);
}

.confirmation {
  display: grid;
  gap: 18px;
}

dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-weight: 700;
}

dd {
  margin: 0;
}

.passcode {
  width: fit-content;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px 18px;
  background: #eff6ff;
  color: var(--accent-dark);
  font-size: 42px;
  font-weight: 850;
  letter-spacing: 0.08em;
}

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

.passcode-list div,
.code-pill {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 14px;
  background: #eff6ff;
  color: var(--accent-dark);
}

.passcode-list strong {
  font-size: 30px;
  letter-spacing: 0.08em;
}

.code-pill {
  margin: 2px 4px 2px 0;
  font-size: 13px;
  font-weight: 800;
}

.notice {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px;
  background: #eff6ff;
  color: var(--accent-dark);
}

.mail-list {
  display: grid;
  gap: 14px;
}

.mail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mail-item header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.mail-item header span,
.mail-item p {
  color: var(--muted);
}

.mail-item pre {
  overflow-x: auto;
  white-space: pre-wrap;
  border-radius: 8px;
  padding: 12px;
  background: #f2f4f7;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.admin-body {
  min-height: 100vh;
  background: #f7f8fb;
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 68px;
  border-bottom: 1px solid #e4e7ec;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.admin-brand {
  color: #101828;
  font-size: 20px;
  font-weight: 850;
}

.admin-userbar {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #344054;
  font-size: 14px;
  font-weight: 750;
}

.admin-notice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #344054;
}

.admin-notice span,
.admin-sidebar em {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-style: normal;
  font-weight: 850;
}

.admin-avatar {
  border-left: 1px solid var(--line);
  padding-left: 14px;
}

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

.admin-frame {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}

.admin-sidebar {
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid #e4e7ec;
  padding: 12px;
  background: #fff;
}

.admin-sidebar nav {
  display: grid;
  gap: 4px;
  color: #344054;
  font-size: 14px;
}

.admin-sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 10px;
}

.admin-sidebar a.active {
  background: var(--accent);
  color: white;
}

.admin-sidebar a span {
  width: 20px;
  text-align: center;
}

.admin-sidebar a strong {
  flex: 1;
  font-size: 13px;
}

.admin-mobile-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: #344054;
  font-size: 13px;
}

.admin-main {
  width: min(100%, 1360px);
  padding: 12px 18px 32px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.admin-stats article,
.admin-card {
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.04);
}

.admin-stats article {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.admin-stats span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.admin-stats strong {
  font-size: 28px;
  line-height: 1;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 1.15fr);
  gap: 12px;
  align-items: start;
}

.admin-card {
  overflow: hidden;
}

.admin-card h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.admin-card p {
  margin: 0;
  font-size: 13px;
}

.admin-span {
  grid-column: 1 / -1;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #e4e7ec;
  padding: 14px 16px;
}

.text-link {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

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

.compact-table {
  min-width: 680px;
}

.compact-table th,
.compact-table td {
  padding: 12px 14px;
  font-size: 13px;
}

.compact-table th {
  background: #fcfcfd;
  color: #475467;
  text-transform: none;
}

.device-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid #e4e7ec;
  border-bottom: 1px solid #e4e7ec;
  padding: 12px 16px;
  color: #344054;
  font-size: 13px;
}

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

.battery-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.battery-badge.good {
  background: #ecfdf3;
  color: #067647;
}

.battery-badge.warning {
  background: #fffaeb;
  color: #b54708;
}

.battery-badge.low {
  background: #fef3f2;
  color: #b42318;
}

.battery-badge.unknown {
  background: #f2f4f7;
  color: #667085;
}

.day-timeline {
  position: relative;
  overflow-x: auto;
  padding: 0 16px 18px;
}

.day-scale,
.day-row {
  display: grid;
  grid-template-columns: 136px minmax(760px, 1fr);
}

.day-scale {
  align-items: center;
  height: 42px;
  color: var(--muted);
  font-size: 12px;
}

.day-scale span:not(:first-child) {
  display: inline-block;
  width: 20%;
}

.day-scale span:first-child + span {
  margin-left: 0;
}

.day-scale {
  grid-template-columns: 136px repeat(5, 1fr);
}

.day-row {
  min-height: 74px;
  border-top: 1px solid #edf0f4;
}

.day-room {
  display: grid;
  align-content: center;
  border-right: 1px solid #edf0f4;
  padding-right: 12px;
}

.day-room strong {
  font-size: 13px;
}

.day-room span {
  color: var(--muted);
  font-size: 11px;
}

.day-lane {
  position: relative;
  min-width: 760px;
  background:
    linear-gradient(to right, #edf0f4 1px, transparent 1px) 0 0 / 20% 100%,
    #fff;
}

.day-event {
  position: absolute;
  top: 12px;
  display: grid;
  gap: 2px;
  min-width: 88px;
  min-height: 48px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 6px 8px;
  overflow: hidden;
  color: #1f2937;
  font-size: 12px;
}

.day-event strong,
.day-event span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.day-event.success,
.legend-success {
  background: #ecfdf3;
  border-color: #a7f3d0;
}

.day-event.warning,
.legend-warning {
  background: #fffaeb;
  border-color: #fedf89;
}

.day-event.danger {
  background: #fef3f2;
  border-color: #fecdca;
}

.day-event.muted,
.legend-muted {
  background: #f2f4f7;
  border-color: #d0d5dd;
}

.day-event.info {
  background: #eff6ff;
}

.day-empty {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding-left: 12px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.timeline-legend i {
  width: 12px;
  height: 12px;
  border: 1px solid;
  border-radius: 3px;
}

.now-line {
  position: absolute;
  top: 42px;
  bottom: 18px;
  width: 1px;
  margin-left: 136px;
  background: #ef4444;
  pointer-events: none;
}

.now-line span {
  position: absolute;
  bottom: -16px;
  left: -24px;
  color: #ef4444;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.placeholder-card {
  padding: 16px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .hero,
  .two-column,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
    padding-top: 24px;
  }

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

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

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 34px;
  }

  .passcode {
    width: 100%;
    text-align: center;
    font-size: 36px;
  }

  .admin-topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    height: auto;
    padding: 12px 16px;
  }

  .admin-userbar {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .admin-avatar {
    margin-left: auto;
    border-left: 0;
    padding-left: 0;
  }

  .admin-frame {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-sidebar nav {
    display: flex;
    overflow-x: auto;
  }

  .admin-sidebar a {
    flex: 0 0 auto;
  }

  .admin-mobile-card {
    display: none;
  }

  .admin-main {
    padding: 12px;
  }

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

  .admin-stats article {
    padding: 12px;
  }

  .admin-stats strong {
    font-size: 24px;
  }

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

  .admin-span {
    grid-column: auto;
  }

  .device-list-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-card > .table-scroll,
  .table-panel.table-scroll {
    overflow-x: visible;
  }

  .mobile-card-table {
    width: 100%;
    min-width: 0;
  }

  .mobile-card-table thead {
    display: none;
  }

  .mobile-card-table tbody,
  .mobile-card-table tr,
  .mobile-card-table td {
    display: block;
    width: 100%;
  }

  .mobile-card-table tr {
    width: auto;
    margin: 10px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .mobile-card-table td {
    display: grid;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid #eef0f3;
    padding: 10px 12px;
    overflow-wrap: anywhere;
  }

  .mobile-card-table td:last-child {
    border-bottom: 0;
  }

  .mobile-card-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
  }

  .mobile-card-table td[colspan] {
    display: block;
    text-align: center;
  }

  .mobile-card-table td[colspan]::before {
    content: none;
  }

  .mobile-card-table input:not([type="checkbox"]) {
    width: 100%;
    min-width: 0;
  }

  .mobile-card-table .table-actions {
    display: grid;
    grid-template-columns: minmax(92px, 34%) repeat(2, minmax(0, 1fr));
  }
}
