/* Components, part 2: tabs, tables, pagination, alerts, overlays, data display. */

/* Inputs that sit outside a .field (inline table forms etc.) get the same control style */
:where(.content) :where(input:not([type=checkbox],[type=radio],[type=file],[type=hidden]), select, textarea) {
  min-height: var(--control-h-sm); padding: 4px 10px; background-color: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); font-size: var(--fs-secondary); max-width: 100%;
}
:where(.content) :where(input, select, textarea):focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }

/* ---------- Tabs ---------- */
.tab {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface);
  color: var(--text-2) !important; font-size: var(--fs-secondary); font-weight: 500; white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s; text-decoration: none !important; cursor: pointer;
}
.tab:hover { color: var(--text) !important; border-color: var(--border-strong); background: var(--surface-2); }
.tab.active, .toolbar .btn.secondary.active { background: var(--accent); border-color: var(--accent); color: #fff !important; }
.tab .count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-micro); font-weight: 600; margin: 0; }
.tab.active .count { background: rgba(255, 255, 255, .22); color: #fff; }
/* Underline tabs (in-page sections) */
.tabs-line { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); overflow-x: auto; scrollbar-width: none; }
.tabs-line::-webkit-scrollbar { display: none; }
.tabs-line button, .tabs-line a {
  display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 var(--sp-4); margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-3) !important;
  font-size: var(--fs-secondary); font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.tabs-line button:hover, .tabs-line a:hover { color: var(--text) !important; }
.tabs-line .active, .tabs-line [aria-selected=true] { color: var(--text) !important; border-bottom-color: var(--accent); }
.tabs-line .count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-micro); display: inline-grid; place-items: center; }
[data-tabpanel][hidden] { display: none !important; }

/* ---------- Tables ---------- */
.table-scroll { overflow: auto; max-width: 100%; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.panel .table-scroll, .card .table-scroll { border-radius: var(--r-md); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-table); }
th, td { padding: 12px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--text-3);
  font-size: var(--fs-helper); font-weight: 600; letter-spacing: .01em;
}
tr:last-child > td { border-bottom: 0; }
tbody tr, table tr { transition: background .12s; }
table tr:hover > td { background: var(--surface-hover); }
td .muted, td small { color: var(--text-3); font-size: var(--fs-helper); }
td.wrap, td[style*="white-space:normal"] { white-space: normal; line-height: 1.55; }
td.empty, .empty { color: var(--text-3); text-align: center; }
table tr:hover > td.empty { background: transparent; }
.table-meta { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-top: var(--sp-3); font-size: var(--fs-helper); color: var(--text-3); flex-wrap: wrap; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user b { display: block; font-weight: 600; color: var(--text); }
.cell-user small { display: block; }

/* Pagination (client-side, see app.js) */
.pagination { display: inline-flex; gap: 4px; align-items: center; }
.pagination button { min-width: 32px; height: 32px; padding: 0 8px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: var(--fs-helper); font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.pagination button:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination button:disabled { opacity: .4; cursor: default; }

/* Empty state */
.empty { padding: var(--sp-6) var(--sp-4); font-size: var(--fs-secondary); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--text-3); }
.empty-state .i { width: 34px; height: 34px; color: var(--text-3); opacity: .7; }
.empty-state b { color: var(--text); font-size: var(--fs-body); }

/* ---------- Alerts / notices / flash ---------- */
/* Block (not flex) so mixed inline text, <b> and inline forms keep normal text flow */
.notice, .alert {
  display: block; position: relative; padding: 12px 46px 12px var(--sp-4); margin-bottom: var(--sp-4);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: var(--r-md);
  background: var(--accent-soft); color: var(--text); font-size: var(--fs-secondary); line-height: 1.65;
}
.notice { --notice-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E"); }
.notice::before { content: ""; position: absolute; right: var(--sp-4); top: 14px; width: 18px; height: 18px; background: var(--accent-text);
  -webkit-mask: var(--notice-icon) center / contain no-repeat; mask: var(--notice-icon) center / contain no-repeat; }
.notice.warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }
.notice.warn::before { background: var(--warning-text); }
.notice.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.notice.danger::before { background: var(--danger-text); }
.notice.success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.notice.success::before { background: var(--success-text); }
.notice > :last-child { margin-bottom: 0; }
.notice form { display: inline; }

.flash {
  display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-4) var(--sp-6) 0; padding: 12px var(--sp-4);
  border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-secondary); font-weight: 500; box-shadow: var(--shadow-sm);
  animation: flash-in .25s var(--ease);
}
.flash.success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 40%, transparent); color: var(--success-text); }
.flash.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger-text); }
.flash.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent-text); }
.flash .flash-close { margin-inline-start: auto; color: inherit; opacity: .7; }
.flash.hide { opacity: 0; transform: translateY(-4px); transition: opacity .3s, transform .3s; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Toast stack (app.js → CDMS.toast) */
.toasts { position: fixed; z-index: 80; bottom: var(--sp-5); left: var(--sp-5); display: grid; gap: var(--sp-2); width: min(360px, calc(100vw - 32px)); }
.toast { display: flex; gap: var(--sp-3); align-items: center; padding: 12px var(--sp-4); border-radius: var(--r-md); background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); font-size: var(--fs-secondary); animation: flash-in .2s var(--ease); }
.toast.success .i { color: var(--success-text); }
.toast.error .i { color: var(--danger-text); }

/* ---------- Modal / confirm dialog ---------- */
dialog.modal { border: 0; padding: 0; background: transparent; color: var(--text); max-width: min(520px, calc(100vw - 32px)); width: 100%; }
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
.modal-box { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) 0; }
.modal-head h3 { margin: 0; font-size: var(--fs-section); font-weight: 600; }
.modal-icon { width: 40px; height: 40px; border-radius: var(--r-lg); display: grid; place-items: center; background: var(--warning-soft); color: var(--warning-text); flex: 0 0 auto; }
.modal-icon.danger { background: var(--danger-soft); color: var(--danger-text); }
.modal-body { padding: var(--sp-3) var(--sp-5) var(--sp-5); color: var(--text-2); font-size: var(--fs-secondary); }
.modal-foot { display: flex; gap: var(--sp-2); justify-content: flex-start; padding: var(--sp-4) var(--sp-5); background: var(--surface-2); border-top: 1px solid var(--border); }

/* ---------- Dropdown / context menu ---------- */
.dropdown { position: relative; display: inline-flex; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60; min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  display: none; direction: rtl;
}
.dropdown.open > .menu { display: block; animation: flash-in .14s var(--ease); }
.menu.end { left: auto; right: 0; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text) !important; font-size: var(--fs-secondary); text-align: right; cursor: pointer; text-decoration: none !important;
}
.menu a:hover, .menu button:hover { background: var(--surface-3); }
.menu .i { width: 16px; height: 16px; color: var(--text-3); }
.menu .danger, .menu .danger .i { color: var(--danger-text) !important; }
.menu hr { margin: 6px 0; }
.menu form { margin: 0; }
.menu-head { padding: 10px 10px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-head b { display: block; font-size: var(--fs-secondary); }
.menu-head small { color: var(--text-3); }

/* ---------- Tooltip ([data-tip]) ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  padding: 6px 10px; border-radius: var(--r-sm); background: #050a14; color: #e7edf7; border: 1px solid var(--border-strong);
  font-size: var(--fs-micro); font-weight: 500; white-space: nowrap; z-index: 70; pointer-events: none; box-shadow: var(--shadow-md);
}

/* ---------- Avatar ---------- */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; flex: 0 0 auto;
  background: linear-gradient(135deg, #2b4c7e, #1d3357); color: #dce8ff; font-weight: 700; font-size: 12px; letter-spacing: .02em;
  border: 1px solid rgba(255, 255, 255, .08);
}
:root[data-theme="light"] .content .avatar { background: linear-gradient(135deg, #dbe7fb, #c7d8f5); color: #1e3a6b; border-color: #c7d6ee; }
.avatar.sm { width: 28px; height: 28px; font-size: 10.5px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }

/* ---------- Key/value, timeline, comments ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 170px) 1fr; gap: 10px var(--sp-4); font-size: var(--fs-secondary); margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0 22px 0 0; border-right: 0; position: relative; }
.timeline::before { content: ""; position: absolute; right: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); border-radius: 2px; }
.timeline li { position: relative; padding: 0 0 var(--sp-4); font-size: var(--fs-secondary); line-height: 1.6; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; right: -22px; top: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); box-sizing: border-box; }
.timeline li.internal::before { border-color: var(--purple); }
.timeline li.completed::before, .timeline li.approved::before { border-color: var(--success); }
.timeline li.rejected::before, .timeline li.cancelled::before { border-color: var(--danger); }
.timeline b { font-size: var(--fs-secondary); font-weight: 600; color: var(--text); }
.timeline span { color: var(--text-2); }
.timeline small { color: var(--text-3); font-size: var(--fs-helper); }

.comment { border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; margin-bottom: var(--sp-3); background: var(--surface-2); font-size: var(--fs-secondary); }
.comment.internal { background: var(--purple-soft); border-color: color-mix(in srgb, var(--purple) 30%, transparent); }
.comment .meta { font-size: var(--fs-helper); color: var(--text-3); margin-bottom: 6px; }
.comment .meta b { color: var(--text); }

/* Tree (org chart) */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-right: 22px; border-right: 1px dashed var(--border-strong); padding-right: 14px; }
.tree li { padding: 6px 0; }
.tree .node { display: inline-flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 8px 12px; font-size: var(--fs-secondary); }
.tree .node small { color: var(--text-3); display: block; }

/* Permission grid */
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px var(--sp-5); font-size: var(--fs-secondary); }
.perm-grid label { display: flex; gap: var(--sp-2); align-items: center; padding: 7px 8px; border-radius: var(--r-sm); cursor: pointer; }
.perm-grid label:hover { background: var(--surface-2); }
.perm-grid input { width: 17px; }

details.edit > summary { cursor: pointer; color: var(--accent-text); font-size: var(--fs-helper); font-weight: 600; list-style: none; margin-top: var(--sp-2); display: inline-flex; align-items: center; gap: 4px; }
details.edit > summary::-webkit-details-marker { display: none; }
details.edit > summary::before { content: "＋"; font-size: 11px; }
details.edit[open] > summary::before { content: "－"; }
details.edit[open] { margin-top: var(--sp-2); }

/* Meter / progress */
.meter { height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-pill); }
.meter.green span { background: var(--success); }
.meter.amber span { background: var(--warning); }
.meter.red span { background: var(--danger); }
:where(.content) :where(select:not([multiple])) {
  appearance: none; -webkit-appearance: none; padding-inline-end: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2373839f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 10px center; background-size: 16px;
}
.field select, .filters select { padding-inline-end: 34px; }

/* Wide tables: keep the actions column visible at the end edge while the rest scrolls */
@media (min-width: 761px) {
  table.sticky-actions tr > :last-child { position: sticky; left: 0; z-index: 2; background: var(--surface); box-shadow: 8px 0 12px -10px rgba(0, 0, 0, .5) inset; }
  table.sticky-actions tr > th:last-child { background: var(--surface-2); z-index: 3; }
  table.sticky-actions tr:hover > td:last-child { background: var(--surface-hover); }
}
table.sticky-actions td { padding-inline: 12px; }

/* Tables fit their container: long text wraps; dates, numbers, codes and badges never break */
td { white-space: normal; line-height: 1.5; }
th { white-space: nowrap; }
td.num, td .num, td .ltr, td .status, td .code, td .btn, td .actions { white-space: nowrap; }
td:has(> .status:only-child), td.num { white-space: nowrap; }
th, td { padding: 11px 12px; }
.table-scroll.overflowing { background:
  linear-gradient(to left, var(--surface) 30%, transparent) right center / 24px 100% no-repeat local,
  linear-gradient(to right, var(--surface) 30%, transparent) left center / 24px 100% no-repeat local,
  radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.35), transparent) right center / 12px 100% no-repeat scroll,
  radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.35), transparent) left center / 12px 100% no-repeat scroll, var(--surface); }
.content td a[href^="/requests/"], .content td .ltr { white-space: nowrap; }
td .actions { flex-wrap: nowrap; }
