:root {
  --navy: #0f2a43;
  --blue: #1c6fd6;
  --blue-light: #eaf2fd;
  --ink: #1c2733;
  --muted: #5b6b7c;
  --border: #dfe6ee;
  --bg: #f6f8fb;
  --white: #ffffff;
  --green: #1c8a56;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.site-header {
  background: var(--navy);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 8px rgba(0,0,0,0.15);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 24px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  background: var(--blue);
  color: white;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  border-radius: 8px;
}

.brand-name { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 12px; color: #b7c6d9; }

.tabs { display: flex; gap: 4px; }

.settings-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: #c7d5e6;
  font-size: 15px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  margin-left: 8px;
}

.settings-toggle:hover { background: rgba(255,255,255,0.1); color: white; }

.tab-btn {
  background: transparent;
  border: none;
  color: #c7d5e6;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover { background: rgba(255,255,255,0.08); color: white; }

.tab-btn.active {
  background: var(--blue);
  color: white;
  font-weight: 600;
}

/* Main */
main { padding: 32px 0 64px; }

.panel-intro h1 {
  font-size: 22px;
  margin: 0 0 6px;
}

.panel-intro p {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 14px;
  max-width: 680px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Search */
.search-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

#searchBox {
  flex: 1;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  outline: none;
}

#searchBox:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(28,111,214,0.15);
}

.result-count {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.table-wrap {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  background: var(--blue-light);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

th.num, td.num { text-align: right; }
th.check-col, td.check-col { width: 36px; padding-left: 16px; padding-right: 0; }

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafcff; }

.code-cell { font-weight: 600; color: var(--navy); white-space: nowrap; }
.fee-cell { font-variant-numeric: tabular-nums; }
.fee-zero { color: var(--muted); }

.row-check { width: 16px; height: 16px; cursor: pointer; accent-color: var(--blue); }

tr.row-pinned { background: var(--blue-light); }
tr.row-pinned:hover { background: #e2edfb; }

tr.row-divider td {
  padding: 0;
  border-bottom: none;
  height: 1px;
  background: var(--border);
}

tr.row-total {
  background: var(--blue-light);
  font-weight: 700;
}

tr.row-total td {
  border-top: 2px solid var(--navy);
  border-bottom: none;
  color: var(--navy);
}

tr.row-total .fee-cell { color: var(--green); }

/* Selection bar */
.selection-bar {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-bar[hidden] { display: none; }

.selection-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-light);
  color: var(--navy);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 6px 4px 10px;
  border-radius: 100px;
}

.chip-x {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.chip-x:hover { color: var(--navy); }

.selection-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
}

.selection-total {
  font-size: 13.5px;
  color: var(--ink);
}

.selection-total strong { color: var(--green); }

.btn-clear {
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-clear:hover { color: var(--navy); border-color: var(--blue); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 32px;
}

/* Scenario cards */
.scenario-list {
  display: grid;
  gap: 16px;
}

.scenario-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.scenario-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.scenario-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
}

.scenario-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--blue);
  background: var(--blue-light);
  padding: 2px 8px;
  border-radius: 100px;
  margin-left: 8px;
  font-weight: 600;
  vertical-align: middle;
}

.scenario-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
}

.scenario-items { list-style: none; margin: 0; padding: 0; }

.scenario-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px dashed var(--border);
  font-size: 13.5px;
}

.scenario-item:first-child { border-top: none; }

.item-main { color: var(--ink); }
.item-fee { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.item-or {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  padding: 2px 0;
}

.material-note {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.material-note a { color: var(--blue); text-decoration: none; }
.material-note a:hover { text-decoration: underline; }

/* Category filter */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.cat-btn {
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 100px;
  cursor: pointer;
}

.cat-btn:hover { border-color: var(--blue); color: var(--navy); }

.cat-btn.active {
  background: var(--navy);
  border-color: var(--navy);
  color: white;
  font-weight: 600;
}

/* Workflow cards */
.workflow-list { display: grid; gap: 12px; }

.workflow-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.workflow-head-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.workflow-head {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: none;
  border: none;
  padding: 14px 18px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.workflow-head:hover { background: #fafcff; }

.workflow-title { font-size: 15px; font-weight: 600; color: var(--navy); }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
}

.icon-btn:hover { color: var(--blue); background: var(--blue-light); }

.chevron {
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s;
  display: inline-block;
}

.chevron.open { transform: rotate(180deg); }

.workflow-body {
  padding: 4px 18px 18px;
  border-top: 1px solid var(--border);
}

.workflow-total {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 14px;
  font-weight: 700;
  color: var(--green);
}

/* Tooth chart */
.tooth-chart {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 12px 12px;
  margin: 12px 0;
}

.tc-hint {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.arch-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin: 6px 0 4px;
}

.tc-row {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.tooth {
  flex: 1;
  min-width: 26px;
  max-width: 34px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  padding: 4px 2px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.3;
  user-select: none;
}

.tooth span { display: block; font-weight: 700; color: var(--navy); }
.tooth small { display: block; color: var(--muted); font-size: 9px; }

.tooth:hover { border-color: var(--blue); }

.tooth.selected { background: var(--blue-light); border-color: var(--blue); }
.tooth.selected span { color: var(--blue); }

.tooth.implant { background: #e5f6ec; border-color: var(--green); }
.tooth.implant span { color: var(--green); }

.tooth-spacer { width: 10px; flex: 0 0 auto; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 42, 67, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--white);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal-card.modal-wide { max-width: 700px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h2 { margin: 0; font-size: 18px; color: var(--navy); }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
}

.modal-close:hover { color: var(--navy); }

.auth-banner { min-height: 32px; margin-bottom: 8px; }

.settings-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 16px;
}

.save-status { font-size: 12.5px; color: var(--muted); }

.settings-workflow-list {
  display: grid;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.settings-row-label { flex: 1; font-size: 14px; color: var(--ink); font-weight: 500; }
.settings-row-cat { font-size: 12px; color: var(--muted); }

.btn-primary {
  background: var(--blue);
  border: none;
  color: white;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 7px;
  cursor: pointer;
}

.btn-primary:hover { background: #1558b0; }

.btn-danger {
  background: none;
  border: 1px solid #e5b3ab;
  color: #b91c1c;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
}

.btn-danger:hover { background: #fdf1f0; }

/* Edit workflow form */
#editWorkflowForm { display: flex; flex-direction: column; gap: 14px; }

#editWorkflowForm label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

#editWorkflowForm input[type="text"],
#editWorkflowForm select {
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.field-row { display: flex; gap: 14px; }
.field-row label { flex: 1; }

.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 13.5px !important;
  color: var(--ink) !important;
}

#editWorkflowForm h3 { margin: 4px 0 0; font-size: 13px; color: var(--navy); }

.edit-codes-list { display: grid; gap: 8px; }

.code-row {
  display: grid;
  grid-template-columns: 1.2fr 1.3fr 1.8fr auto;
  gap: 8px;
  align-items: center;
}

.code-row input, .code-row select {
  font-size: 13.5px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.modal-actions-right { display: flex; gap: 10px; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0 40px;
}

.site-footer p {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  thead th:nth-child(3), thead th:nth-child(4) { font-size: 11px; }
}
