/* ==========================================================================
   components.css - buttons, forms, cards, tables, badges, modals, toasts,
                    skeletons, empty states, pagination, tabs, misc widgets
   ========================================================================== */

/* ============================ BUTTONS ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 36px; padding: 0 var(--sp-4);
  border-radius: var(--r-md); border: 1px solid transparent;
  font-size: .85rem; font-weight: 600; white-space: nowrap;
  transition: all .15s var(--ease); user-select: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-ico { font-size: 14px; line-height: 1; }

.btn-primary { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--brand-700); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary { background: var(--bg-elev); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-sunken); border-color: var(--text-faint); text-decoration: none; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }

.btn-soft { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-100); }
.btn-soft:hover { background: var(--brand-100); text-decoration: none; }
html[data-theme="dark"] .btn-soft { color: var(--brand-300); }

.btn-success { background: var(--ok-600); color: #fff; }
.btn-success:hover { background: var(--ok-700); text-decoration: none; }
.btn-danger  { background: var(--err-600); color: #fff; }
.btn-danger:hover { background: var(--err-700); text-decoration: none; }
.btn-danger-soft { background: var(--err-50); color: var(--err-700); border-color: var(--err-100); }
.btn-danger-soft:hover { background: var(--err-100); text-decoration: none; }
html[data-theme="dark"] .btn-danger-soft { color: #fca5a5; }

.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: .79rem; border-radius: var(--r-sm); }
.btn-lg { height: 44px; padding: 0 var(--sp-6); font-size: .95rem; border-radius: var(--r-md); }
.btn-block { width: 100%; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-md) var(--r-md) 0; }
.btn-group .btn.active { background: var(--brand-600); color: #fff; border-color: var(--brand-600); z-index: 1; }

.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn-secondary.loading::after, .btn-ghost.loading::after, .btn-soft.loading::after {
  border-color: rgba(100,116,139,.35); border-top-color: var(--text-muted);
}

/* ============================ CARDS ============================ */
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.card-head h3, .card-head h2 { font-size: 1rem; display: flex; align-items: center; gap: var(--sp-2); }
.card-head .card-sub { font-size: .79rem; color: var(--text-muted); margin-top: 2px; font-weight: 400; }
.card-head-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.card-body { padding: var(--sp-5); }
.card-body.tight { padding: var(--sp-3) var(--sp-4); }
.card-body.flush { padding: 0; }
.card-foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-elev-2); }

/* stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-4); }
.stat {
  position: relative; display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5); background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
  overflow: hidden; transition: transform .16s var(--ease), box-shadow .16s var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent, var(--brand-500)); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.stat-label { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.stat-ico {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--accent, var(--brand-500)) 14%, transparent);
  color: var(--accent, var(--brand-600)); font-size: 16px;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat-value small { font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-left: 3px; }
.stat-foot { display: flex; align-items: center; gap: var(--sp-2); font-size: .76rem; color: var(--text-muted); }
.stat-delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; }
.stat-delta.up { color: var(--ok-600); } .stat-delta.down { color: var(--err-600); }
.stat.accent-ok   { --accent: var(--ok-500); }
.stat.accent-warn { --accent: var(--warn-500); }
.stat.accent-err  { --accent: var(--err-500); }
.stat.accent-info { --accent: var(--info-500); }
.stat.accent-brand{ --accent: var(--brand-500); }
.stat.accent-violet { --accent: #8b5cf6; }
.stat.accent-pink { --accent: #ec4899; }

/* clickable stat */
a.stat:hover { text-decoration: none; border-color: var(--brand-300); }

/* ============================ BADGES / PILLS ============================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size: .72rem; font-weight: 650; line-height: 1.6; white-space: nowrap;
  background: var(--bg-sunken); color: var(--text-muted); border: 1px solid transparent;
}
.badge .bdot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.badge.ok    { background: var(--ok-50);   color: var(--ok-700);   border-color: var(--ok-100); }
.badge.warn  { background: var(--warn-50); color: var(--warn-700); border-color: var(--warn-100); }
.badge.err   { background: var(--err-50);  color: var(--err-700);  border-color: var(--err-100); }
.badge.info  { background: var(--info-50); color: var(--info-700); border-color: var(--info-100); }
.badge.brand { background: var(--brand-50);color: var(--brand-700);border-color: var(--brand-100); }
.badge.muted { background: var(--bg-sunken); color: var(--text-muted); border-color: var(--border); }
html[data-theme="dark"] .badge.ok    { color: #6ee7b7; }
html[data-theme="dark"] .badge.warn  { color: #fcd34d; }
html[data-theme="dark"] .badge.err   { color: #fca5a5; }
html[data-theme="dark"] .badge.info  { color: #93c5fd; }
html[data-theme="dark"] .badge.brand { color: var(--brand-300); }
.badge.lg { font-size: .79rem; padding: 4px 12px; }
.badge.sq { border-radius: var(--r-sm); }

.chip-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* ============================ FORMS ============================ */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--sp-4); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; grid-column: span 12; }
.field.c2 { grid-column: span 2; } .field.c3 { grid-column: span 3; }
.field.c4 { grid-column: span 4; } .field.c5 { grid-column: span 5; }
.field.c6 { grid-column: span 6; } .field.c7 { grid-column: span 7; }
.field.c8 { grid-column: span 8; } .field.c9 { grid-column: span 9; }
.field.c12{ grid-column: span 12; }
.field > label, .label {
  font-size: .79rem; font-weight: 650; color: var(--text);
  display: flex; align-items: center; gap: 5px;
}
.field .req { color: var(--err-500); }
.field .hint { font-size: .73rem; color: var(--text-muted); }
.field .err-msg { font-size: .74rem; color: var(--err-600); display: flex; align-items: center; gap: 4px; }
.field.invalid .input, .field.invalid select, .field.invalid textarea { border-color: var(--err-500); }
.field.invalid .input:focus, .field.invalid select:focus { box-shadow: 0 0 0 3px rgba(239,68,68,.16); }

.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 8px var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--bg-elev); color: var(--text); font-size: .87rem;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
textarea.input { min-height: 92px; resize: vertical; line-height: 1.55; }
.input:hover:not(:disabled) { border-color: var(--text-faint); }
.input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(99,102,241,.16); }
.input:disabled, .input[readonly] { background: var(--bg-sunken); color: var(--text-muted); cursor: not-allowed; }
.input[readonly].link-allowed { cursor: text; background: var(--bg-elev); color: var(--text); }
select.input { appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input-sm { min-height: 32px; padding: 5px var(--sp-3); font-size: .82rem; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0; }
.input-group .input:first-child { border-radius: var(--r-md) 0 0 var(--r-md); }
.input-group .input:last-child { border-radius: 0 var(--r-md) var(--r-md) 0; }
.input-group .btn { border-radius: 0 var(--r-md) var(--r-md) 0; margin-left: -1px; }
.input-prefix {
  display: flex; align-items: center; padding: 0 var(--sp-3);
  background: var(--bg-sunken); border: 1px solid var(--border-strong); border-right: 0;
  border-radius: var(--r-md) 0 0 var(--r-md); color: var(--text-muted); font-size: .82rem;
}
.input-prefix + .input { border-radius: 0 var(--r-md) var(--r-md) 0; }

.search-input-wrap { position: relative; flex: 1 1 220px; min-width: 0; }
.search-input-wrap .input { padding-left: 34px; }
.search-input-wrap::before {
  content: ""; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; pointer-events: none;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.4' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='M20 20l-3.5-3.5'/></svg>") no-repeat center / contain;
}

/* checkbox / radio */
.check { display: inline-flex; align-items: flex-start; gap: var(--sp-2); cursor: pointer; font-size: .85rem; user-select: none; }
.check input { width: 17px; height: 17px; margin-top: 1px; flex: 0 0 auto; accent-color: var(--brand-600); cursor: pointer; }
.check-box-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-2); }
.check-box-list .check { padding: 7px var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-elev-2); }
.check-box-list .check:hover { border-color: var(--brand-300); }
.check-box-list .check:has(input:checked) { border-color: var(--brand-500); background: var(--brand-50); }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 42px; height: 24px; flex: 0 0 auto; border-radius: var(--r-full);
  background: var(--border-strong); transition: background .18s var(--ease); position: relative;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .18s var(--ease);
}
.switch input:checked + .switch-track { background: var(--ok-500); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .45; cursor: not-allowed; }
.switch-text { font-size: .85rem; }
.switch-text small { display: block; color: var(--text-muted); font-size: .75rem; }

/* segmented */
.segmented { display: inline-flex; padding: 3px; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--r-md); gap: 2px; overflow-x: auto; max-width: 100%; }
.segmented button {
  padding: 5px var(--sp-3); border-radius: var(--r-sm); font-size: .8rem; font-weight: 600;
  color: var(--text-muted); white-space: nowrap; transition: all .14s var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--bg-elev); color: var(--brand-700); box-shadow: var(--shadow-xs); }
html[data-theme="dark"] .segmented button.active { color: var(--brand-300); }

/* form sections */
.form-section { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--bg-elev); margin-bottom: var(--sp-4); overflow: hidden; }
.form-section-head {
  display: flex; align-items: center; gap: var(--sp-3); justify-content: space-between;
  padding: var(--sp-3) var(--sp-5); background: var(--bg-elev-2); border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
.form-section-head h4 { font-size: .92rem; display: flex; align-items: center; gap: var(--sp-2); }
.form-section-head .fs-sub { font-size: .75rem; color: var(--text-muted); font-weight: 400; }
.form-section-head .fs-caret { transition: transform .2s var(--ease); color: var(--text-faint); font-size: .7rem; }
.form-section.collapsed .fs-caret { transform: rotate(-90deg); }
.form-section.collapsed .form-section-body { display: none; }
.form-section-body { padding: var(--sp-5); }
.form-section.locked { border-color: var(--warn-100); }
.form-section.locked .form-section-head { background: var(--warn-50); }

.form-actions {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5); background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  position: sticky; bottom: var(--sp-4); box-shadow: var(--shadow-md); z-index: 20;
}
.unsaved-flag { display: inline-flex; align-items: center; gap: 6px; font-size: .79rem; color: var(--warn-700); font-weight: 600; }
html[data-theme="dark"] .unsaved-flag { color: var(--warn-500); }

/* ============================ ALERTS ============================ */
.alert {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--bg-sunken);
  font-size: .85rem; line-height: 1.5;
}
.alert-ico { font-size: 15px; line-height: 1.4; flex: 0 0 auto; }
.alert-body { min-width: 0; flex: 1 1 auto; }
.alert-body strong { display: block; margin-bottom: 1px; }
.alert.ok    { background: var(--ok-50);   border-color: var(--ok-100);   color: var(--ok-700); }
.alert.warn  { background: var(--warn-50); border-color: var(--warn-100); color: var(--warn-700); }
.alert.err   { background: var(--err-50);  border-color: var(--err-100);  color: var(--err-700); }
.alert.info  { background: var(--info-50); border-color: var(--info-100); color: var(--info-700); }
.alert.brand { background: var(--brand-50);border-color: var(--brand-100);color: var(--brand-800); }
html[data-theme="dark"] .alert.ok { color: #a7f3d0; } html[data-theme="dark"] .alert.warn { color: #fde68a; }
html[data-theme="dark"] .alert.err { color: #fecaca; } html[data-theme="dark"] .alert.info { color: #bfdbfe; }
html[data-theme="dark"] .alert.brand { color: var(--brand-200); }
.alert .alert-close { margin-left: auto; color: inherit; opacity: .6; font-size: 15px; }
.alert .alert-close:hover { opacity: 1; }

.lock-banner {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--warn-50), var(--bg-elev));
  border: 1px solid var(--warn-100); border-left: 4px solid var(--warn-500);
  font-size: .85rem;
}
.lock-banner strong { display: block; color: var(--warn-700); }
html[data-theme="dark"] .lock-banner strong { color: var(--warn-500); }
.lock-banner small { color: var(--text-muted); }
.lock-banner .lock-ico { font-size: 20px; }

/* ============================ TABLES ============================ */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { font-size: .85rem; min-width: 640px; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  padding: 10px var(--sp-4); text-align: left;
  font-size: .71rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table thead th.sortable { cursor: pointer; user-select: none; }
.table thead th.sortable:hover { color: var(--text); background: var(--bg-sunken); }
.table thead th .sort-ico { opacity: .35; margin-left: 4px; font-size: .68rem; }
.table thead th.sorted .sort-ico { opacity: 1; color: var(--brand-600); }
.table tbody td { padding: 11px var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s var(--ease); }
.table tbody tr:hover { background: var(--bg-elev-2); }
.table tbody tr.selected { background: var(--brand-50); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { padding: var(--sp-3) var(--sp-4); font-size: .79rem; color: var(--text-muted); background: var(--bg-elev-2); border-top: 1px solid var(--border); }
.table .cell-main { font-weight: 600; }
.table .cell-sub { font-size: .75rem; color: var(--text-muted); }
.table .cell-user { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.table .cell-user .avatar { width: 32px; height: 32px; font-size: .74rem; }
.table-rowlink { cursor: pointer; }
.table.dense tbody td { padding: 7px var(--sp-3); }
.table.dense thead th { padding: 8px var(--sp-3); }

/* mobile card-table */
@media (max-width: 860px) {
  .table.cards-mobile { min-width: 0; }
  .table.cards-mobile thead { display: none; }
  .table.cards-mobile tbody tr {
    display: block; border: 1px solid var(--border); border-radius: var(--r-md);
    margin: var(--sp-2) var(--sp-3); padding: var(--sp-2); background: var(--bg-elev);
  }
  .table.cards-mobile tbody tr:hover { background: var(--bg-elev); }
  .table.cards-mobile tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    border: 0; padding: 5px var(--sp-2); text-align: right;
  }
  .table.cards-mobile tbody td::before {
    content: attr(data-label); flex: 0 0 auto; text-align: left;
    font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
  }
  .table.cards-mobile tbody td[data-label=""]::before { display: none; }
  .table.cards-mobile tbody td .cell-user { justify-content: flex-end; }
  .table.cards-mobile tbody td.col-span { display: block; text-align: left; }
  .table.cards-mobile tbody td.col-span::before { display: block; margin-bottom: 3px; }
}

/* toolbar above tables */
.toolbar {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); background: var(--bg-elev-2);
}
.toolbar .spacer { flex: 1 1 auto; }
.bulk-bar {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-4); background: var(--brand-50);
  border-bottom: 1px solid var(--brand-100); font-size: .83rem; color: var(--brand-800);
}
html[data-theme="dark"] .bulk-bar { color: var(--brand-200); }

/* pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border);
  background: var(--bg-elev-2); flex-wrap: wrap;
}
.pagination-info { font-size: .79rem; color: var(--text-muted); }
.pagination-ctrls { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--bg-elev);
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
  display: grid; place-items: center; transition: all .14s var(--ease);
}
.page-btn:hover:not(:disabled) { border-color: var(--brand-400); color: var(--brand-600); }
.page-btn.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-ellipsis { padding: 0 4px; color: var(--text-faint); }

/* ============================ TABS ============================ */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px var(--sp-4); font-size: .86rem; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px;
  transition: all .15s var(--ease); display: inline-flex; align-items: center; gap: var(--sp-2);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--brand-600); border-bottom-color: var(--brand-600); }
.tab .tab-count { padding: 0 6px; border-radius: var(--r-full); background: var(--bg-sunken); font-size: .7rem; font-weight: 700; }
.tab.active .tab-count { background: var(--brand-100); color: var(--brand-700); }
.tab-panel { padding-top: var(--sp-5); }

/* ============================ PROGRESS ============================ */
.progress { height: 8px; width: 100%; background: var(--bg-sunken); border-radius: var(--r-full); overflow: hidden; border: 1px solid var(--border); }
.progress-bar { height: 100%; background: var(--brand-500); border-radius: var(--r-full); transition: width .5s var(--ease); }
.progress-bar.ok { background: var(--ok-500); } .progress-bar.warn { background: var(--warn-500); }
.progress-bar.err { background: var(--err-500); } .progress-bar.info { background: var(--info-500); }
.progress-bar.striped { background-image: linear-gradient(45deg, rgba(255,255,255,.18) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.18) 50%, rgba(255,255,255,.18) 75%, transparent 75%); background-size: 14px 14px; }
.progress-row { display: flex; align-items: center; gap: var(--sp-3); }
.progress-row .progress { flex: 1 1 auto; }
.progress-label { font-size: .78rem; font-weight: 650; color: var(--text-muted); min-width: 42px; text-align: right; }

.donut-mini { position: relative; width: 92px; height: 92px; flex: 0 0 auto; }
.donut-mini .donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut-mini .donut-center strong { font-size: 1.15rem; font-weight: 700; line-height: 1; }
.donut-mini .donut-center small { font-size: .62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ============================ DROPDOWN ============================ */
.dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 900;
  min-width: 210px; padding: var(--sp-2);
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); animation: ddIn .14s var(--ease);
}
.dropdown.left { right: auto; left: 0; }
.dropdown.up { top: auto; bottom: calc(100% + 6px); }
@keyframes ddIn { from { opacity: 0; transform: translateY(-5px) } to { opacity: 1; transform: none } }
.dropdown-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  padding: 8px var(--sp-3); border-radius: var(--r-sm); font-size: .85rem; color: var(--text);
  text-align: left; transition: background .12s var(--ease);
}
.dropdown-item:hover { background: var(--bg-sunken); text-decoration: none; }
.dropdown-item.danger { color: var(--err-600); }
.dropdown-item.danger:hover { background: var(--err-50); }
.dropdown-item.active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.dropdown-item small { margin-left: auto; color: var(--text-faint); font-size: .72rem; }
.dropdown-sep { height: 1px; background: var(--border); margin: var(--sp-2) 0; }
.dropdown-label { padding: var(--sp-2) var(--sp-3) 4px; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); }

/* ============================ MODAL ============================ */
.modal-host { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: var(--sp-4); }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,.55); backdrop-filter: blur(3px); animation: fadeIn .18s var(--ease); }
.modal {
  position: relative; width: 100%; max-width: 560px; max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl); animation: modalIn .2s var(--ease); overflow: hidden;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98) } to { opacity: 1; transform: none } }
.modal.sm { max-width: 420px; } .modal.md { max-width: 620px; }
.modal.lg { max-width: 860px; } .modal.xl { max-width: 1100px; }
.modal-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.modal-head h3 { font-size: 1.06rem; }
.modal-head .modal-sub { font-size: .81rem; color: var(--text-muted); margin-top: 2px; font-weight: 400; }
.modal-close { margin-left: auto; width: 32px; height: 32px; border-radius: var(--r-md); display: grid; place-items: center; color: var(--text-muted); font-size: 15px; flex: 0 0 auto; }
.modal-close:hover { background: var(--bg-sunken); color: var(--text); }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-elev-2); flex: 0 0 auto;
}
.modal-foot .left { margin-right: auto; }
.modal.danger .modal-head { background: var(--err-50); }
.modal.confirm .modal-ico {
  width: 44px; height: 44px; border-radius: var(--r-full); display: grid; place-items: center;
  font-size: 20px; flex: 0 0 auto; background: var(--warn-100); color: var(--warn-700);
}
.modal.confirm.danger .modal-ico { background: var(--err-100); color: var(--err-700); }
.modal.confirm .modal-body { font-size: .88rem; color: var(--text-muted); }

@media (max-width: 640px) {
  .modal-host { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 92vh; border-radius: var(--r-xl) var(--r-xl) 0 0; animation: sheetIn .24s var(--ease); }
  @keyframes sheetIn { from { transform: translateY(100%) } to { transform: none } }
  .modal-head { padding: var(--sp-4); }
  .modal-body { padding: var(--sp-4); }
  .modal-foot { padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 auto; }
}

/* ============================ DRAWER ============================ */
.drawer-host { position: fixed; inset: 0; z-index: 990; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,.5); animation: fadeIn .18s var(--ease); }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  display: flex; flex-direction: column;
  background: var(--bg-elev); border-left: 1px solid var(--border); box-shadow: var(--shadow-xl);
  animation: drawerIn .24s var(--ease);
}
@keyframes drawerIn { from { transform: translateX(100%) } to { transform: none } }
.drawer-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.drawer-body { padding: var(--sp-5); overflow-y: auto; flex: 1 1 auto; }
.drawer-foot { display: flex; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--bg-elev-2); flex-wrap: wrap; }

/* ============================ TOASTS ============================ */
.toast-host {
  position: fixed; z-index: 1200; top: var(--sp-4); right: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(380px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-lg);
  background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: .85rem; pointer-events: auto;
  animation: toastIn .24s var(--ease); border-left: 4px solid var(--text-faint);
}
.toast.out { animation: toastOut .2s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(28px) scale(.97) } to { opacity: 1; transform: none } }
@keyframes toastOut { to { opacity: 0; transform: translateX(28px) scale(.97) } }
.toast-ico { font-size: 16px; line-height: 1.4; flex: 0 0 auto; }
.toast-body { min-width: 0; flex: 1 1 auto; }
.toast-body strong { display: block; margin-bottom: 1px; }
.toast-body p { color: var(--text-muted); font-size: .81rem; margin: 0; }
.toast-close { color: var(--text-faint); font-size: 13px; flex: 0 0 auto; padding: 2px; }
.toast-close:hover { color: var(--text); }
.toast.success { border-left-color: var(--ok-500); }   .toast.success .toast-ico { color: var(--ok-600); }
.toast.error   { border-left-color: var(--err-500); }  .toast.error .toast-ico { color: var(--err-600); }
.toast.warning { border-left-color: var(--warn-500); } .toast.warning .toast-ico { color: var(--warn-600); }
.toast.info    { border-left-color: var(--info-500); } .toast.info .toast-ico { color: var(--info-600); }
.toast-progress { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--brand-400); border-radius: 0 0 0 var(--r-lg); }
@media (max-width: 640px) {
  .toast-host { top: auto; bottom: calc(var(--bottomnav-h) + 12px + env(safe-area-inset-bottom)); right: 12px; left: 12px; width: auto; }
}

/* ============================ SKELETONS ============================ */
.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-sm); color: transparent !important; user-select: none; pointer-events: none;
}
@keyframes shimmer { 0% { background-position: 100% 50% } 100% { background-position: 0 50% } }
.sk-line { height: 11px; margin: 6px 0; }
.sk-line.w40 { width: 40% } .sk-line.w60 { width: 60% } .sk-line.w80 { width: 80% }
.sk-title { height: 20px; width: 45%; margin-bottom: var(--sp-4); }
.sk-circle { border-radius: 50%; }
.sk-card { padding: var(--sp-5); background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg); }
.sk-stat { height: 96px; border-radius: var(--r-lg); }
.sk-row { height: 46px; border-radius: var(--r-sm); margin-bottom: var(--sp-2); }
.sk-table { padding: var(--sp-4); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--brand-500); border-radius: 50%; animation: spin .75s linear infinite; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.spinner.lg { width: 40px; height: 40px; border-width: 4px; }
.loading-overlay { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: color-mix(in srgb, var(--bg-elev) 72%, transparent); backdrop-filter: blur(1.5px); border-radius: inherit; }
.pos-rel { position: relative; }

/* ============================ EMPTY / ERROR STATES ============================ */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-12) var(--sp-6); text-align: center;
}
.empty-ico {
  width: 66px; height: 66px; border-radius: var(--r-full); display: grid; place-items: center;
  font-size: 28px; background: var(--bg-sunken); color: var(--text-faint);
  border: 1px solid var(--border);
}
.empty h3 { font-size: 1.02rem; }
.empty p { color: var(--text-muted); font-size: .86rem; max-width: 46ch; margin: 0; }
.empty .empty-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; margin-top: var(--sp-2); }
.empty.compact { padding: var(--sp-6) var(--sp-4); }
.empty.compact .empty-ico { width: 48px; height: 48px; font-size: 20px; }

.error-state {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-6); text-align: center;
}
.error-state .empty-ico { background: var(--err-50); color: var(--err-600); border-color: var(--err-100); }
.error-detail {
  font-family: var(--font-mono); font-size: .76rem; color: var(--text-muted);
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3); max-width: 100%; overflow-x: auto; text-align: left;
}

/* ============================ TIMELINE ============================ */
.timeline { position: relative; padding-left: var(--sp-6); }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: var(--sp-5); }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: calc(-1 * var(--sp-6) + 2px); top: 4px;
  width: 14px; height: 14px; border-radius: 50%; background: var(--bg-elev);
  border: 3px solid var(--border-strong);
}
.tl-item.ok .tl-dot { border-color: var(--ok-500); }
.tl-item.warn .tl-dot { border-color: var(--warn-500); }
.tl-item.err .tl-dot { border-color: var(--err-500); }
.tl-item.info .tl-dot { border-color: var(--info-500); }
.tl-item.brand .tl-dot { border-color: var(--brand-500); }
.tl-title { font-size: .87rem; font-weight: 650; }
.tl-meta { font-size: .75rem; color: var(--text-muted); margin-top: 1px; }
.tl-body { margin-top: var(--sp-2); font-size: .82rem; color: var(--text-muted); }

/* stepper */
.stepper { display: flex; align-items: flex-start; gap: 0; overflow-x: auto; padding-bottom: var(--sp-2); }
.step { flex: 1 1 0; min-width: 96px; text-align: center; position: relative; padding: 0 var(--sp-2); }
.step::before {
  content: ""; position: absolute; top: 13px; left: -50%; width: 100%; height: 2px; background: var(--border); z-index: 0;
}
.step:first-child::before { display: none; }
.step.done::before, .step.active::before { background: var(--brand-500); }
.step-dot {
  position: relative; z-index: 1; width: 28px; height: 28px; margin: 0 auto var(--sp-2);
  border-radius: 50%; display: grid; place-items: center; font-size: .74rem; font-weight: 700;
  background: var(--bg-elev); border: 2px solid var(--border-strong); color: var(--text-faint);
}
.step.done .step-dot { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.step.active .step-dot { border-color: var(--brand-600); color: var(--brand-600); box-shadow: 0 0 0 4px rgba(99,102,241,.16); }
.step.rejected .step-dot { background: var(--err-500); border-color: var(--err-500); color: #fff; }
.step-label { font-size: .72rem; font-weight: 650; color: var(--text-muted); line-height: 1.3; }
.step.active .step-label { color: var(--text); }
.step-meta { font-size: .66rem; color: var(--text-faint); }

/* ============================ KEY-VALUE / DETAILS ============================ */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--sp-4); }
.kv { min-width: 0; }
.kv dt, .kv-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 2px; }
.kv dd, .kv-value { font-size: .88rem; font-weight: 550; word-break: break-word; }
.kv-value.empty-val { color: var(--text-faint); font-style: italic; font-weight: 400; }
.kv-list { display: grid; gap: var(--sp-3); }
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-2) 0; border-bottom: 1px dashed var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { font-size: .81rem; color: var(--text-muted); }
.kv-row .v { font-size: .86rem; font-weight: 600; text-align: right; }

.def-list { display: grid; grid-template-columns: 170px 1fr; gap: var(--sp-3) var(--sp-4); font-size: .86rem; }
.def-list dt { color: var(--text-muted); font-size: .81rem; }
.def-list dd { font-weight: 550; word-break: break-word; }
@media (max-width: 640px) { .def-list { grid-template-columns: 1fr; gap: 2px 0; } .def-list dd { margin-bottom: var(--sp-3); } }

/* ============================ MISC ============================ */
.divider { height: 1px; background: var(--border); margin: var(--sp-4) 0; border: 0; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }
.kbd {
  display: inline-block; padding: 1px 6px; border-radius: var(--r-xs);
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  background: var(--bg-sunken); font-family: var(--font-mono); font-size: .72rem; color: var(--text-muted);
}
.link-btn { color: var(--brand-600); font-weight: 600; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }
.code-block {
  font-family: var(--font-mono); font-size: .79rem; line-height: 1.6;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); overflow-x: auto; white-space: pre;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%) translateY(3px);
  padding: 4px 8px; border-radius: var(--r-sm); background: #0f172a; color: #fff;
  font-size: .7rem; white-space: nowrap; opacity: 0; pointer-events: none; transition: all .15s var(--ease); z-index: 100;
}
.tooltip:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.scroll-y { overflow-y: auto; }
.sticky-col { position: sticky; left: 0; background: var(--bg-elev); z-index: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: var(--sp-4); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 720px)  { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .field.c2,.field.c3,.field.c4,.field.c5,.field.c6,.field.c7,.field.c8,.field.c9 { grid-column: span 12; }
  .form-actions { position: static; }
}
