:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e2e4e9;
  --primary: #c8102e; /* OCBC red */
  --primary-text: #ffffff;
  --free: #eef7ee;
  --free-border: #b9e3b9;
  --booked: #fdeceb;
  --booked-border: #f3b9b4;
  --danger: #c8102e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1e2126;
    --text: #edeef0;
    --muted: #9aa0a8;
    --border: #2c3038;
    --free: #16281a;
    --free-border: #2f5a37;
    --booked: #2e1a1a;
    --booked-border: #6a2c2c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: 2rem;
}

header {
  background: var(--primary);
  color: var(--primary-text);
  padding: 1rem 1.25rem;
}
header h1 { margin: 0; font-size: 1.25rem; }
header .sub { margin: 0.15rem 0 0; opacity: 0.9; font-size: 0.9rem; }

main { padding: 1rem; max-width: 900px; margin: 0 auto; }

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
.toolbar label { font-weight: 600; min-width: 3.5rem; }
.toolbar input[type="date"],
.toolbar select {
  min-height: 44px;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.status.error { background: var(--booked); color: var(--danger); }
.status.info { background: var(--free); color: #2e7d32; }
.status button {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  background: var(--card);
  border: 1px solid currentColor;
  color: inherit;
}

.grid-wrap {
  overflow: auto;
  max-height: 65vh;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}

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

th, td {
  border-bottom: 1px solid var(--border);
  padding: 0;
  text-align: center;
  font-size: 0.8rem;
}

thead th {
  padding: 0.5rem 0.4rem;
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 2;
}
.room-info {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

td:first-child, th:first-child {
  position: sticky;
  left: 0;
  background: var(--card);
  font-weight: 600;
  padding: 0.4rem;
  white-space: nowrap;
  border-right: 1px solid var(--border);
  z-index: 1;
}
thead th:first-child {
  z-index: 3;
}

.slot {
  cursor: pointer;
  padding: 0.5rem 0.3rem;
  min-width: 90px;
  height: 44px;
  vertical-align: top;
}
.slot.free { background: var(--free); }
.slot.free:hover { filter: brightness(0.97); }
.slot.booked { background: var(--booked); cursor: pointer; }
.slot.past { background: var(--bg); cursor: not-allowed; }
.slot:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.slot-add { color: #2e7d32; font-size: 0.72rem; font-weight: 600; }
.slot-title { font-weight: 600; display: block; overflow-wrap: break-word; }
.slot-by { color: var(--muted); font-size: 0.72rem; }
.slot-loading { padding: 1rem; text-align: center; color: var(--muted); }

.legend { font-size: 0.85rem; color: var(--muted); text-align: right; margin: 0 0 0.5rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.25rem; vertical-align: middle; }
.dot.free { background: var(--free-border); }
.dot.booked { background: var(--booked-border); }
.dot.past { background: var(--border); }

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(420px, 92vw);
  color: var(--text);
  background: var(--card);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog form { padding: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
dialog h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.muted { color: var(--muted); margin: 0 0 0.5rem; font-size: 0.9rem; }

dialog label { font-size: 0.85rem; font-weight: 600; margin-top: 0.4rem; }
dialog input, dialog select, dialog textarea {
  min-height: 44px;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
dialog textarea { min-height: 72px; }
.hint { color: var(--muted); font-size: 0.78rem; margin: 0.2rem 0 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

button { min-height: 44px; font-size: 0.95rem; padding: 0.55rem 1rem; border-radius: 8px; border: none; cursor: pointer; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }

.error { color: var(--danger); font-size: 0.85rem; margin: 0.25rem 0 0; }
