:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --sidebar: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #4f46e5;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: .95rem; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  display: grid;
  place-items: center;
  font-size: 1.05rem;
}

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

.nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--sidebar-text);
  font-size: .93rem;
  text-align: left;
  transition: background .15s, color .15s;
}

.nav button:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav button.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: #fff;
  font-size: .88rem;
}

.user-chip .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .9rem;
  color: #fff;
}

.user-chip small { display: block; color: var(--sidebar-text); font-size: .76rem; }

.logout-btn {
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px;
  background: transparent;
  color: #fda4af;
  font-size: .85rem;
}

.logout-btn:hover { background: rgba(220,38,38,.15); }

.pass-btn {
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px;
  background: transparent;
  color: #93c5fd;
  font-size: .85rem;
}

.pass-btn:hover { background: rgba(79,70,229,.25); }

.main { flex: 1; padding: 28px 32px; max-width: 1200px; }

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

.page-header h1 { font-size: 1.45rem; font-weight: 700; }
.page-header .sub { color: var(--text-muted); font-size: .9rem; margin-top: 2px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 { font-size: 1.05rem; margin-bottom: 14px; font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ---------- Room status card ---------- */
.room-card { padding: 22px; border-left: 6px solid var(--border); }
.room-card.free { border-left-color: var(--success); }
.room-card.occupied { border-left-color: var(--danger); }

.room-card .room-top { display: flex; align-items: center; justify-content: space-between; }
.room-card h3 { font-size: 1.1rem; }
.room-card .room-icon { font-size: 1.6rem; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
}

.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.status-pill.free { background: var(--success-bg); color: var(--success); }
.status-pill.occupied { background: var(--danger-bg); color: var(--danger); }
.status-pill.busy { background: var(--warning-bg); color: var(--warning); }

.occupied-banner {
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-info { margin-top: 14px; color: var(--text-muted); font-size: .92rem; }
.room-info strong { color: var(--text); }
.room-next { margin-top: 10px; font-size: .88rem; }

/* ---------- Clock ---------- */
.clock { text-align: right; }
.clock .time { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock .date { color: var(--text-muted); font-size: .9rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #f8fafc; }
td .tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.tag.admin { background: #ede9fe; color: #6d28d9; }
.tag.professor { background: #dbeafe; color: #1d4ed8; }
.tag.aluno { background: #ccfbf1; color: #0f766e; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 9px;
  font-size: .9rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--danger); background: var(--danger-bg); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.form-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 14px;
  border-radius: 9px;
  font-size: .9rem;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.alert.error { background: var(--danger-bg); color: #991b1b; }
.alert.success { background: var(--success-bg); color: #166534; }
.alert.info { background: #e0f2fe; color: #0c4a6e; }
.alert .close { background: none; border: none; font-size: 1rem; color: inherit; cursor: pointer; }

/* ---------- Reservation list ---------- */
.res-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.res-item:last-child { border-bottom: none; }
.res-item .time-block { text-align: center; min-width: 74px; }
.res-item .time-block .t { font-weight: 700; font-size: .95rem; }
.res-item .time-block .sep { color: var(--text-muted); font-size: .8rem; }
.res-item .res-body { flex: 1; }
.res-item .res-body .res-title { font-weight: 600; font-size: .93rem; }
.res-item .res-body .res-meta { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }
.res-item .room-badge {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: .75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.res-item.now { background: var(--primary-light); border-radius: 9px; padding: 12px; border-bottom: none; }

.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); }
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #312e81 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card .logo { width: 56px; height: 56px; border-radius: 14px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 1.6rem; margin-bottom: 16px; }
.login-card h1 { font-size: 1.35rem; margin-bottom: 4px; }
.login-card p { color: var(--text-muted); font-size: .9rem; margin-bottom: 24px; }
.login-hint { margin-top: 18px; background: var(--primary-light); padding: 10px 12px; border-radius: 9px; font-size: .78rem; color: var(--primary-dark); text-align: center; }

.notice {
  background: var(--warning-bg);
  color: #92400e;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: .84rem;
  margin-top: 14px;
}

.tag.solicitada { background: var(--warning-bg); color: var(--warning); }

/* ---------- Charts (CSS bars) ---------- */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bar-track { width: 100%; max-width: 42px; background: #f1f5f9; border-radius: 6px; height: 100%; display: flex; align-items: flex-end; overflow: hidden; }
.chart .bar { width: 100%; background: var(--primary); border-radius: 6px; min-height: 3px; transition: height .4s; }
.chart .bar.alt { background: #10b981; }
.chart .bar-label { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }
.chart .bar-value { font-size: .76rem; font-weight: 700; }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .stat-cards { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stat .stat-label { color: var(--text-muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-size: 1.7rem; font-weight: 700; margin-top: 6px; }
.stat .stat-sub { color: var(--text-muted); font-size: .8rem; margin-top: 2px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: grid; place-items: center; padding: 20px; z-index: 100;
}
.modal { background: #fff; border-radius: 14px; padding: 26px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { font-size: 1.15rem; margin-bottom: 18px; }

.day-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.day-nav .day-label { font-weight: 700; font-size: 1rem; min-width: 220px; text-align: center; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.print-header { display: none; }
.print-tickets { display: none; }

@media print {
  @page { size: A4; margin: 1.5cm; }

  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .sidebar, .page-header, .toolbar, #alert-zone, .modal-backdrop, .btn { display: none !important; }
  .print-hide { display: none !important; }

  .main { padding: 0; max-width: none; }

  .print-header {
    display: block;
    text-align: center;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 14px;
  }
  .print-school { font-size: .85rem; color: var(--text-muted); font-weight: 600; }
  .print-title { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
  .print-period { font-size: .9rem; color: var(--text-muted); margin-top: 2px; }

  .print-tickets { display: block; }
  .print-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
  .print-table th, .print-table td { border: 1px solid #cbd5e1; padding: 6px 8px; text-align: left; vertical-align: top; }
  .print-table th { background: #f1f5f9; }
  .print-table td { word-break: break-word; }
  .print-footer { margin-top: 12px; font-size: .85rem; color: var(--text-muted); }
  .print-empty { font-size: .9rem; color: var(--text-muted); }

  .card { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; margin-bottom: 14px; }
  .grid-2, .grid-3, .stat-cards { break-inside: avoid; }

  .chart .bar, .status-pill, .tag, .room-card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .nav { flex-direction: row; margin: 0; }
  .nav button { width: auto; }
  .sidebar-footer { margin: 0 0 0 auto; display: flex; align-items: center; gap: 10px; border: none; }
  .logout-btn, .pass-btn { width: auto; margin: 0; }
  .user-chip { display: none; }
  .main { padding: 20px 16px; }
}

/* ---------- ApoioTIC · Tickets ---------- */
.ticket-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.ticket-item:last-child { border-bottom: none; }
.ticket-item:hover { background: #f8fafc; border-radius: 9px; }
.ticket-item .ticket-main { min-width: 0; }
.ticket-item .ticket-title { font-weight: 600; font-size: .95rem; }
.ticket-item .ticket-id { color: var(--text-muted); font-size: .78rem; font-weight: 600; }
.ticket-item .ticket-meta { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }
.ticket-item .ticket-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.tag.cat { background: var(--primary-light); color: var(--primary-dark); }
.tag.prio-baixa { background: var(--success-bg); color: var(--success); }
.tag.prio-media { background: var(--warning-bg); color: var(--warning); }
.tag.prio-alta { background: var(--danger-bg); color: var(--danger); }
.tag.st-novo { background: #e2e8f0; color: #334155; }
.tag.st-em_curso { background: #dbeafe; color: #1d4ed8; }
.tag.st-resolvido { background: var(--success-bg); color: var(--success); }

.ticket-detail .td-title { font-size: 1.1rem; margin-bottom: 10px; }
.ticket-detail .td-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.ticket-detail .td-requester { color: var(--text-muted); font-size: .84rem; margin-bottom: 12px; }
.ticket-detail .td-room { color: var(--text-muted); font-size: .84rem; margin-bottom: 12px; }
.ticket-detail .td-desc {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  font-size: .92rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 14px;
}

.ticket-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }

.td-comments h4 { font-size: .95rem; margin-bottom: 10px; }
.td-comments .comment {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 8px;
  background: #fff;
}
.td-comments .comment-head { font-weight: 600; font-size: .82rem; }
.td-comments .comment-date { color: var(--text-muted); font-weight: 400; }
.td-comments .comment-body { font-size: .9rem; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }

.comment-box { margin-top: 12px; }
.comment-box textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: .9rem;
  margin-bottom: 8px;
  resize: vertical;
}
.comment-box textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
