:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #65717e;
  --line: #d9e0e7;
  --accent: #0f766e;
  --accent-2: #b45309;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }
/* honor the hidden attribute even on elements with an explicit display rule
   (form/label use display:grid which would otherwise override [hidden]) */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 18px 14px;
}

.brand {
  display: grid;
  gap: 4px;
  margin-bottom: 22px;
}

.brand span {
  color: #aeb8c4;
  font-size: 13px;
}

.nav {
  width: 100%;
  border: 0;
  background: transparent;
  color: #d7dee8;
  text-align: left;
  padding: 11px 12px;
  border-radius: 6px;
  margin-bottom: 5px;
  cursor: pointer;
  font: inherit;
}

.nav.active, .nav:hover {
  background: #243041;
  color: #fff;
}

main {
  padding: 22px;
  overflow: auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 16px; margin-bottom: 14px; }
p { color: var(--muted); margin-top: 4px; }

.lock {
  border: 1px solid var(--line);
  background: #ecfdf5;
  color: #047857;
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.view { display: none; }
.view.active { display: block; }

.toolbar, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

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

input, select, button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  background: white;
}

button {
  cursor: pointer;
  font-weight: 750;
}

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

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  font-size: 24px;
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

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

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 120px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar {
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--accent);
}

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

.wide { grid-column: 1 / -1; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check input { min-height: 0; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.answer {
  margin-top: 14px;
  padding: 14px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  min-height: 52px;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #111827;
  color: white;
  padding: 10px 12px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(8px);
  transition: .2s;
}
#toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* sidebar footer: who am I + logout */
.sidebar-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #243041;
  display: grid;
  gap: 8px;
}
.who { display: grid; gap: 2px; }
.who span { font-weight: 700; font-size: 14px; }
.who small { color: #aeb8c4; font-size: 12px; }
.logout {
  background: #243041;
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 9px;
}
.logout:hover { background: #31415a; }

/* header right cluster */
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.branch-chip {
  background: #0f766e;
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}
.branch-switch { min-height: 38px; }

/* calendar */
.cal-toolbar { gap: 8px; }
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12px;
}
.cal-legend .lg {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 700;
}
.lg-offline { background: #ecfdf5; color: #047857; }
.lg-rdz { background: #fef2f2; color: #b91c1c; }
.lg-checkin { background: #0f766e; color: #fff; }
.lg-reserved { background: #e0f2fe; color: #075985; }
.lg-checkout { background: #fef3c7; color: #92400e; }
.lg-out { background: #e5e7eb; color: #4b5563; }
.lg-conflict { background: #fde68a; color: #92400e; }

.cal-panel { padding: 0; overflow: hidden; }
.cal-grid-wrap { overflow: auto; max-height: 72vh; }
.cal-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}
.cal-table th, .cal-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.cal-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  font-size: 11px;
  text-align: center;
  padding: 6px 4px;
  line-height: 1.25;
  text-transform: none;
}
.cal-room-head, .cal-room {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  min-width: 92px;
  text-align: left;
  padding: 6px 10px;
}
.cal-room-head { z-index: 4; }
.cal-room { font-weight: 800; }
.cal-room small { display: block; color: var(--muted); font-weight: 600; font-size: 10px; }
.cal-date { min-width: 78px; }

.cal-cell { width: 80px; height: 44px; padding: 2px; vertical-align: top; }
.cal-cell.vacant { cursor: pointer; }
.cal-cell.vacant:hover { background: #f0fdfa; box-shadow: inset 0 0 0 2px #99f6e4; }
.cal-cell.occupied { cursor: pointer; }
.cal-cell .bar {
  height: 100%;
  border-radius: 5px;
  padding: 3px 5px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.15;
  border-left: 4px solid transparent;
}
.cal-cell .bar b { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-cell .badge { font-weight: 800; font-size: 9px; opacity: .8; }
.cal-cell .bar em { font-style: normal; font-size: 9px; }
.cal-cell .due { color: #b91c1c; font-weight: 700; }
.cal-cell .paid { color: #047857; font-weight: 700; }
.cal-cell .park { color: #1d4ed8; font-weight: 800; }
.cal-cell .more { color: #92400e; font-weight: 800; }

/* blocked / drag */
.cal-cell.blocked { cursor: pointer; }
.cal-cell.blocked .bar {
  background: repeating-linear-gradient(45deg, #e5e7eb, #e5e7eb 6px, #d1d5db 6px, #d1d5db 12px);
  color: #4b5563;
  border-left-color: #6b7280;
}
.cal-cell.blocked .bar em { color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-cell.occupied { cursor: grab; }
.cal-cell.occupied:active { cursor: grabbing; }
.cal-cell.drop-hover { background: #cffafe; box-shadow: inset 0 0 0 2px #06b6d4; }
.cal-hint { font-size: 12px; margin: 0 0 10px; color: var(--muted); }
.full-note { grid-column: 1 / -1; margin: 0 0 4px; }

/* buttons */
.danger-btn { background: var(--danger); color: #fff; border-color: var(--danger); }
.danger-btn:hover { filter: brightness(1.08); }
.link-btn { border: 0; background: transparent; color: var(--accent); font-weight: 700; padding: 0; min-height: 0; text-decoration: underline; cursor: pointer; }
.adjust-actions { display: flex; gap: 10px; }

/* segmented toggle + panel head */
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.panel-head h2 { margin-bottom: 0; }
.muted-note { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #eef2f6; }
.seg-btn { border: 0; background: transparent; padding: 7px 18px; min-height: 32px; border-radius: 0; font-weight: 750; color: var(--muted); }
.seg-btn.active { background: var(--accent); color: #fff; }

/* polish pass */
.panel, .toolbar, .kpi {
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
}
.kpi { border-left: 3px solid var(--accent); }
.nav.active { box-shadow: inset 3px 0 0 var(--accent); }
.branch-chip { box-shadow: 0 1px 2px rgba(15, 118, 110, .25); }
.primary:hover { filter: brightness(1.06); }
header h1 { letter-spacing: -.2px; }

/* source accent */
.src-offline .bar { border-left-color: #0f766e; }
.src-rdz .bar { border-left-color: #b91c1c; }
.src-ota .bar { border-left-color: #b45309; }
/* state fill */
.st-reserved .bar { background: #e0f2fe; }
.st-checked-in .bar { background: #ccfbf1; }
.st-checkout .bar { background: #fef3c7; }
.st-checked-out .bar { background: #eef0f2; color: #6b7280; }
.st-conflict .bar { background: #fde68a; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: min(420px, 100%);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 22px;
  min-height: 0;
  cursor: pointer;
}
.modal-body { display: grid; gap: 8px; margin: 14px 0 18px; }
.mrow { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.mrow span { color: var(--muted); }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  grid-template-columns: none;
  background: #0f172a;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 30px;
  width: min(380px, 92vw);
}
.login-card .brand { margin-bottom: 16px; }
.login-card .brand strong { font-size: 20px; }
.login-card form { display: grid; gap: 14px; margin-top: 16px; }
.login-card .primary { margin-top: 6px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; font-weight: 700; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 5; display: flex; overflow: auto; gap: 6px; align-items: center; }
  .brand { min-width: 160px; margin: 0; }
  .nav { min-width: 130px; text-align: center; }
  .sidebar-foot { margin: 0; padding: 0 0 0 8px; border: 0; border-left: 1px solid #243041; grid-auto-flow: column; align-items: center; }
  header { align-items: start; flex-direction: column; }
  .kpis, .grid.two, .form-panel form { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 90px 1fr; }
  .bar-row strong { grid-column: 2; }
}
