:root {
  --bg: #f3f5f9; --panel: #fff; --border: #e3e7ee; --text: #1c2333; --muted: #667085;
  --primary: #2563eb; --primary-dark: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --hour-h: 56px; --topbar: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---- Botões e formulários ---- */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: .45rem .8rem; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: #f7f8fb; border-color: #cfd5df; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c2c2; }
.btn.danger:hover { background: #fef2f2; }
.btn.ok { color: var(--ok); border-color: #b7e4c7; } .btn.ok:hover { background: #f0fdf4; }
.btn.sm { padding: .25rem .55rem; font-size: 12.5px; border-radius: 6px; }
.btn.icon { padding: .4rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.field label { font-size: 12.5px; font-weight: 600; color: #344054; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=month], select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid #d0d5dd; border-radius: 8px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.check { display: flex; align-items: center; gap: .5rem; font-size: 13.5px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: .25rem .7rem; cursor: pointer; user-select: none; background: #fff; font-size: 13px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.alert { padding: .6rem .8rem; border-radius: 8px; font-size: 13.5px; margin-bottom: .75rem; }
.alert.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ---- Layout ---- */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.auth .card { width: 100%; max-width: 400px; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; }

.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1rem; }
.nav { display: flex; gap: .15rem; overflow-x: auto; }
.nav a { color: #475467; padding: .45rem .7rem; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: #f2f4f7; }
.nav a.active { background: #eff6ff; color: var(--primary); }
.nav .badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 11px; text-align: center; margin-left: 4px; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
main { padding: 1rem; max-width: 1400px; margin: 0 auto; }
main.wide { max-width: none; }
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }

/* ---- Tabelas ---- */
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tr.sub td { background: #fafbfc; color: var(--muted); font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.tag.pending { background: #fef3c7; color: #92400e; }
.tag.confirmed { background: #dcfce7; color: #166534; }
.tag.cancelled { background: #f1f5f9; color: #64748b; text-decoration: line-through; }
.tag.approved { background: #dcfce7; color: #166534; }
.tag.blocked { background: #fee2e2; color: #991b1b; }
.tag.admin { background: #ede9fe; color: #5b21b6; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* ---- Calendário ---- */
.cal-toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.cal-toolbar .title { font-weight: 650; font-size: 1.05rem; min-width: 210px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: .4rem .7rem; cursor: pointer; }
.seg button.on { background: var(--primary); color: #fff; }
.legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.cal { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.cal-body { border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.cal-head { border-radius: var(--radius) var(--radius) 0 0; display: grid; grid-template-columns: 56px repeat(var(--cols), minmax(0, 1fr)); border-bottom: 1px solid var(--border); position: sticky; top: var(--topbar); background: #fff; z-index: 5; }
.cal-head > div { padding: .5rem .35rem; text-align: center; border-left: 1px solid var(--border); font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-head > div:first-child { border-left: 0; }
.cal-head .dnum { display: block; font-size: 17px; font-weight: 700; }
.cal-head .today .dnum { color: var(--primary); }
.cal-body { display: grid; grid-template-columns: 56px repeat(var(--cols), minmax(0, 1fr)); position: relative; }
.cal-times { position: relative; }
.cal-times div { height: var(--hour-h); font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.cal-col { position: relative; border-left: 1px solid var(--border); background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 100% var(--hour-h); }
.cal-col.closed { background-color: #f6f7f9; }
.cal-col.past-day { background-color: #fafafa; }
.cal-col .slot { position: absolute; left: 0; right: 0; cursor: pointer; }
.cal-col .slot:hover { background: rgba(37,99,235,.08); }
.cal-col .closed-band { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(45deg, #f1f3f6 0 6px, #f8f9fb 6px 12px); pointer-events: none; }
.evt { position: absolute; left: 2px; right: 3px; border-radius: 6px; padding: 3px 6px; font-size: 12px; overflow: hidden; cursor: pointer;
  color: #fff; border-left: 4px solid rgba(0,0,0,.25); box-shadow: 0 1px 2px rgba(0,0,0,.15); line-height: 1.3; }
.evt b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.evt .t { opacity: .9; font-size: 11px; }
.evt.pending { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.2) 0 6px, transparent 6px 12px); outline: 2px dashed rgba(255,255,255,.7); outline-offset: -3px; }
.evt.other { opacity: .55; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: #ef4444; z-index: 3; pointer-events: none; }
.now-line::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; }

/* ---- Página de salas ---- */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.room-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: .5rem; overflow: hidden; }
.room-card.inactive { opacity: .6; }
.room-head { margin: 0 -1rem; padding: .8rem 1rem .4rem; display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.room-head h3 { margin: 0 0 .15rem; font-size: 1.1rem; }
.room-facts { display: flex; gap: .9rem; flex-wrap: wrap; font-size: 13.5px; color: #344054; }
.room-am .chip { cursor: default; background: #f5f7fb; border-color: #e6eaf1; font-size: 12.5px; }
.room-notes { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: .5rem .7rem; font-size: 13px; color: #78350f; }
.space-card p { margin: .2rem 0; }
.prewrap { white-space: pre-wrap; }
#am .chip, #am-extra .chip { font-size: 12.5px; }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { padding: 1rem 1.25rem .5rem; display: flex; align-items: center; justify-content: space-between; }
.modal header h2 { margin: 0; }
.modal .body { padding: 0 1.25rem 1rem; }
.modal footer { padding: .75rem 1.25rem 1rem; display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--border); }
.modal footer .left { margin-right: auto; display: flex; gap: .5rem; }
.x { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: .3rem .75rem; margin-bottom: .75rem; }
.kv dt { color: var(--muted); font-size: 13px; } .kv dd { margin: 0; }

/* ---- Toast ---- */
#toast-root { position: fixed; bottom: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #1c2333; color: #fff; padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px; animation: up .2s ease; max-width: 360px; }
.toast.error { background: var(--danger); } .toast.ok { background: var(--ok); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---- Cards de estatística ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.stat .v { font-size: 1.5rem; font-weight: 700; } .stat .l { color: var(--muted); font-size: 12.5px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; align-items: start; }
.section { margin-bottom: 1.25rem; }
code { background: #f2f4f7; padding: .1rem .35rem; border-radius: 4px; font-size: 12.5px; word-break: break-all; }

@media (max-width: 720px) {
  .topbar { padding: 0 .5rem; gap: .5rem; }
  .brand span.name { display: none; }
  main { padding: .5rem; }
  .cal-head > div { font-size: 11px; padding: .35rem .1rem; }
  .cal-head .dnum { font-size: 14px; }
  .cal-body, .cal-head { grid-template-columns: 40px repeat(var(--cols), minmax(0, 1fr)); }
  .cal-times div { font-size: 10px; padding-right: 3px; }
  .evt { font-size: 10.5px; padding: 2px 3px; }
  .grid2 { grid-template-columns: 1fr; }
  .cal-toolbar .title { min-width: 0; font-size: .95rem; }
  .hide-m { display: none !important; }
}
