:root {
  --bg: #f5f6f8; --card: #fff; --line: #e5e7eb; --line2: #eef0f3;
  --ink: #111827; --ink2: #374151; --muted: #6b7280; --faint: #9ca3af;
  --side: #111827; --side-ink: #cbd5e1; --side-active: #1d4ed8;
  --blue: #2563eb; --blue-soft: #eff6ff; --green: #16a34a; --green-soft: #ecfdf3;
  --orange: #f59e0b; --orange-ink: #b45309; --orange-soft: #fffbeb;
  --red: #dc2626; --red-soft: #fef2f2; --purple: #7c3aed; --gray-soft: #f3f4f6;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.04);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink); font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 0 0 10px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; } .faint { color: var(--faint); }
.right { text-align: right; } .nowrap { white-space: nowrap; } .mono { font-family: ui-monospace, Consolas, monospace; }
.green { color: var(--green); } .blue { color: var(--blue); } .orange { color: var(--orange-ink); } .red { color: var(--red); } .purple { color: var(--purple); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 26px 16px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { color: #fff; font-weight: 800; font-size: 21px; letter-spacing: .04em; padding: 0 12px; }
.brand small { display: block; font-size: 10px; font-weight: 400; color: #94a3b8; letter-spacing: 0; margin-top: 3px; }
.nav { margin-top: 34px; display: flex; flex-direction: column; gap: 6px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 8px; color: var(--side-ink); font-size: 14px; }
.nav a::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #64748b; }
.nav a:hover { background: #1f2937; text-decoration: none; }
.nav a.active { background: var(--side-active); color: #fff; }
.nav a.active::before { background: #fff; }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.side-foot { margin-top: auto; font-size: 11px; color: #64748b; padding: 0 12px; }
.side-foot .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #64748b; margin-right: 6px; }
.side-foot .dot.on { background: #22c55e; }
.main { padding: 26px 34px 60px; min-width: 0; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.head .sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.tools { display: flex; gap: 10px; align-items: center; }
.tools input.search { width: 190px; }
.me { position: relative; }
.me > button { min-width: 44px; }
.menu { position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.08); min-width: 220px; z-index: 30; padding: 6px; }
.menu .who { padding: 10px 12px; border-bottom: 1px solid var(--line2); margin-bottom: 4px; }
.menu button { width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 6px; }
.menu button:hover { background: var(--gray-soft); }
.mobile-bar { display: none; }

/* ---------- cards & grids ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 20px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-wide { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 20px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 700; margin: 10px 0 4px; letter-spacing: -.01em; }
.kpi .note { font-size: 11.5px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

/* ---------- forms ---------- */
label.f { display: block; font-size: 12px; color: var(--muted); }
label.f > span { display: block; margin-bottom: 7px; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; width: 100%; outline: none; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
input[type=checkbox] { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 40px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink2); }
button, .btn { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; display: inline-flex; align-items: center; gap: 6px; justify-content: center; text-decoration: none; }
button:hover, .btn:hover { background: var(--gray-soft); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.primary:hover { background: #1d4ed8; }
.soft { background: var(--blue-soft); border-color: #dbeafe; color: var(--blue); }
.danger { color: var(--red); border-color: #fecaca; }
.danger:hover { background: var(--red-soft); }
.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.link { border: 0; background: none; color: var(--blue); padding: 0; }
.link:hover { background: none; text-decoration: underline; }
.btn-lg { padding: 13px 28px; min-width: 200px; }
.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
.t th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 0 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 14px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: #fafbfc; }
.t .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- badges, pills, tabs ---------- */
.badge { display: inline-block; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--gray-soft); color: var(--ink2); white-space: nowrap; }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.orange { background: var(--orange-soft); color: var(--orange-ink); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.purple { background: #f5f3ff; color: var(--purple); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; border-radius: 0; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pills button.on { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- bed map ---------- */
.legend { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.legend .item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.occupied { background: var(--green); } .dot.available { background: var(--blue); } .dot.booked { background: var(--orange); }
.dot.sensor_issue { background: var(--red); } .dot.blocked { background: #6b7280; } .dot.maintenance { background: var(--purple); }
.beds { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 26px; }
.bed { border: 1px solid var(--line); border-radius: 10px; padding: 14px 14px 12px; background: #fff; cursor: pointer; position: relative; transition: box-shadow .15s, border-color .15s; }
.bed:hover { border-color: #c7d2fe; box-shadow: 0 2px 10px rgba(37,99,235,.08); }
.bed .code { font-weight: 700; font-size: 13.5px; font-family: ui-monospace, Consolas, monospace; }
.bed .st { font-size: 11.5px; margin: 8px 0 6px; }
.bed .ty { font-size: 10.5px; color: var(--muted); }
.bed .guest { font-size: 11px; color: var(--ink2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bed .flag { position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.bed.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px rgba(37,99,235,.45); } 100% { box-shadow: none; } }
.st.occupied { color: var(--green); } .st.available { color: var(--blue); } .st.booked { color: var(--orange-ink); }
.st.sensor_issue { color: var(--red); } .st.blocked { color: #4b5563; } .st.maintenance { color: var(--purple); }
.bed-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 26px; }
.chip { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; text-align: left; display: block; }
.chip .c { font-size: 13px; } .chip .s { font-size: 10.5px; margin-top: 4px; }
.chip.sel { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.chip:disabled { opacity: .6; }

/* ---------- charts ---------- */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 210px; padding: 0 8px; }
.bars .b { flex: 1; background: var(--blue); border-radius: 2px 2px 0 0; min-height: 2px; position: relative; }
.bars .b:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, -6px); background: #111827; color: #fff; font-size: 11px; padding: 4px 7px; border-radius: 5px; white-space: nowrap; z-index: 2; }
.bars-x { display: flex; gap: 12px; padding: 10px 8px 0; font-size: 10.5px; color: var(--muted); }
.bars-x span { flex: 1; text-align: center; overflow: hidden; }
.hbar { margin-bottom: 26px; }
.hbar .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.hbar .track { height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--blue); }
.floor-row { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 18px 0; font-size: 13.5px; }

/* ---------- usage timeline ---------- */
.usage-box { background: var(--green-soft); border: 1px solid #bbf7d0; border-radius: 10px; padding: 16px 20px; }
.usage-box .big { font-size: 26px; font-weight: 700; color: var(--green); }
.timeline { position: relative; height: 10px; background: var(--line); border-radius: 5px; margin: 26px 12px 8px; }
.timeline .seg { position: absolute; top: 0; height: 100%; background: #86efac; border-radius: 5px; }
.timeline .pin { position: absolute; top: 50%; width: 14px; height: 18px; border-radius: 7px; transform: translate(-50%, -50%); }
.timeline-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 0 4px; }
.lines .l { display: grid; grid-template-columns: 1fr 120px 110px; padding: 13px 0; font-size: 13.5px; }
.lines .l .d { color: var(--muted); font-size: 12.5px; }
.lines .l .a { text-align: right; font-variant-numeric: tabular-nums; }
.total { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line); padding-top: 18px; margin-top: 8px; }
.total b { font-size: 17px; } .total .amt { font-size: 22px; font-weight: 700; color: var(--blue); }

/* ---------- drawer, modal, toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(17,24,39,.35); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 760px; }
.modal h2 { margin-bottom: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal .err { color: var(--red); font-size: 13px; margin-top: 12px; }
.drawer-bg { position: fixed; inset: 0; background: rgba(17,24,39,.25); z-index: 35; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: 420px; max-width: 100%; background: #fff; z-index: 36; box-shadow: -10px 0 30px rgba(0,0,0,.1); padding: 24px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13px; }
.kv > :nth-child(odd) { color: var(--muted); }
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13px; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--red); } .toast.ok { background: var(--green); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: 100%; max-width: 470px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 46px 58px 54px; }
.login .logo { text-align: center; color: var(--blue); font-size: 32px; font-weight: 800; letter-spacing: .04em; }
.login .tag { text-align: center; color: var(--muted); font-size: 13px; margin: 10px 0 50px; }
.login form > * + * { margin-top: 20px; }
.login button.primary { width: 100%; padding: 14px; margin-top: 32px; }
.login .forgot { text-align: center; font-size: 12px; margin-top: 30px; color: var(--muted); }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.perm-grid fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0; }
.perm-grid legend { font-size: 12px; font-weight: 600; padding: 0 6px; }
.perm-grid .check { margin: 6px 0; font-size: 12.5px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-wide, .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .mobile-bar { display: flex; align-items: center; gap: 12px; background: var(--side); color: #fff; padding: 12px 16px; position: sticky; top: 0; z-index: 20; }
  .mobile-bar button { background: none; color: #fff; border-color: #374151; }
  .main { padding: 18px 16px 50px; }
  .head { flex-direction: column; }
  .tools input.search { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .beds { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .login { padding: 34px 24px; }
  .lines .l { grid-template-columns: 1fr 70px 90px; }
}
