:root {
  --bg: #edf2f5;
  --surface: #fff;
  --line: #d4dde3;
  --text: #17232d;
  --muted: #687883;
  --blue: #1769aa;
  --blue-soft: #e8f2fb;
  --green: #177245;
  --green-soft: #e5f4ec;
  --amber: #9a5b00;
  --amber-soft: #fff4d9;
  --red: #b42318;
  --purple: #6b3fa0;
  --purple-soft: #f0e9f8;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }
button, input, select { font: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
.qms-page { min-height: 100vh; padding: 12px; }
.qms-header, .header-actions, .toolbar, .toolbar-actions, .panel-heading, .panel-heading > div, .dialog-heading, .dialog-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.qms-header { margin-bottom: 10px; }
h1 { margin: 0; font-size: 22px; }
.qms-subtitle { margin-top: 3px; color: var(--muted); }
.icon-btn, .command {
  min-height: 34px; border: 1px solid #aebbc5; border-radius: 5px; background: #fff; color: var(--text); cursor: pointer;
}
.icon-btn { width: 34px; }
.command { padding: 0 10px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.command.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.command.small { min-height: 30px; font-size: 12px; }
.toolbar { justify-content: flex-start; align-items: end; flex-wrap: wrap; padding: 10px; background: var(--surface); border: 1px solid var(--line); }
.toolbar label, dialog label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.toolbar input, .toolbar select, dialog select, dialog input { height: 35px; border: 1px solid #b7c2ca; border-radius: 4px; padding: 0 8px; background: #fff; color: var(--text); }
.room-select-label select { min-width: 250px; }
.search-label { flex: 1; min-width: 220px; }
.search-label input { width: 100%; }
.toolbar-actions { margin-left: auto; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); margin: 10px 0; border: 1px solid var(--line); background: var(--surface); }
.summary-item { padding: 8px 10px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-value { font-size: 20px; font-weight: 800; }
.summary-label { margin-top: 2px; color: var(--muted); font-size: 11px; }
.workspace { display: grid; grid-template-columns: minmax(300px, .75fr) minmax(560px, 1.6fr); gap: 10px; }
.unassigned-panel, .room-panel, .waiting-section, .flow-block { min-width: 0; border: 1px solid var(--line); background: var(--surface); }
.room-panel { border: 0; background: transparent; }
.panel-heading { min-height: 43px; padding: 6px 9px; border-bottom: 1px solid var(--line); background: #f7f9fa; }
.panel-heading span { min-width: 24px; padding: 3px 6px; border-radius: 10px; background: #e5ebef; text-align: center; font-size: 11px; }
.pending-list { height: calc(100vh - 235px); min-height: 430px; overflow: auto; padding: 6px; }
.active-flow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.flow-block header { height: 38px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border-bottom: 1px solid var(--line); font-weight: 800; }
.called-block { border-top: 3px solid var(--purple); }
.serving-block { border-top: 3px solid var(--green); }
.waiting-section { border-top: 3px solid var(--amber); }
.waiting-list { height: calc(100vh - 365px); min-height: 300px; overflow: auto; padding: 7px; }
.empty { padding: 26px 12px; color: var(--muted); text-align: center; }
.patient-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: start;
  padding: 8px; margin-bottom: 6px; border: 1px solid #ccd6dd; border-left: 4px solid #81919c; background: #fff;
}
.patient-row.priority-STAT { border-left-color: var(--red); }
.patient-row.priority-HIGH { border-left-color: #df7b13; }
.patient-row.dragging { opacity: .4; }
.patient-row.drag-over { border-top: 3px solid var(--blue); }
.drag-handle { color: #84939e; cursor: grab; padding: 8px 2px; }
.patient-main { min-width: 0; }
.patient-top { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.ticket { color: var(--blue); font-size: 18px; font-weight: 900; }
.patient-name { margin-top: 3px; font-size: 14px; font-weight: 800; overflow-wrap: anywhere; }
.service { margin-top: 3px; color: #374751; line-height: 1.3; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 9px; margin-top: 5px; color: var(--muted); font-size: 11px; }
.badge { display: inline-flex; padding: 2px 5px; border-radius: 3px; background: var(--blue-soft); color: #145b91; font-size: 10px; font-weight: 800; }
.badge.AUTO { background: var(--green-soft); color: var(--green); }
.badge.MANUAL { background: var(--amber-soft); color: var(--amber); }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 110px; }
.row-action { width: 30px; height: 29px; border: 1px solid #b9c5cd; border-radius: 4px; background: #fff; color: #43535e; cursor: pointer; }
.row-action.call { color: var(--purple); border-color: #cdb8e2; }
.row-action.start { color: var(--green); border-color: #a8d3bb; }
.row-action.done { color: #fff; background: var(--green); border-color: var(--green); }
.active-card { min-height: 122px; padding: 12px; }
.active-card .ticket { font-size: 27px; }
.active-card .patient-name { font-size: 17px; }
.active-card.called { background: #fcfaff; }
.active-card.serving { background: #f8fcfa; }
.active-card .row-actions { max-width: none; justify-content: flex-start; margin-top: 8px; }
.pending-check { width: 17px; height: 17px; margin-top: 4px; }
.qms-toast { position: fixed; right: 16px; bottom: 16px; max-width: 420px; padding: 10px 12px; border-radius: 5px; background: #18232c; color: #fff; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .18s; z-index: 10; }
.qms-toast.show { opacity: 1; transform: translateY(0); }
.qms-toast.error { background: var(--red); }
dialog { width: min(420px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 6px; padding: 0; box-shadow: 0 12px 40px rgba(0,0,0,.24); }
dialog::backdrop { background: rgba(23,35,45,.42); }
dialog form { display: grid; gap: 14px; padding: 14px; }
.dialog-entry { padding: 8px; border: 1px solid var(--line); background: #f7f9fa; font-weight: 700; overflow-wrap: anywhere; }
.dialog-actions { justify-content: flex-end; }
@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; }
  .pending-list, .waiting-list { height: auto; max-height: 430px; min-height: 150px; }
}
@media (max-width: 620px) {
  .qms-page { padding: 8px; }
  .toolbar { display: grid; grid-template-columns: 1fr; }
  .toolbar-actions { margin-left: 0; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; }
  .summary { grid-template-columns: 1fr 1fr; }
  .active-flow { grid-template-columns: 1fr; }
}
