/* Shared components: buttons, badges, panels, forms, tables, tabs, modal, toasts, menus, states. */

/* ---- buttons (pill, 36px) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--ctl-h); padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--r-pill); font: 600 13px/1 var(--font); text-decoration: none;
  cursor: pointer; transition: background-color 0.15s, border-color 0.15s, color 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover:not(:disabled) { background: var(--blue); }
.btn-secondary { background: #fff; border-color: var(--line-2); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--paper-2); border-color: var(--ink-2); }
.btn-plain { background: transparent; color: var(--ink-2); }
.btn-plain:hover:not(:disabled) { background: var(--paper-2); color: var(--ink); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #8f1d17; }
.btn-danger-outline { background: #fff; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn-danger-outline:hover:not(:disabled) { background: var(--red-bg); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
a.btn[disabled] { pointer-events: none; }
.btn[aria-busy="true"] { cursor: progress; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--paper-2); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.menu-trigger { border: 0; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.avatar-initial { width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap; background: var(--grey-bg); color: var(--ink-2); }
.badge-amber { background: var(--amber-bg); color: var(--amber-fg); }
.badge-blue { background: var(--blue-soft); color: var(--blue-ink); }
.badge-green { background: var(--green-bg); color: var(--green-fg); }
.badge-red { background: var(--red-bg); color: var(--bad); }
.badge-grey { background: var(--grey-bg); color: var(--ink-2); }

/* ---- page header ---- */
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 8px; }
.back-link:hover { color: var(--ink); }
.page-head-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.page-head-text { min-width: 0; flex: 1 1 260px; }
.page-title-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.page-sub { margin-top: 4px; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- panels ---- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px 0; }
.panel-title { font-size: 14px; }
.panel-sub { margin-top: 4px; color: var(--muted); font-size: 13px; }
.panel-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.panel-body { padding: 16px 20px 20px; }
.panel-flush > .panel-body { padding: 0; }
.panel-flush > .panel-head { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.panel-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.panel-pad { padding: 16px 20px; }
.panel-sep { height: 1px; background: var(--line); margin: 20px 0; }
.callout { max-inline-size: none; background: var(--blue-soft); color: var(--ink); border-radius: 10px; padding: 12px 12px; margin-bottom: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; color: inherit; text-decoration: none; min-width: 0; }
a.stat:hover { border-color: var(--line-2); box-shadow: var(--shadow-1); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 8px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; overflow-wrap: anywhere; }
.stat-hint { margin-top: 8px; color: var(--muted); font-size: 12.5px; }

/* ---- forms ---- */
.field { display: grid; gap: 8px; min-width: 0; align-content: start; }
.field-label { font-weight: 600; font-size: 13px; }
.field-hint, .field-count { color: var(--muted); font-size: 12.5px; }
.field-count.is-over { color: var(--bad); }
.field-error { color: var(--bad); font-size: 12.5px; }
.field-group { display: grid; gap: 16px; }
.field-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.input {
  width: 100%; height: var(--ctl-h); padding: 0 12px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; color: var(--ink);
  font: inherit; transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: #8a92a5; }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.input[readonly], .input:disabled { background: var(--paper-2); color: var(--muted); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.textarea { height: auto; padding: 8px 12px; resize: vertical; line-height: 1.45; }
.select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235e6679' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 18px;
}
.input-group { display: flex; }
.input-group .input { border-radius: 0 10px 10px 0; min-width: 0; }
.input-affix { display: inline-flex; align-items: center; padding: 0 12px; border: 1px solid var(--line-2); border-right: 0; border-radius: 10px 0 0 10px; background: var(--paper-2); color: var(--muted); }
.input-affix:last-child { border-right: 1px solid var(--line-2); border-left: 0; border-radius: 0 10px 10px 0; }
.field-switch { display: flex; gap: 12px; align-items: flex-start; }
.switch { position: relative; flex: none; width: 36px; min-width: 36px; height: 20px; min-height: 20px; margin-top: 1px; padding: 0; border: 0; border-radius: var(--r-pill); background: var(--line-2); cursor: pointer; transition: background-color 0.15s; }
.switch[aria-checked="true"] { background: var(--blue); }
.switch::after { content: ""; position: absolute; inset: -12px -8px; }
.switch-knob { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform 0.15s var(--ease); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(16px); }
.switch-label { display: grid; gap: 4px; font-weight: 600; cursor: pointer; }
.switch-label .field-hint { font-weight: 400; }

.savebar { position: sticky; bottom: 16px; z-index: 30; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; border-radius: 14px; background: #fff; color: var(--muted); border: 1px solid var(--line); }
.savebar.is-dirty { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: var(--shadow-2); }
.savebar-msg { font-weight: 600; }
.savebar-actions { display: flex; gap: 8px; }
.savebar.is-dirty .btn-secondary { background: transparent; color: #fff; border-color: rgb(255 255 255 / 0.4); }
.savebar.is-dirty .btn-secondary:hover:not(:disabled) { background: rgb(255 255 255 / 0.12); border-color: #fff; }
.savebar.is-dirty .btn-primary { background: #fff; color: var(--ink); }
.savebar.is-dirty .btn-primary:hover:not(:disabled) { background: var(--blue-soft); }
progress { width: 100%; max-width: 240px; height: 6px; accent-color: var(--blue); }

/* ---- index list: tabs, toolbar, table ---- */
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs-flat { padding: 0; margin-bottom: 0; }
.tab { position: relative; flex: none; height: 36px; padding: 0 12px; border: 0; background: none; color: var(--muted); font: 600 13px/1 var(--font); cursor: pointer; white-space: nowrap; border-radius: 8px 8px 0 0; }
.tab:hover { color: var(--ink); background: var(--paper-2); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--blue); }
.toolbar { display: flex; gap: 8px; padding: 12px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.search-box { position: relative; flex: 1 1 240px; min-width: 0; }
.search-box > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input { padding-left: 34px; }
.filter-select { width: auto; min-width: 160px; }
.list-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.list-foot:empty { display: none; }
.pager { display: flex; gap: 8px; }
.table-scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; padding: 12px 16px; font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--paper); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--paper-2); }
.tbl .num { text-align: right; }
.tbl tr.is-link, .tbl tr:has(.cell-link) { cursor: pointer; }
.cell-link { color: var(--ink); font-weight: 600; text-decoration: none; background: none; border: 0; padding: 0; font-family: inherit; font-size: inherit; cursor: pointer; text-align: left; }
.cell-link:hover { text-decoration: underline; }
.order-no { font-weight: 600; }
.stack { display: grid; gap: 4px; min-width: 0; }

@media (max-width: 719px) {
  .tbl thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl td { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 4px 0; border: 0; text-align: right; }
  .tbl td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12.5px; text-align: left; }
  .tbl td.cell-first { justify-content: flex-start; text-align: left; font-size: 15px; padding-bottom: 8px; }
  .tbl td.cell-first::before { content: none; }
  .tbl td > .stack { text-align: right; justify-items: end; }
  .tbl td.cell-first > .stack { text-align: left; justify-items: start; }
}

/* ---- states, skeleton ---- */
.state { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 48px 24px; }
.state-icon { color: var(--muted); }
.state-title { font-size: 16px; }
.state-text { color: var(--muted); max-width: 46ch; }
.state-loading { justify-items: stretch; text-align: left; padding: 24px; }
.state .btn { margin-top: 8px; }
.skel { border-radius: 8px; background: linear-gradient(90deg, var(--paper-2) 25%, #fff 50%, var(--paper-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skel-bar { height: 14px; margin: 8px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- modal (native dialog) ---- */
.modal { padding: 0; border: 0; border-radius: 16px; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); color: var(--ink); background: #fff; box-shadow: var(--shadow-2); overflow: hidden; }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgb(11 18 48 / 0.45); }
.modal-sm { width: min(440px, calc(100vw - 32px)); }
.modal-lg { width: min(1040px, calc(100vw - 32px)); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 16px 16px 20px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 15px; }
.modal-form { display: flex; flex-direction: column; overflow: auto; min-height: 0; }
.modal-body { padding: 20px; display: grid; gap: 16px; }
.modal-error { margin: 0 20px 16px; padding: 12px 12px; border-radius: 10px; background: var(--red-bg); color: var(--bad); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--paper); }
.modal-foot:empty { display: none; }

/* ---- toasts, menus ---- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--shadow-2); cursor: pointer; animation: toast-in 0.2s var(--ease); }
.toast-error { background: var(--bad); }
.toast-out { opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.menu-host { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); min-width: 220px; max-width: 280px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-2); padding: 8px; z-index: 60; }
.menu[data-align="right"] { right: 0; }
.menu-text { padding: 8px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; text-decoration: none; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--paper-2); }
.menu-item.is-danger { color: var(--bad); }

/* ---- phones: thumb-sized controls ---- */
@media (max-width: 559px) {
  .switch { width: 52px; min-width: 52px; height: 44px; min-height: 44px; margin-top: -8px; background: transparent !important; }
  .switch::before { content: ""; position: absolute; left: 8px; top: 12px; width: 36px; height: 20px; border-radius: var(--r-pill); background: var(--line-2); transition: background-color 0.15s; }
  .switch[aria-checked="true"]::before { background: var(--blue); }
  .switch-knob { top: 14px; left: 10px; }
  .switch[aria-checked="true"] .switch-knob { transform: translateX(16px); }
}
@media (max-width: 639px) {
  :root { --ctl-h: 44px; }
  .btn-sm { height: 44px; }
  .cell-link, .link, .link-btn, .back-link, .guide-title, .chart-data summary { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
  .menu-item, .search-item { min-height: 44px; }
  .tab { height: 44px; }
  .field-cols { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 20px; }
  .panel-head { padding: 16px 16px 0; }
  .panel-body { padding: 16px 16px 16px; }
  .panel-actions { flex-wrap: wrap; justify-content: flex-end; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; }
  .savebar { bottom: 12px; padding-left: 16px; }
  .savebar-msg { font-size: 13px; }
  .toolbar { padding: 12px; }
  .filter-select { width: 100%; }
}
@media (max-width: 1023px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- live site status: panel colour, pill popover, attention strip (live-status.js) ---- */
.live-status[data-tone="ok"] { color: var(--ok); }
.live-status[data-tone="busy"] { color: var(--blue-ink); }
.live-status[data-tone="wait"] { color: var(--warn); }
.live-status[data-tone="bad"] { color: var(--bad); }
.live-status[data-tone="idle"] { color: var(--muted); }
.live-pop { position: absolute; right: 0; top: calc(100% + 6px); width: min(340px, calc(100vw - 24px)); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-2); padding: 12px 16px; z-index: 60; display: grid; gap: 8px; }
.live-pop-title { font-weight: 600; }
.live-pop-sentence[data-tone="bad"] { color: var(--bad); }
.live-pop-when { font-size: 12.5px; }
.live-item-link { font-weight: 600; }
.status-strip { grid-column: 1 / -1; grid-row: 2; }
.live-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 10px var(--pad); background: var(--red-bg); color: var(--bad); border-bottom: 1px solid color-mix(in srgb, var(--bad) 25%, var(--line)); }
.live-strip-text { font-weight: 500; overflow-wrap: anywhere; }
.live-strip .live-item-link { color: var(--bad); text-decoration: underline; }
