:root {
  --bg: #faf9fa;
  --surface: #ffffff;
  --border: #ede8eb;
  --text: #593f52;
  --muted: #715e6b;
  --primary: #63455b;
  --primary-hover: #593f52;
  --danger: #873f4b;
  --warning: #834327;
  --info: #63455b;
  --purple: #63455b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.board-status-filter { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.board-status-filter label { font-size: 0.85rem; font-weight: 600; }
.ticket-menu { width: auto; max-width: 100%; padding: 4px 7px; font-size: 0.8rem; }
.ticket-card.ticket-compact { padding: 8px 10px; display: grid; gap: 5px; }
.ticket-compact-line { display: flex; align-items: baseline; gap: 7px; overflow-wrap: anywhere; }
.ticket-compact .ticket-number { font-size: 1rem; }
.ticket-compact .ticket-number:hover { cursor: default; color: var(--text); text-decoration: none; }
.ticket-compact-footer { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 4px; }
.board-grid.board-grid-filtrado { grid-template-columns: minmax(0, 430px); }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #593f52; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover { background: #593f52; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #743f52; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #873f4b; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #faf9fa; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: #ede8eb; }

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.92rem;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(99, 69, 91, 0.25);
  border-color: var(--primary);
}

.select-compact { width: auto; min-width: 165px; padding: 6px 10px; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: #593f52; }
.checkbox-group { justify-content: flex-end; }
.checkbox-label { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: auto; }

/* Auth */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(89, 63, 82, 0.08);
}

.brand-header { text-align: center; margin-bottom: 22px; }
.brand-header h1 { margin: 8px 0 4px; font-size: 1.45rem; }
.brand-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form h2 { margin: 0; font-size: 1.15rem; }
.auth-links { text-align: center; margin-top: 4px; }

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left, .topbar-center, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title { display: block; font-size: 1rem; }
.topbar-sub { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }

.nav-tabs { display: flex; gap: 6px; }
.tab-btn {
  border: 1px solid var(--border);
  background: #faf9fa;
  padding: 7px 12px;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.sync-badge {
  font-size: 0.78rem;
  color: var(--primary);
  background: #fceae9;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 600;
}

.main-content { padding: 18px 20px; max-width: 1600px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-header-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-header-inline h2, .card-header-inline h3 { margin: 0; font-size: 1.05rem; }

.reception-form {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto auto;
  gap: 12px;
  align-items: end;
}

/* Board */
.board-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}

.board-col {
  background: #ede8eb;
  border-radius: var(--radius);
  padding: 10px;
  min-height: 320px;
}

.board-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  color: #fff;
  margin-bottom: 10px;
}
.board-col-header h3 { margin: 0; font-size: 0.95rem; }
.col-abertura { background: #593f52; }
.col-aguardando { background: var(--info); }
.col-enfermagem { background: var(--primary); }
.col-medico { background: var(--purple); }

.count-badge {
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.card-list { display: flex; flex-direction: column; gap: 10px; }

.ticket-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(89, 63, 82, 0.05);
}

.ticket-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ticket-number {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
}
.ticket-number:hover { color: var(--primary); text-decoration: underline; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}
.pill-role { background: #f0edef; color: #593f52; }
.pill-triagem { background: #f7e2da; color: #834327; }
.pill-consulta { background: #fceae9; color: #593f52; }
.pill-medico { background: #e7dce5; color: #593f52; }
.pill-done { background: #ede8eb; color: #593f52; }
.pill-cancel { background: #fceae9; color: #873f4b; }
.pill-old { background: #f7e2da; color: #834327; }

.ticket-meta { font-size: 0.84rem; color: #593f52; display: flex; flex-direction: column; gap: 2px; }
.ticket-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.ticket-actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 4px; border-top: 1px dashed #ede8eb; }

.finished-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
}

/* Admin */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stacked-form { display: flex; flex-direction: column; gap: 12px; }
.inline-local-form { display: grid; grid-template-columns: 110px 1fr 130px auto; gap: 8px; margin-bottom: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #ede8eb; }
th { background: #faf9fa; font-weight: 700; color: #593f52; }

.alert-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fceae9;
  border: 1px solid #b6a5b1;
  font-size: 0.85rem;
  word-break: break-all;
}

.report-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.stat-box {
  min-width: 170px;
  background: #faf9fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.stat-box strong { display: block; font-size: 1.35rem; margin-top: 4px; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(89, 63, 82, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 12px;
  padding: 18px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-lg { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h3 { margin: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.timeline { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.timeline li {
  border-left: 3px solid var(--primary);
  padding: 4px 10px;
  background: #faf9fa;
  border-radius: 0 6px 6px 0;
  font-size: 0.86rem;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}
.toast {
  background: #593f52;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary); }

@media (max-width: 1150px) {
  .board-grid { grid-template-columns: repeat(2, 1fr); }
  .reception-form { grid-template-columns: 1fr 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .board-grid { grid-template-columns: 1fr; }
  .reception-form { grid-template-columns: 1fr; }
  .inline-local-form { grid-template-columns: 1fr; }
}
