/* ========================= components ========================= */

/* ---------- Button ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid transparent;
  font-weight: 500; font-size: var(--fs-13); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  background: var(--surface); color: var(--text);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #04201d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #04201d; } }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--fs-12); }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11.5px; border-radius: 5px; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--text-3) transparent var(--text-3) transparent; animation: spin .7s linear infinite;
}
.btn-primary.is-loading::after { border-color: #fff transparent #fff transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.btn-group .btn[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-text); border-color: var(--brand); z-index: 1; }

/* ---------- Badges (level / action / state / severity / generic) ---------- */
.bdg {
  --c: #64748b;
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: var(--r-pill); font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1;
  background: color-mix(in srgb, var(--c) var(--mix-bg-amt), transparent);
  color: color-mix(in srgb, var(--c), var(--mix-text) var(--mix-text-amt));
  border: 1px solid color-mix(in srgb, var(--c) 34%, transparent);
  cursor: default;
}
.bdg svg.i { width: 12px; height: 12px; stroke-width: 2.4; }
.bdg.sq { border-radius: 5px; }
.bdg.outline { background: transparent; }
.bdg.sm { height: 19px; padding: 0 6px; font-size: 11px; }
.bdg .lv-shape { width: 8px; height: 8px; background: var(--c); flex: none; }
.lv-shape.s0 { border-radius: 50%; }
.lv-shape.s1 { border-radius: 2px; }
.lv-shape.s2 { transform: rotate(45deg); border-radius: 1px; width: 7px; height: 7px; }
.lv-shape.s3 { clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; }
.lv-shape.s4 { clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%); }
.lv-shape.s5 { clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); width: 10px; height: 10px; }
.bdg.state { border-style: dashed; }
.bdg[tabindex] { cursor: help; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid var(--border);
}
.chip .sw { width: 8px; height: 8px; border-radius: 2px; background: var(--c, #94a3b8); }
.chip.removable button { border: 0; background: none; padding: 0; margin-left: 2px; cursor: pointer; color: var(--text-3); display: inline-flex; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--text-3)); flex: none; }
.dot.pulse { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 60%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-3); color: var(--text-2); font-size: 11px; font-weight: 600; }
.count.hot { background: var(--danger); color: #fff; }
.soon { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); padding: 1px 6px; border-radius: 4px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-1); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 12px 16px; border-bottom: 1px solid var(--border); min-height: 48px; }
.card-h h2, .card-h h3 { display: flex; align-items: center; gap: 6px; }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.card.clickable { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.card.clickable:hover { border-color: var(--border-strong); box-shadow: var(--sh-2); }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.kpi .kpi-label { display: flex; align-items: center; gap: 4px; color: var(--text-2); font-size: var(--fs-13); font-weight: 500; }
.kpi .kpi-value { font-size: var(--fs-28); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .kpi-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 2px; }
.delta.up-bad, .delta.down-bad { color: var(--danger); }
.delta.up-good, .delta.down-good { color: var(--success); }
.delta.flat { color: var(--text-3); }
.spark { width: 96px; height: 28px; }
.stat-inline { display: flex; flex-direction: column; }
.stat-inline b { font-size: 20px; font-variant-numeric: tabular-nums; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: var(--fs-13); font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 4px; }
.req::after { content: "*"; color: var(--danger); margin-left: 2px; }
.hint { font-size: var(--fs-12); color: var(--text-3); }
.err-msg { font-size: var(--fs-12); color: var(--danger); display: flex; gap: 4px; align-items: flex-start; }
.input, .select, .textarea {
  height: 34px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); min-width: 0; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.input.invalid, .select.invalid, .textarea.invalid, .ms-trigger.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 16%, transparent); }
.input.sm, .select.sm { height: 28px; font-size: var(--fs-12); }
.input-icon { position: relative; }
.input-icon > svg.i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon > .input { padding-left: 32px; }
.code-input { font-family: var(--mono); font-size: 12.5px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-13); }
.check input { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
.radio-cards { display: grid; gap: 8px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-md); cursor: pointer; background: var(--surface); }
.radio-card:hover { border-color: var(--text-3); }
.radio-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.radio-card input { margin-top: 3px; accent-color: var(--brand); }
.radio-card .rc-title { font-weight: 600; font-size: 13px; }
.radio-card .rc-desc { font-size: 12px; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
fieldset { border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; margin: 0; }
legend { padding: 0 6px; font-size: 13px; font-weight: 600; }

/* toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-13); }
.switch input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: transform .15s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }

/* slider */
.slider-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] { accent-color: var(--brand); flex: 1; }
.slider-val { min-width: 44px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* multiselect */
.ms { position: relative; }
.ms-trigger {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 34px; padding: 4px 30px 4px 8px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); background: var(--surface); cursor: pointer; width: 100%; text-align: left; position: relative;
}
.ms-trigger::after { content: ""; position: absolute; right: 12px; top: 50%; width: 6px; height: 6px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: translateY(-70%) rotate(45deg); }
.ms-trigger .ph { color: var(--text-3); font-size: 13px; padding-left: 2px; }
.ms-panel { position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0; min-width: 240px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--sh-3); padding: 6px; }
.ms-panel .input { margin-bottom: 6px; }
.ms-list { max-height: 260px; overflow: auto; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.ms-opt:hover, .ms-opt.active { background: var(--surface-3); }
.ms-opt input { accent-color: var(--brand); }
.ms-opt .indent { display: inline-block; }
.ms-foot { display: flex; justify-content: space-between; padding: 6px 4px 2px; border-top: 1px solid var(--border); margin-top: 6px; }

/* tag input */
.tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 34px; padding: 4px 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); }
.tags:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.tags input { border: 0; outline: 0; flex: 1; min-width: 120px; background: transparent; height: 24px; font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; background: none; padding: 10px 12px; font-size: var(--fs-13); font-weight: 500; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--brand-text); border-bottom-color: var(--brand); }
.tabpanel { padding-top: var(--s4); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; height: 28px; padding: 0 10px; border-radius: 5px; font-size: 12.5px; font-weight: 500; color: var(--text-2); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

/* ---------- Stepper ---------- */
.stepper { display: flex; gap: 0; align-items: stretch; overflow-x: auto; }
.step {
  flex: 1; min-width: 120px; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 0; background: none; text-align: left;
  cursor: pointer; border-bottom: 3px solid var(--border); color: var(--text-2); font-size: 12.5px;
}
.step .n { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); font-weight: 700; font-size: 12px; flex: none; border: 1px solid var(--border-strong); }
.step .st { display: flex; flex-direction: column; line-height: 1.25; }
.step .st small { font-size: 11px; color: var(--text-3); }
.step.done { color: var(--text); border-bottom-color: color-mix(in srgb, var(--brand) 55%, transparent); }
.step.done .n { background: var(--brand); color: #fff; border-color: var(--brand); }
.step.current { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.step.current .n { border: 2px solid var(--brand); color: var(--brand-text); background: var(--surface); }
.step.error { border-bottom-color: var(--danger); }
.step.error .n { background: var(--danger); color: #fff; border-color: var(--danger); }
.step:disabled { cursor: not-allowed; opacity: .6; }

/* Step Guide box */
.guide { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent); margin-top: var(--s5); }
.guide h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.guide p, .guide li { font-size: 12.5px; color: var(--text-2); margin: 0; }
.guide ul { margin: 0; padding-left: 16px; }

/* ---------- Banner ---------- */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-13); }
.banner svg.i { margin-top: 2px; }
.banner .grow p { margin: 0; }
.banner.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--text); }
.banner.info > svg.i { color: var(--info); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.warn > svg.i { color: var(--warn); }
.banner.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.banner.danger > svg.i { color: var(--danger); }
.banner.success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.banner.success > svg.i { color: var(--success); }
.validation-list { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Table ---------- */
.tbl-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tbl-bulk { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--brand-soft); border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap; }
.tbl-scroll { overflow: auto; max-height: var(--tbl-max, 620px); }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-13); }
.tbl thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; font-weight: 600; color: var(--text-2);
  font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none;
}
.tbl thead th .th { display: inline-flex; align-items: center; gap: 4px; }
.tbl thead th button.sort { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.tbl thead th .arrow { font-size: 10px; color: var(--text-3); }
.tbl thead th[aria-sort="ascending"] .arrow, .tbl thead th[aria-sort="descending"] .arrow { color: var(--brand-text); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl.dense td { padding: 5px 12px; }
.tbl.dense thead th { padding: 6px 12px; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.selected { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.tbl tbody tr:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tbl .cb { width: 36px; padding-right: 0; }
.tbl .cb input { width: 15px; height: 15px; accent-color: var(--brand); }
.tbl-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 4px; }
.pager button { min-width: 28px; height: 28px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: 12px; }
.pager button[aria-current="page"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.cell-main { font-weight: 500; color: var(--text); }
.cell-sub { font-size: 12px; color: var(--text-3); }
.drag-handle { cursor: grab; color: var(--text-3); display: inline-flex; padding: 2px; border-radius: 4px; border: 0; background: none; }
.drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: .45; }
tr.drag-over td { box-shadow: inset 0 2px 0 var(--brand); }

/* ---------- Empty / skeleton / error ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 40px 16px; text-align: center; color: var(--text-2); }
.empty .ill { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text-3); }
.empty.error .ill { background: var(--danger-soft); color: var(--danger); }
.empty h3 { color: var(--text); font-size: 15px; }
.empty p { max-width: 420px; font-size: 13px; }
.skel { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Overlays: tooltip / popover / modal / drawer / toast ---------- */
.tip {
  position: fixed; z-index: 400; max-width: 300px; padding: 6px 9px; border-radius: 6px; background: #0f172a; color: #f1f5f9;
  font-size: 12px; line-height: 1.4; pointer-events: none; box-shadow: var(--sh-2);
}
:root[data-theme="dark"] .tip { background: #e2e8f0; color: #0f172a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tip { background: #e2e8f0; color: #0f172a; } }
.tip .tip-more { opacity: .7; font-size: 11px; display: block; margin-top: 2px; }
.info-btn { border: 0; background: none; padding: 0 2px; color: var(--text-3); cursor: pointer; display: inline-flex; border-radius: 50%; }
.info-btn:hover { color: var(--brand-text); }
.info-btn svg.i { width: 14px; height: 14px; }
.popover {
  position: fixed; z-index: 380; width: 360px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--sh-3); padding: 14px 16px; font-size: 13px;
}
.popover h4 { font-size: 14px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.popover .pop-sec { margin-top: 10px; }
.popover .pop-sec b { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); margin-bottom: 3px; }
.popover .pop-close { position: absolute; top: 8px; right: 8px; }
.popover.menu { width: auto; min-width: 200px; padding: 6px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; text-align: left; color: var(--text); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

.backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 300; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
#modal-root .backdrop { z-index: 330; } /* modal luôn nằm trên drawer (320) */
.modal {
  position: fixed; z-index: 340; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 520px; max-width: calc(100vw - 32px); max-height: calc(100vh - 48px);
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-3); display: flex; flex-direction: column; animation: pop .16s ease;
}
.modal.lg { width: 760px; }
.modal.xl { width: 980px; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } }
.modal-h { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 12px; }
.modal-h .mi { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--brand-soft); color: var(--brand-text); }
.modal-h .mi.danger { background: var(--danger-soft); color: var(--danger); }
.modal-h .mi.warn { background: var(--warn-soft); color: var(--warn); }
.modal-h h2 { font-size: 16px; }
.modal-b { padding: 0 18px 16px; overflow: auto; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.consequences { margin: 8px 0 12px; padding: 10px 12px 10px 28px; background: var(--surface-2); border-radius: var(--r-sm); border: 1px solid var(--border); font-size: 13px; }

.drawer {
  position: fixed; z-index: 320; top: 0; right: 0; height: 100vh; width: var(--drawer-w); max-width: 100vw; background: var(--surface);
  box-shadow: var(--sh-3); display: flex; flex-direction: column; animation: slide .2s ease; border-left: 1px solid var(--border);
}
.drawer.wide { --drawer-w: 760px; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.drawer-h { padding: 14px 18px 0; border-bottom: 1px solid var(--border); }
.drawer-h .dh-top { display: flex; gap: 10px; align-items: flex-start; }
.drawer-h h2 { font-size: 16px; }
.drawer-h .dh-sum { color: var(--text-2); font-size: 13px; margin-top: 4px; }
.drawer-h .dh-badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.drawer-b { flex: 1; overflow: auto; padding: 16px 18px; }
.drawer-f { padding: 10px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; background: var(--surface-2); }
.dl { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 8px 12px; font-size: 13px; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.toast-root { position: fixed; z-index: 500; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; min-width: 280px; max-width: 420px; padding: 10px 12px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-left: 4px solid var(--c, var(--brand)); border-radius: var(--r-md); box-shadow: var(--sh-3); font-size: 13px; animation: slideup .2s ease;
}
.toast .grow b { display: block; }
@keyframes slideup { from { transform: translateY(12px); opacity: 0; } }

/* ---------- JSON viewer ---------- */
.json { margin: 0; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); overflow: auto; max-height: 460px; font-size: 12px; line-height: 1.55; white-space: pre; }
.json .k { color: #7c3aed; } .json .s { color: #047857; } .json .n { color: #b45309; } .json .b { color: #1d4ed8; } .json .z { color: #64748b; }
:root[data-theme="dark"] .json .k { color: #c4b5fd; } :root[data-theme="dark"] .json .s { color: #6ee7b7; } :root[data-theme="dark"] .json .n { color: #fcd34d; } :root[data-theme="dark"] .json .b { color: #93c5fd; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .json .k { color: #c4b5fd; } :root:not([data-theme="light"]) .json .s { color: #6ee7b7; } :root:not([data-theme="light"]) .json .n { color: #fcd34d; } :root:not([data-theme="light"]) .json .b { color: #93c5fd; } }
.code-edit { width: 100%; min-height: 360px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; padding: 12px; border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); tab-size: 2; resize: vertical; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; position: relative; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; bottom: -6px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--text-3)); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--c, var(--text-3)); }
.timeline li.focus { font-weight: 600; }
.timeline .tl-time { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- Accordion ---------- */
details.acc { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
details.acc + details.acc { margin-top: 8px; }
details.acc > summary { list-style: none; cursor: pointer; padding: 10px 14px; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
details.acc[open] > summary::before { transform: rotate(45deg); }
details.acc > .acc-b { padding: 0 14px 12px; }

/* ---------- Breadcrumb ---------- */
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-3); flex-wrap: wrap; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { opacity: .5; }

/* ---------- Command palette ---------- */
.cmdk { position: fixed; z-index: 450; top: 12vh; left: 50%; transform: translateX(-50%); width: 620px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--sh-3); overflow: hidden; }
.cmdk .cmdk-in { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.cmdk .cmdk-in input { flex: 1; border: 0; outline: 0; background: none; font-size: 15px; }
.cmdk-list { max-height: 420px; overflow: auto; padding: 6px; }
.cmdk-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 8px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.cmdk-item .ci-sub { margin-left: auto; color: var(--text-3); font-size: 12px; }
.cmdk-item.active { background: var(--brand-soft); color: var(--brand-text); }
.cmdk-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-3); }

/* ---------- Tour ---------- */
.tour-spot { position: fixed; z-index: 460; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(2, 6, 23, .55), 0 0 0 3px var(--brand); transition: all .25s ease; pointer-events: none; }
.tour-bubble { position: fixed; z-index: 470; width: 340px; max-width: calc(100vw - 24px); background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-3); padding: 14px 16px; border: 1px solid var(--border-strong); }
.tour-bubble h4 { font-size: 14px; margin-bottom: 6px; }
.tour-bubble p { font-size: 13px; color: var(--text-2); }
.tour-bubble .tb-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }

/* ---------- Misc ---------- */
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--c, var(--brand)); border-radius: 3px; }
.meter { display: flex; align-items: center; gap: 8px; }
.meter .progress { flex: 1; min-width: 50px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--c, var(--accent)); color: #fff; font-size: 11px; font-weight: 700; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 9.5px; }
.kv { display: flex; gap: 6px; align-items: baseline; font-size: 13px; }
.kv span { color: var(--text-3); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: var(--s6) 0 var(--s3); }
.section-title h2 { display: flex; align-items: center; gap: 8px; }
.mark { background: color-mix(in srgb, #f59e0b 35%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.masked { font-family: var(--mono); background: var(--surface-3); border-radius: 4px; padding: 0 4px; }
.diff-add { background: color-mix(in srgb, #16a34a 16%, transparent); }
.diff-del { background: color-mix(in srgb, #dc2626 16%, transparent); text-decoration: line-through; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-plain > li:last-child { border-bottom: 0; }
.sla { font-variant-numeric: tabular-nums; font-size: 12.5px; font-weight: 600; }
.sla.breach { color: var(--danger); }
.sla.soon { color: var(--warn); }
