/* ===== Shorter — Design Tokens + Role Theming =====
   M3 token block removed Phase 3 (2026-04-18). v2 tokens live at
   the tail of this file: R G B triples for --color-*, --radius-*,
   --shadow-*, --font-*, --text-scale. Page-level data-theme switches
   the palette; data-role switches sidebar identity + brand hue. */

:root {
  /* --- Sidebar (fixed dark across themes; role overrides below) --- */
  --sidebar-width: 260px;
  --sidebar-bg: #1e293b;
  --sidebar-text: #f1f5f9;
  --sidebar-text-muted: #94a3b8;
  --sidebar-active: #3b82f6;
  --sidebar-active-text: #ffffff;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-border: rgba(255,255,255,0.06);

  /* --- Topbar --- */
  --topbar-height: 64px;
  --topbar-bg: rgba(255,255,255,0.92);
  --topbar-border: #e2e8f0;
}

/* ===== Role Overrides — override sidebar + --color-primary brand hue =====
   Specificity (0,1,1) via html[...] beats [data-theme="X"] (0,1,0) so the
   role's brand color survives regardless of the chosen theme. */

html[data-role="superadmin"] {
  --sidebar-bg: #312e81;
  --sidebar-text: #e0e7ff;
  --sidebar-text-muted: #a5b4fc;
  --sidebar-active: #818cf8;
  --sidebar-active-text: #ffffff;
  --sidebar-hover: rgba(129,140,248,0.15);
  --sidebar-border: rgba(255,255,255,0.08);
  --color-primary:       99 102 241;   /* indigo-500 */
  --color-primary-soft:  224 231 255;  /* indigo-100 */
}

html[data-role="admin"] {
  --sidebar-bg: #064e3b;
  --sidebar-text: #d1fae5;
  --sidebar-text-muted: #6ee7b7;
  --sidebar-active: #10b981;
  --sidebar-active-text: #ffffff;
  --sidebar-hover: rgba(16,185,129,0.15);
  --sidebar-border: rgba(255,255,255,0.08);
  --color-primary:       15 118 110;   /* teal-700 (brand default) */
  --color-primary-soft:  209 250 229;  /* emerald-100 */
}

html[data-role="member"] {
  --sidebar-bg: #1e293b;
  --sidebar-text: #f1f5f9;
  --sidebar-text-muted: #94a3b8;
  --sidebar-active: #3b82f6;
  --sidebar-active-text: #ffffff;
  --sidebar-hover: rgba(59,130,246,0.15);
  --sidebar-border: rgba(255,255,255,0.08);
  --color-primary:       59 130 246;   /* blue-500 */
  --color-primary-soft:  219 234 254;  /* blue-100 */
}

/* ===== Global Base ===== */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: rgb(var(--color-text));
  background: rgb(var(--color-surface-muted));
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
a { color: rgb(var(--color-primary)); }

/* ===== Login / Blank Page Layout ===== */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, rgb(var(--color-surface-muted)) 0%, #e2e8f0 100%);
}

.login-card {
  width: 100%;
  max-width: 440px;
}

.login-card .card {
  padding: 32px;
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: rgb(var(--color-text));
  margin-top: 16px;
}

.login-header p {
  font-size: 14px;
  color: rgb(var(--color-text-muted));
  margin: 6px 0 0;
}

.brand-mark-lg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgb(var(--color-primary));
  color: rgb(var(--color-on-primary));
  font-weight: 700;
  font-size: 22px;
}

.login-form-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}

.login-actions button {
  background: none;
  border: none;
  color: rgb(var(--color-text-muted));
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}

.login-actions button:hover {
  color: rgb(var(--color-primary));
}

/* ===== Portal Shell ===== */

.shell {
  display: flex;
  min-height: 100vh;
}

.shell-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.shell-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.shell-topbar {
  position: sticky;
  top: 0;
  min-height: var(--topbar-height);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  padding: 12px 24px;
  z-index: 30;
  gap: 12px;
}

.shell-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ===== Topbar ===== */

.topbar-inner {
  flex: 1;
  min-width: 0;
}

.topbar-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgb(var(--color-surface-inset));
  color: rgb(var(--color-text-muted));
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: rgb(var(--color-text));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-subtitle {
  font-size: 13px;
  color: rgb(var(--color-text-muted));
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-hamburger {
  display: none;
  padding: 8px;
  margin: -8px;
  margin-right: 4px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-input);
  color: rgb(var(--color-text-muted));
  transition: background 0.15s;
}

.topbar-hamburger:hover {
  background: rgb(var(--color-surface-inset));
}

/* ===== Sidebar Components ===== */

.sidebar-brand {
  padding: 16px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-input);
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  min-width: 0;
}

.sidebar-brand-text h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--sidebar-text);
  line-height: 1.2;
}

.sidebar-brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--sidebar-text-muted);
}

/* ===== Project Selector ===== */

.sidebar-project-selector {
  padding: 10px 10px 0;
  flex-shrink: 0;
  position: relative;
}

.sidebar-selector-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-input);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  text-align: left;
}

.sidebar-selector-btn:hover {
  background: rgba(255,255,255,0.12);
}

.sidebar-selector-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-selector-info {
  flex: 1;
  min-width: 0;
}

.sidebar-selector-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-selector-slug {
  display: block;
  font-size: 12px;
  color: var(--sidebar-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-selector-chevron {
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.2s;
}

.sidebar-project-selector.open .sidebar-selector-chevron {
  transform: rotate(180deg);
}

/* Dropdown */
.sidebar-dropdown {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 100%;
  margin-top: 4px;
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-popup);
  z-index: 50;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}

.sidebar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-input);
  color: rgb(var(--color-text));
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-dropdown-item:hover {
  background: rgb(var(--color-surface-inset));
}

.sidebar-dropdown-item.active {
  background: rgba(99,102,241,0.08);
  color: rgb(var(--color-primary));
  font-weight: 600;
}

.sidebar-dropdown-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-dropdown-item-slug {
  font-size: 12px;
  color: rgb(var(--color-text-muted));
  flex-shrink: 0;
}

.sidebar-dropdown-empty {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: rgb(var(--color-text-muted));
}

.sidebar-dropdown-footer {
  border-top: 1px solid rgb(var(--color-border));
  margin-top: 4px;
  padding-top: 4px;
}

/* ===== Nav Scroll + Groups ===== */

.sidebar-nav-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

/* Sidebar navigation */
.sidebar-nav {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-nav-group-label {
  padding: 14px 12px 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-muted);
}

.sidebar-nav-group-label:first-child {
  padding-top: 6px;
}

.sidebar-nav-separator {
  height: 1px;
  background: var(--sidebar-border);
  margin: 8px 12px;
}

.sidebar-nav-hint {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--sidebar-text-muted);
  text-align: center;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-input);
  color: var(--sidebar-text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a,
.sidebar-nav button,
.sidebar-nav .sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-input);
  color: var(--sidebar-text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover,
.sidebar-nav button:hover,
.sidebar-nav .sidebar-nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-nav a.active,
.sidebar-nav button.active,
.sidebar-nav .sidebar-nav-item.active {
  background: var(--sidebar-hover);
  color: var(--sidebar-active-text);
  font-weight: 600;
  border-left: 3px solid var(--sidebar-active);
  padding-left: 13px;
}

/* Legacy admin link */
.sidebar-legacy-link {
  display: block;
  margin: 4px 10px;
  padding: 8px 14px;
  border-radius: var(--radius-input);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  color: var(--sidebar-text-muted);
  border: 1px solid var(--sidebar-border);
  transition: background 0.15s;
  flex-shrink: 0;
}

.sidebar-legacy-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

/* ===== Sidebar Footer ===== */

.sidebar-footer {
  padding: 8px 10px 12px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-footer-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-input);
  color: var(--sidebar-text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar-footer-profile:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-footer-profile.active {
  background: var(--sidebar-hover);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.sidebar-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 0;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role {
  display: block;
  font-size: 12px;
  color: var(--sidebar-text-muted);
  text-transform: capitalize;
}

.sidebar-logout-btn {
  background: none;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-input);
  color: var(--sidebar-text-muted);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}

.sidebar-logout-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--sidebar-text);
}

.sidebar-status-text {
  display: block;
  font-size: 12px;
  color: var(--sidebar-text-muted);
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-status-text:empty { display: none; }

/* ===== Page Sections ===== */

/* Sidebar overlay: always hidden by default, only shown on mobile when sidebar is open */
.sidebar-overlay { display: none; }

.page { display: none; }
.page.active { display: block; }

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: rgb(var(--color-text));
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 14px;
  color: rgb(var(--color-text-muted));
  line-height: 1.6;
  margin: 0 0 20px;
  max-width: 760px;
}

.page-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-toolbar h2 {
  font-size: 18px;
  font-weight: 600;
  margin-right: auto;
}

.section-helper {
  margin: 0 0 12px;
  font-size: 13px;
  color: rgb(var(--color-text-muted));
  line-height: 1.7;
}

.empty-state-card {
  padding: 40px 32px;
  border: 2px dashed rgb(var(--color-border));
  border-radius: var(--radius-popup);
  background: rgb(var(--color-surface));
  text-align: center;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 700;
  color: rgb(var(--color-text));
  margin-bottom: 8px;
}

.empty-state-body {
  font-size: 14px;
  line-height: 1.7;
  color: rgb(var(--color-text-muted));
  max-width: 400px;
  margin: 0 auto;
}

/* ===== Grid Layouts (CSS-only, no Tailwind needed) ===== */

.grid-cards {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
/* When grid-cards contains a table-wrap, don't constrain it */
.grid-cards > .table-wrap {
  grid-column: 1 / -1;
  min-width: 0;
}

.grid-2col {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

.grid-form {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.grid-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  position: sticky;
  top: var(--topbar-height);
  background: rgb(var(--color-surface-muted));
  z-index: 10;
  padding: 12px 0;
}

.grid-filters .field-input {
  width: auto;
  min-width: 140px;
}

.grid-filters input[type="search"] {
  min-width: 240px;
  flex: 1;
  max-width: 360px;
}

@media (min-width: 640px) {
  .grid-cards { grid-template-columns: repeat(2, 1fr); }
  .grid-form { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .grid-cards { grid-template-columns: repeat(3, 1fr); }
  .grid-2col { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Cards & Panels ===== */

.card {
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s;
}

.card:hover { box-shadow: var(--shadow-lift); }

.card-padded {
  padding: 22px 26px;
}

.card + .card {
  margin-top: 16px;
}

/* ===== Buttons ===== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-input);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.3;
  font-family: inherit;
}

.btn-primary {
  background: rgb(var(--color-primary));
  color: rgb(var(--color-on-primary));
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  border: 1px solid rgb(var(--color-border));
}
.btn-secondary:hover { background: rgb(var(--color-surface-inset)); }

.btn-danger {
  background: rgb(var(--color-error));
  color: rgb(var(--color-on-primary));
}
.btn-danger:hover { filter: brightness(1.1); }

.btn-text {
  background: transparent;
  color: rgb(var(--color-primary));
  padding: 6px 10px;
}
.btn-text:hover { background: rgba(0,0,0,0.04); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Compat: elements with just btn-primary/btn-secondary/btn-danger (no .btn parent) */
button.btn-primary, a.btn-primary,
button.btn-secondary, a.btn-secondary,
button.btn-danger, a.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-input);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.3;
  font-family: inherit;
}

button.btn-primary, a.btn-primary {
  background: rgb(var(--color-primary));
  color: rgb(var(--color-on-primary));
  border: none;
  box-shadow: 0 1px 3px rgba(14,124,102,0.2);
}
button.btn-primary:hover, a.btn-primary:hover { filter: brightness(1.1); transform: translateY(-0.5px); }

button.btn-secondary, a.btn-secondary {
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  border: 1px solid rgb(var(--color-border));
}
button.btn-secondary:hover, a.btn-secondary:hover { background: rgb(var(--color-surface-inset)); border-color: rgb(var(--color-border-strong)); }

button.btn-danger, a.btn-danger {
  background: transparent;
  color: rgb(var(--color-error));
  border: 1px solid rgb(var(--color-error));
}
button.btn-danger:hover, a.btn-danger:hover { background: rgba(220,38,38,0.08); }

.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-input);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.3;
  background: none;
  border: none;
}

/* ===== Form ===== */

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: rgb(var(--color-text-muted));
  margin-bottom: 4px;
}

.field-input {
  display: block;
  width: 100%;
  padding: 11px 14px;
  font-size: 14px;
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-input);
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.field-input:focus {
  outline: none;
  border-color: rgb(var(--color-primary));
  box-shadow: 0 0 0 3px rgba(14,124,102,0.12);
}

.field-input::placeholder { color: rgb(var(--color-text-muted)); opacity: 0.7; }

select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

textarea.field-input {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-group label {
  display: block;
}

/* Link create form: tighter layout */
#portal-link-form textarea.field-input {
  min-height: 56px;
}

#portal-link-form .actions {
  position: sticky;
  bottom: 0;
  background: rgb(var(--color-surface));
  padding: 12px 0 4px;
  z-index: 5;
  border-top: 1px solid rgb(var(--color-border));
  margin-top: 4px;
}

/* ===== Tags / Chips ===== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: rgb(var(--color-primary-soft));
  color: rgb(var(--color-primary));
}

/* ===== Status ===== */

.status-msg {
  font-size: 13px;
  color: rgb(var(--color-text-muted));
  min-height: 18px;
  line-height: 1.6;
}

.status-msg.error {
  color: rgb(var(--color-error));
}

/* ===== Record Cards ===== */

.record-card {
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 10px;
  transition: box-shadow 0.15s;
}

.record-card:hover {
  box-shadow: var(--shadow-card);
}

.record-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  color: rgb(var(--color-text));
}

.record-meta {
  font-size: 13px;
  color: rgb(var(--color-text-muted));
  line-height: 1.6;
}

/* ===== Link Cards ===== */

.link-card {
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 8px;
  background: rgb(var(--color-surface));
  transition: box-shadow 0.15s;
}

.link-card:hover { box-shadow: var(--shadow-lift); }

.link-card.selected {
  border-color: rgb(var(--color-primary));
  background: rgba(14,124,102,0.02);
}

.link-card.link-trashed { opacity: 0.6; }

.link-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.link-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-head-left strong {
  font-size: 15px;
  color: rgb(var(--color-primary));
  word-break: break-all;
}

.link-summary {
  font-size: 13px;
  line-height: 1.5;
  margin-top: 4px;
}

.link-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgb(var(--color-border));
  font-size: 12px;
}

/* ===== Dialog / Modal ===== */

dialog {
  border: none;
  border-radius: var(--radius-popup);
  box-shadow: var(--shadow-popup);
  padding: 24px;
  max-width: 480px;
  width: 90vw;
}

dialog::backdrop {
  background: rgba(0,0,0,0.5);
}

dialog h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ===== Portal.js Compat Components ===== */

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.field-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
  color: rgb(var(--color-text-muted));
  line-height: 1.6;
}

.note {
  padding: 10px 14px;
  background: rgb(var(--color-surface-inset));
  border-radius: var(--radius-input);
  font-size: 13px;
  line-height: 1.6;
  color: rgb(var(--color-text));
}

/* Invite/member page — truncate long URLs */
.card .mono { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .mono:hover { white-space: normal; word-break: break-all; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.preview-box {
  margin-top: 8px;
  padding: 8px 12px;
  background: rgb(var(--color-surface-inset));
  border-radius: var(--radius-input);
  font-size: 13px;
}

.preview-box .preview-title { font-weight: 600; margin-bottom: 2px; }
.preview-box .preview-description { font-size: 12px; }
.preview-box .preview-image-link { color: rgb(var(--color-primary)); font-size: 12px; }

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgb(var(--color-primary-soft));
  color: rgb(var(--color-primary));
  letter-spacing: 0.01em;
}

.check-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.check-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: rgb(var(--color-primary));
}

/* Portal-form compat (used by login.js / portal.js inline forms) */
.portal-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: rgb(var(--color-text-muted));
}

.portal-form input,
.portal-form select,
.portal-form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-input);
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  font-family: inherit;
}

.portal-form input:focus,
.portal-form select:focus,
.portal-form textarea:focus {
  outline: none;
  border-color: rgb(var(--color-primary));
  box-shadow: 0 0 0 3px rgba(14,124,102,0.1);
}

/* Preview card (link creation form) */
.preview-card {
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-card);
  overflow: hidden;
  background: rgb(var(--color-surface));
}

.preview-card img { max-width: 100%; height: auto; }

/* Preview details toggle */
.preview-details {
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-card);
  overflow: hidden;
}

.preview-details summary {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: rgb(var(--color-text-muted));
  cursor: pointer;
  transition: background 0.15s;
}

.preview-details summary:hover {
  background: rgb(var(--color-surface-inset));
}

.preview-details-body,
.preview-details > div:last-child {
  padding: 0 16px 16px;
}

/* ===== Utility ===== */

.hidden { display: none !important; }
.muted { color: rgb(var(--color-text-muted)); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-y > * + * { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }

/* ===== Responsive ===== */

@media (max-width: 1023px) {
  .shell-sidebar {
    transform: translateX(-100%);
  }

  .shell-sidebar.open {
    transform: translateX(0);
  }

  .shell-main {
    margin-left: 0;
  }

  .topbar-hamburger {
    display: flex;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 35;
    display: none;
  }

  .sidebar-overlay.open {
    display: block;
  }
}

@media (max-width: 640px) {
  .shell-content { padding: 16px; }
  .shell-topbar { padding: 8px 16px; }
  .login-card .card { padding: 24px; }
}

/* ===== Data Table ===== */
.table-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-input {
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}
.filter-select {
  min-width: 140px;
  max-width: 200px;
}
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: calc(100vw - var(--sidebar-width, 260px) - 48px);
}
@media (max-width: 1023px) {
  .table-wrap { max-width: calc(100vw - 32px); }
}
.data-table {
  min-width: 800px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
}
.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border, #e2e8f0);
}
.data-table thead th {
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-secondary, #f8fafc);
  position: sticky;
  top: 0;
}
.data-table tbody tr {
  transition: background 0.15s;
}
.data-table tbody tr:hover {
  background: var(--bg-secondary, #f8fafc);
}
.status-badge, .data-table .status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.02em;
}
.status-active, .data-table .status-active {
  background: #dcfce7;
  color: #166534;
}
.status-suspended, .data-table .status-suspended {
  background: #fef3c7;
  color: #92400e;
}
.status-inactive, .data-table .status-inactive {
  background: #f1f5f9;
  color: #64748b;
}
.data-table .project-link {
  color: var(--link, #3b82f6);
  text-decoration: none;
}
.data-table .project-link:hover {
  text-decoration: underline;
}
.data-table .text-muted {
  color: var(--text-secondary, #64748b);
}
.data-table .text-mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}
.data-table .row-actions {
  display: flex;
  gap: 4px;
  white-space: nowrap;
}
.data-table .row-actions button {
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid var(--border, #e2e8f0);
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.data-table .row-actions button:hover {
  background: var(--bg-secondary, #f8fafc);
}
.data-table .row-actions .row-btn-danger {
  color: #dc2626;
  border-color: #fecaca;
}
.data-table .row-actions .row-btn-danger:hover {
  background: #fef2f2;
}
.th-check {
  width: 36px;
  text-align: center;
}
.data-table td:first-child input[type="checkbox"],
.data-table th:first-child input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
/* Sortable table headers */
.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.sortable:hover {
  color: var(--primary, #6366f1);
}
.sort-indicator { margin-left: 2px; }
.sort-indicator::after { content: ""; opacity: 0.3; }
.sortable:hover .sort-indicator::after { content: "▼"; }
.sortable[data-sort-dir="desc"] .sort-indicator::after { content: "▼"; opacity: 1; }
.sortable[data-sort-dir="asc"] .sort-indicator::after { content: "▲"; opacity: 1; }
.data-table .text-right { text-align: right; font-variant-numeric: tabular-nums; }

/* Sticky right column (actions) */
.th-sticky-right {
  position: sticky;
  right: 0;
  background: var(--card-bg, #fff);
  box-shadow: -2px 0 4px rgba(0,0,0,0.06);
  z-index: 1;
}
thead .th-sticky-right {
  background: var(--table-header-bg, #f8fafc);
  z-index: 2;
}

.batch-action-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  font-size: 14px;
  flex-wrap: wrap;
}
.batch-action-bar .status-msg {
  margin-left: auto;
}
.btn-sm {
  padding: 4px 12px;
  font-size: 13px;
}
.btn-danger {
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover {
  background: #dc2626;
}
.btn-danger:disabled {
  background: #fca5a5;
  cursor: not-allowed;
}
#danger-confirm-dialog {
  max-width: 420px;
  width: 90vw;
}
#danger-confirm-dialog .dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
@media (max-width: 640px) {
  .table-filters {
    flex-direction: column;
  }
  .filter-input,
  .filter-select {
    max-width: 100%;
  }
}

/* ==================== Analytics Dashboard ==================== */
.ana-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.ana-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.ana-tz-label {
  font-size: 0.8rem;
  color: var(--text-secondary, #64748b);
  white-space: nowrap;
}
.ana-help-link {
  font-size: 0.8rem;
  color: var(--color-accent, #6c63ff);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.ana-help-link:hover {
  opacity: 1;
  text-decoration: underline;
}
.ana-range {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--color-surface, #f1f5f9);
  border: 1px solid var(--color-border, #e2e8f0);
}
.ana-range-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--color-text-secondary, #64748b);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.ana-range-btn.active {
  background: var(--color-accent, #6c63ff);
  color: #fff;
}
.ana-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.ana-filter-select {
  max-width: 180px;
  font-size: 0.8rem;
  padding: 6px 10px;
}

/* Advanced URL filter dropdown */
.ana-url-filter {
  position: relative;
}
.ana-url-filter-btn {
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ana-url-filter-btn::after {
  content: "▾";
  font-size: 0.7rem;
  margin-left: auto;
  opacity: 0.5;
}
.ana-url-filter-btn.ana-url-filter-active {
  border-color: var(--color-accent, #6c63ff);
  color: var(--color-accent, #6c63ff);
  background: #f0eeff;
}
.ana-url-filter-panel[hidden] {
  display: none !important;
}
.ana-url-filter-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 100;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 280px;
  max-width: 360px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ana-url-filter-modes {
  display: flex;
  gap: 2px;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 2px;
}
.ana-url-mode {
  flex: 1;
  padding: 5px 8px;
  font-size: 0.75rem;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  color: #64748b;
  font-weight: 500;
  transition: all 0.15s;
}
.ana-url-mode.active {
  background: #fff;
  color: #1e293b;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.ana-url-filter-input {
  font-size: 0.8rem !important;
  padding: 7px 10px !important;
}
.ana-url-filter-list {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ana-url-filter-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  font-size: 0.78rem;
  color: #334155;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}
.ana-url-filter-item:hover {
  background: #f8fafc;
}
.ana-url-filter-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--color-accent, #6c63ff);
}
.ana-url-filter-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ana-url-filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid #f1f5f9;
}
.ana-url-filter-actions .btn-text {
  font-size: 0.78rem;
  padding: 4px 10px;
}
.ana-url-filter-actions .btn-primary {
  font-size: 0.78rem;
  padding: 4px 14px;
  border-radius: 6px;
}

.ana-toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--color-text-secondary, #64748b);
  cursor: pointer;
  white-space: nowrap;
}
.ana-toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
}
.ana-refresh-note {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 16px;
}
.ana-refresh-note span {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border, #e2e8f0);
  font-size: 0.75rem;
  color: var(--color-text-secondary, #64748b);
}
.ana-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.ana-stat-card {
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-card, #ffffff);
}
.ana-stat-num {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
}
.ana-stat-label {
  margin-top: 4px;
  color: var(--color-text-secondary, #64748b);
  font-size: 0.8rem;
}
.ana-body {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(240px, 0.7fr);
  gap: 12px;
  margin-bottom: 12px;
}
.ana-bottom {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.ana-card {
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-card, #ffffff);
}
.ana-card h4 {
  margin: 0 0 12px;
  font-size: 0.88rem;
  font-weight: 700;
}
/* Bar chart */
.ana-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 180px;
}
.ana-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.ana-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #3b82f6, rgba(59, 130, 246, 0.35));
  transition: height 0.6s ease;
  cursor: default;
}
.ana-bar:hover {
  background: linear-gradient(180deg, #2563eb, rgba(37, 99, 235, 0.5));
}
.ana-bar-col span {
  font-size: 0.6rem;
  color: var(--color-text-secondary, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
/* Donut */
.ana-donut-shell {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 16px;
  align-items: center;
}
.ana-donut {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  mask: radial-gradient(circle, transparent 36px, black 37px);
  -webkit-mask: radial-gradient(circle, transparent 36px, black 37px);
}
.ana-device-legend {
  display: grid;
  gap: 8px;
}
.ana-device-legend div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--color-text-secondary, #64748b);
}
.ana-device-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
/* Geo / Hour / Lang rows */
.ana-geo-list, .ana-hour-list, .ana-lang-list {
  display: grid;
  gap: 8px;
}
.ana-geo-row, .ana-hour-row, .ana-lang-row {
  display: grid;
  grid-template-columns: auto minmax(48px, 100px) 1fr auto;
  gap: 8px;
  align-items: center;
}
.ana-flag { font-size: 1rem; }
.ana-name { color: var(--color-text-secondary, #64748b); font-size: 0.82rem; }
.ana-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--color-surface, #f1f5f9);
  overflow: hidden;
}
.ana-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #06b6d4);
  transition: width 0.6s ease;
}
.ana-fill.best {
  background: linear-gradient(90deg, #22c55e, #06b6d4);
}
.ana-pct { font-size: 0.75rem; color: var(--color-text-secondary, #64748b); }
/* Table */
.ana-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.ana-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  color: var(--color-text-secondary, #64748b);
  font-weight: 600;
}
.ana-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
}
/* Globe SVG */
.ana-card-wide { grid-column: 1 / -1; }
.ana-globe-svg {
  width: 100%;
  max-height: 220px;
  border-radius: 8px;
}
.ana-globe-svg circle {
  cursor: default;
  transition: r 0.3s ease;
}
.ana-globe-svg circle:hover {
  fill: rgba(59, 130, 246, 0.8);
}
/* Link mini analytics */
.link-mini-analytics {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--color-surface, #f1f5f9);
  border: 1px solid var(--color-border, #e2e8f0);
}
.link-ana-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.link-ana-stat {
  text-align: center;
}
.link-ana-stat strong {
  display: block;
  font-size: 1.1rem;
}
.link-ana-stat span {
  font-size: 0.75rem;
  color: var(--color-text-secondary, #64748b);
}
/* Responsive */
@media (max-width: 768px) {
  .ana-stats { grid-template-columns: repeat(2, 1fr); }
  .ana-body { grid-template-columns: 1fr; }
  .ana-bottom { grid-template-columns: 1fr; }
  .ana-donut-shell { grid-template-columns: 100px 1fr; }
  .ana-donut { width: 100px; height: 100px; }
}

/* ==================== Quick Create (Google-style) ==================== */
.qc-wrap {
  position: relative;
  background: linear-gradient(135deg, #f0fdf4 0%, #f8fafc 50%, #f0f9ff 100%);
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius-popup);
  box-shadow: var(--shadow-lift);
  padding: 28px 28px 20px;
  margin-bottom: 28px;
}
.qc-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--color-card, #ffffff);
  border: 2px solid var(--color-border, #e2e8f0);
  border-radius: 28px;
  height: 56px;
  padding: 0 6px 0 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.qc-bar:focus-within {
  border-color: var(--color-accent, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.qc-icon {
  flex-shrink: 0;
  padding: 0 12px 0 18px;
  font-size: 18px;
  line-height: 1;
}
.qc-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  height: 100%;
  min-width: 0;
  color: var(--color-text, #1e293b);
}
.qc-input::placeholder { color: var(--color-text-secondary, #94a3b8); }
.qc-domain {
  flex-shrink: 0;
  border: none;
  background: var(--color-surface, #f1f5f9);
  border-radius: 20px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--color-text-secondary, #64748b);
  cursor: pointer;
  max-width: 180px;
  margin-right: 6px;
}
.qc-btn {
  flex-shrink: 0;
  height: 44px;
  padding: 0 28px;
  border: none;
  border-radius: 22px;
  background: rgb(var(--color-primary));
  color: rgb(var(--color-on-primary));
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
.qc-btn:hover { background: #0a6b58; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(14,124,102,0.3); }
.qc-btn:disabled { background: #94a3b8; cursor: not-allowed; }
/* Result slide-out */
.qc-result {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 18px;
  margin-top: 12px;
  background: var(--color-surface, #f0fdf4);
  border: 1px solid #bbf7d0;
  border-radius: 12px;
  animation: qcSlideIn 0.3s ease;
}
@keyframes qcSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.qc-result-icon { font-size: 20px; }
.qc-result-url {
  font-size: 18px;
  font-weight: 700;
  color: rgb(var(--color-primary));
  text-decoration: none;
  word-break: break-all;
  font-family: var(--font-mono);
}
.qc-result-url:hover { text-decoration: underline; }
.qc-action-btn { font-size: 13px; padding: 6px 14px; border-radius: 8px; font-weight: 600; transition: all 0.15s; }
.qc-action-btn:hover { background: rgb(var(--color-primary-soft)); }
.qc-sub { margin-top: 8px; padding-left: 18px; }
/* Batch details */
.qc-batch-details { margin-top: 12px; }
.qc-batch-summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--color-text-secondary, #64748b);
  padding: 8px 0;
  user-select: none;
}
.qc-batch-body { padding-top: 8px; }
.qc-batch-text {
  width: 100%;
  min-height: 140px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-family: 'JetBrains Mono', monospace;
  resize: vertical;
}
/* Drop zone */
.qc-batch-drop {
  margin-top: 8px;
  border: 2px dashed var(--color-border, #cbd5e1);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.qc-batch-drop.dragover {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.05);
}
.qc-drop-content { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.qc-drop-icon { font-size: 28px; }
/* Batch config row */
.qc-batch-config {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
/* CSV mapping */
.qc-csv-map {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 8px;
  background: var(--color-surface, #f8fafc);
}
.qc-csv-title { font-weight: 700; margin-bottom: 10px; }
.qc-csv-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
}
.qc-csv-row .qc-csv-icon { width: 20px; text-align: center; }
.qc-csv-preview {
  margin-top: 10px;
  padding: 10px;
  border-radius: 6px;
  background: var(--color-card, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  font-size: 13px;
}
/* Progress panel */
.qc-batch-progress { margin-top: 12px; }
.qc-progress-bar {
  height: 8px;
  background: var(--color-surface, #e2e8f0);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.qc-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #3b82f6);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}
.qc-progress-text { font-size: 13px; color: var(--color-text-secondary, #64748b); margin-bottom: 8px; }
.qc-batch-items {
  max-height: 200px;
  overflow-y: auto;
  font-size: 13px;
}
.qc-batch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--color-border, #f1f5f9);
}
.qc-batch-item .qc-item-url {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-secondary, #64748b);
}
.qc-batch-actions { display: flex; gap: 8px; margin-top: 10px; }
.qc-batch-done {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  background: var(--color-surface, #f0fdf4);
  border: 1px solid #bbf7d0;
  font-size: 14px;
}
/* QR inline preview */
.qc-qr-preview {
  margin-top: 10px;
  text-align: center;
  animation: qcSlideIn 0.3s ease;
}
.qc-qr-preview canvas, .qc-qr-preview img {
  border-radius: 8px;
  border: 1px solid var(--color-border, #e2e8f0);
}
/* Result actions row */
.qc-result-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}
/* RWD */
@media (max-width: 768px) {
  .qc-wrap {
    padding: 16px;
    border-radius: 12px;
  }
  .qc-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px;
    border-radius: 16px;
    gap: 8px;
  }
  .qc-icon { display: none; }
  .qc-input {
    flex-basis: 100%;
    width: 100%;
    height: 48px;
    font-size: 15px;
    order: 1;
    border-bottom: 1px solid var(--color-border, #e2e8f0);
    padding-bottom: 8px;
  }
  .qc-domain {
    flex: 1;
    min-width: 0;
    order: 2;
    max-width: none;
    margin-right: 0;
  }
  .qc-btn {
    order: 3;
    flex-shrink: 0;
    height: 42px;
    min-width: 72px;
    padding: 0 20px;
    border-radius: 12px;
  }
  .qc-result {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .qc-result-url {
    font-size: 15px;
    word-break: break-all;
  }
  .qc-result-actions {
    justify-content: stretch;
  }
  .qc-action-btn {
    flex: 1;
    text-align: center;
    padding: 8px 0;
  }
  .qc-sub { display: none; }
  .qc-batch-summary { font-size: 13px; }
  .qc-batch-text { font-size: 13px; min-height: 120px; }
  .qc-batch-drop { padding: 16px; }
  .qc-batch-config { flex-direction: column; }
  .qc-batch-config select,
  .qc-batch-config input { max-width: none !important; width: 100%; }
}

/* ===== Global Toast ===== */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-input);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: var(--shadow-lift);
  animation: toast-in 0.25s ease-out;
  word-break: break-word;
}
.toast.toast-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}
.toast.toast-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.toast.toast-info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
.toast.toast-out {
  animation: toast-out 0.2s ease-in forwards;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ================================================================
   TOKENS V2 — New design token layer (Phase 1)
   R G B triples + theme switching + font-size scale + component layer.
   Coexists with M3 tokens above; M3 will be removed in Phase 3.
   ================================================================ */

/* ---- Token vars: R G B triples ---- */
:root,
[data-theme="light"] {
  --color-bg:              241 245 249;
  --color-surface:         255 255 255;
  --color-surface-muted:   248 250 252;
  --color-surface-inset:   241 245 249;
  --color-surface-strong:  226 232 240;

  --color-text:            15 23 42;
  --color-text-strong:     2 6 23;
  --color-text-secondary:  51 65 85;
  --color-text-body:       71 85 105;
  --color-text-muted:      100 116 139;
  --color-text-subtle:     148 163 184;

  --color-border:          226 232 240;
  --color-border-strong:   203 213 225;
  --color-border-subtle:   241 245 249;

  --color-primary:         15 118 110;
  --color-primary-soft:    204 251 241;
  --color-primary-muted:   153 246 228;
  --color-on-primary:      255 255 255;

  --color-success:         4 120 87;
  --color-success-soft:    209 250 229;
  --color-error:           185 28 28;
  --color-error-soft:      254 226 226;
  --color-warning:         180 83 9;
  --color-warning-soft:    254 243 199;

  --radius-chip:  4px;
  --radius-input: 8px;
  --radius-card:  12px;
  --radius-popup: 16px;
  --radius-xl:    28px;
  --radius-pill:  9999px;

  --shadow-card:  0 1px 3px 0 rgb(15 23 42 / 0.08), 0 1px 2px -1px rgb(15 23 42 / 0.06);
  --shadow-lift:  0 4px 6px -1px rgb(15 23 42 / 0.1), 0 2px 4px -2px rgb(15 23 42 / 0.08);
  --shadow-popup: 0 20px 25px -5px rgb(15 23 42 / 0.15), 0 8px 10px -6px rgb(15 23 42 / 0.1);

  --font-body: "Inter", "Noto Sans TC", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Consolas", monospace;

  --text-scale: 1;
}

[data-theme="dark"] {
  --color-bg:              15 23 42;
  --color-surface:         30 41 59;
  --color-surface-muted:   51 65 85;
  --color-surface-inset:   15 23 42;
  --color-surface-strong:  71 85 105;

  --color-text:            241 245 249;
  --color-text-strong:     248 250 252;
  --color-text-secondary:  203 213 225;
  --color-text-body:       186 200 219;
  --color-text-muted:      148 163 184;
  --color-text-subtle:     100 116 139;

  --color-border:          71 85 105;
  --color-border-strong:   100 116 139;
  --color-border-subtle:   51 65 85;

  --color-primary:         20 184 166;
  --color-primary-soft:    19 78 74;
  --color-primary-muted:   15 118 110;
  --color-on-primary:      255 255 255;

  --color-success:         52 211 153;
  --color-success-soft:    6 78 59;
  --color-error:           248 113 113;
  --color-error-soft:      127 29 29;
  --color-warning:         251 191 36;
  --color-warning-soft:    120 53 15;
}

[data-theme="sun"] {
  --color-bg:              255 251 235;
  --color-surface:         255 247 237;
  --color-surface-muted:   254 243 199;
  --color-surface-inset:   253 230 138;
  --color-surface-strong:  252 211 77;

  --color-text:            28 25 23;
  --color-text-strong:     12 10 9;
  --color-text-secondary:  68 64 60;
  --color-text-body:       87 83 78;
  --color-text-muted:      120 113 108;
  --color-text-subtle:     168 162 158;

  --color-border:          214 188 132;
  --color-border-strong:   180 152 101;
  --color-border-subtle:   245 231 186;

  --color-primary:         13 148 136;
  --color-primary-soft:    204 251 241;
  --color-primary-muted:   153 246 228;
  --color-on-primary:      255 255 255;
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --color-bg:              15 23 42;
    --color-surface:         30 41 59;
    --color-surface-muted:   51 65 85;
    --color-surface-inset:   15 23 42;
    --color-surface-strong:  71 85 105;

    --color-text:            241 245 249;
    --color-text-strong:     248 250 252;
    --color-text-secondary:  203 213 225;
    --color-text-body:       186 200 219;
    --color-text-muted:      148 163 184;
    --color-text-subtle:     100 116 139;

    --color-border:          71 85 105;
    --color-border-strong:   100 116 139;
    --color-border-subtle:   51 65 85;

    --color-primary:         20 184 166;
    --color-primary-soft:    19 78 74;
    --color-primary-muted:   15 118 110;
    --color-on-primary:      255 255 255;

    --color-success:         52 211 153;
    --color-success-soft:    6 78 59;
    --color-error:           248 113 113;
    --color-error-soft:      127 29 29;
    --color-warning:         251 191 36;
    --color-warning-soft:    120 53 15;
  }
}

/* ---- Font-size scale ---- */
[data-font-size="sm"] { --text-scale: 0.875; }
[data-font-size="md"] { --text-scale: 1; }
[data-font-size="lg"] { --text-scale: 1.125; }

/* ---- Theme transition helper (applied transiently by setTheme JS) ---- */
html.theme-transitions,
html.theme-transitions *,
html.theme-transitions *::before,
html.theme-transitions *::after {
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease !important;
}

/* ---- @layer base: raw form-control safety net ----
   Prevents white-text-on-white-bg when a future page uses a bare
   <input>/<textarea>/<select> without a proper .input class in dark mode.
   Unlayered rules below continue to win; this is only a fallback. */
@layer base {
  input:where(:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"])),
  textarea,
  select {
    background-color: rgb(var(--color-surface));
    color: rgb(var(--color-text));
  }
  input::placeholder,
  textarea::placeholder {
    color: rgb(var(--color-text-subtle));
  }
}

/* ---- Typography tier (12px 下限；用 --text-scale 做字級縮放) ---- */
.t-sm    { font-size: calc(12px * var(--text-scale, 1)); line-height: calc(16px * var(--text-scale, 1)); }
.t-md    { font-size: calc(14px * var(--text-scale, 1)); line-height: calc(20px * var(--text-scale, 1)); }
.t-lg    { font-size: calc(20px * var(--text-scale, 1)); line-height: calc(28px * var(--text-scale, 1)); }
.t-hero  { font-size: calc(32px * var(--text-scale, 1)); line-height: calc(40px * var(--text-scale, 1)); }

/* Legacy aliases (自動映射至 3 tier) */
.t-caption,
.t-label   { font-size: calc(12px * var(--text-scale, 1)); line-height: calc(16px * var(--text-scale, 1)); }
.t-body,
.t-section { font-size: calc(14px * var(--text-scale, 1)); line-height: calc(20px * var(--text-scale, 1)); }
.t-title   { font-size: calc(20px * var(--text-scale, 1)); line-height: calc(28px * var(--text-scale, 1)); }
.t-display { font-size: calc(32px * var(--text-scale, 1)); line-height: calc(40px * var(--text-scale, 1)); }

/* ---- Font weight ---- */
.fw-normal   { font-weight: 400; }
.fw-medium   { font-weight: 500; }
.fw-semibold { font-weight: 600; }
.fw-bold     { font-weight: 700; }

/* ---- Text colors ---- */
.c-text       { color: rgb(var(--color-text)); }
.c-strong     { color: rgb(var(--color-text-strong)); }
.c-secondary  { color: rgb(var(--color-text-secondary)); }
.c-body       { color: rgb(var(--color-text-body)); }
.c-muted      { color: rgb(var(--color-text-muted)); }
.c-subtle     { color: rgb(var(--color-text-subtle)); }
.c-primary    { color: rgb(var(--color-primary)); }
.c-on-primary { color: rgb(var(--color-on-primary)); }
.c-success    { color: rgb(var(--color-success)); }
.c-error      { color: rgb(var(--color-error)); }
.c-warning    { color: rgb(var(--color-warning)); }

/* ---- Backgrounds ---- */
.bg-page            { background-color: rgb(var(--color-bg)); }
.bg-surface         { background-color: rgb(var(--color-surface)); }
.bg-surface-muted   { background-color: rgb(var(--color-surface-muted)); }
.bg-surface-inset   { background-color: rgb(var(--color-surface-inset)); }
.bg-surface-strong  { background-color: rgb(var(--color-surface-strong)); }
.bg-primary         { background-color: rgb(var(--color-primary)); color: rgb(var(--color-on-primary)); }
.bg-primary-soft    { background-color: rgb(var(--color-primary-soft)); }
.bg-primary-muted   { background-color: rgb(var(--color-primary-muted)); }
.bg-primary-hover:hover { background-color: rgb(var(--color-primary) / 0.92); }
.bg-success-soft    { background-color: rgb(var(--color-success-soft)); }
.bg-error-soft      { background-color: rgb(var(--color-error-soft)); }
.bg-warning-soft    { background-color: rgb(var(--color-warning-soft)); }

/* ---- Borders ---- */
.b-default { border: 1px solid rgb(var(--color-border)); }
.b-strong  { border: 1px solid rgb(var(--color-border-strong)); }
.b-subtle  { border: 1px solid rgb(var(--color-border-subtle)); }
.b-focus   { border: 1px solid rgb(var(--color-primary)); }
.b-primary { border: 1px solid rgb(var(--color-primary)); }
.b-success { border: 1px solid rgb(var(--color-success)); }
.b-error   { border: 1px solid rgb(var(--color-error)); }
.b-warning { border: 1px solid rgb(var(--color-warning)); }

/* ---- Radius ---- */
.r-chip  { border-radius: var(--radius-chip); }
.r-input { border-radius: var(--radius-input); }
.r-card  { border-radius: var(--radius-card); }
.r-popup { border-radius: var(--radius-popup); }
.r-pill  { border-radius: var(--radius-pill); }

/* ---- Shadows ---- */
.s-card  { box-shadow: var(--shadow-card); }
.s-lift  { box-shadow: var(--shadow-lift); }
.s-popup { box-shadow: var(--shadow-popup); }

/* ---- Focus ring ---- */
.focus-ring:focus-visible {
  outline: none;
  border-color: rgb(var(--color-primary));
  box-shadow: 0 0 0 2px rgb(var(--color-primary) / 0.35);
}

/* ================================================================
   Component patterns (Phase 1) — placed in @layer components so that
   existing unlayered .card / .btn / .badge definitions above keep
   winning the cascade. This guarantees zero visual regression for
   pages still on M3 token classes. Phase 3 will drop the unlayered
   versions, at which point these patterns become canonical.
   ================================================================ */
@layer components {
  /* ---- Card ---- */
  .card {
    background: rgb(var(--color-surface));
    border: 1px solid rgb(var(--color-border));
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.2s;
  }
  .card:hover { box-shadow: var(--shadow-lift); }
  .card-flat {
    background: rgb(var(--color-surface));
    border: 1px solid rgb(var(--color-border));
    border-radius: var(--radius-card);
  }
  .card-body     { padding: 22px 26px; }
  .card-body-sm  { padding: 14px 18px; }

  /* ---- Buttons ---- */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-input);
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: filter 0.15s, background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    text-decoration: none;
    line-height: 1.3;
    font-family: inherit;
  }
  .btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgb(var(--color-primary) / 0.35);
  }

  /* Size modifiers */
  .btn-sm  { padding: 6px 12px; font-size: calc(12px * var(--text-scale, 1)); }
  .btn-md  { padding: 9px 16px; font-size: calc(14px * var(--text-scale, 1)); }
  .btn-lg  { padding: 11px 20px; font-size: calc(14px * var(--text-scale, 1)); }
  .btn-xl  { padding: 14px 24px; font-size: calc(16px * var(--text-scale, 1)); }
  .btn-pill { border-radius: var(--radius-pill); }

  /* Variants */
  .btn-primary {
    background: rgb(var(--color-primary));
    color: rgb(var(--color-on-primary));
  }
  .btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
  .btn-primary-soft {
    background: rgb(var(--color-primary-soft));
    color: rgb(var(--color-primary));
  }
  .btn-primary-soft:hover:not(:disabled) { background: rgb(var(--color-primary-muted)); }
  .btn-secondary {
    background: rgb(var(--color-surface));
    color: rgb(var(--color-text));
    border-color: rgb(var(--color-border));
  }
  .btn-secondary:hover:not(:disabled) {
    background: rgb(var(--color-surface-muted));
    border-color: rgb(var(--color-border-strong));
  }
  .btn-ghost {
    background: transparent;
    color: rgb(var(--color-text-secondary));
  }
  .btn-ghost:hover:not(:disabled) { background: rgb(var(--color-surface-muted)); color: rgb(var(--color-text)); }
  .btn-outline {
    background: transparent;
    color: rgb(var(--color-primary));
    border-color: rgb(var(--color-primary));
  }
  .btn-outline:hover:not(:disabled) { background: rgb(var(--color-primary-soft)); }
  .btn-danger {
    background: rgb(var(--color-error));
    color: rgb(var(--color-on-primary));
  }
  .btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
  .btn-danger-soft {
    background: rgb(var(--color-error-soft));
    color: rgb(var(--color-error));
  }
  .btn-danger-soft:hover:not(:disabled) { background: rgb(var(--color-error) / 0.16); }
  .btn-success {
    background: rgb(var(--color-success));
    color: rgb(var(--color-on-primary));
  }
  .btn-success:hover:not(:disabled) { filter: brightness(1.08); }
  .btn-warning {
    background: rgb(var(--color-warning));
    color: rgb(var(--color-on-primary));
  }
  .btn-warning:hover:not(:disabled) { filter: brightness(1.08); }

  /* ---- Form controls (self-contained, not modifiers) ---- */
  .input,
  .textarea,
  .select {
    display: block;
    width: 100%;
    padding: 10px 12px;
    font-size: calc(14px * var(--text-scale, 1));
    font-family: inherit;
    line-height: 1.4;
    background: rgb(var(--color-surface));
    color: rgb(var(--color-text));
    border: 1px solid rgb(var(--color-border));
    border-radius: var(--radius-input);
    transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
  }
  .input::placeholder,
  .textarea::placeholder {
    color: rgb(var(--color-text-subtle));
  }
  .input:focus,
  .textarea:focus,
  .select:focus {
    outline: none;
    border-color: rgb(var(--color-primary));
    box-shadow: 0 0 0 2px rgb(var(--color-primary) / 0.25);
  }
  .input:disabled,
  .textarea:disabled,
  .select:disabled {
    background: rgb(var(--color-surface-muted));
    color: rgb(var(--color-text-muted));
    cursor: not-allowed;
  }
  .input-sm { padding: 6px 10px; font-size: calc(12px * var(--text-scale, 1)); }
  .input-lg { padding: 12px 14px; font-size: calc(16px * var(--text-scale, 1)); }
  .textarea { resize: vertical; min-height: 80px; }
  .select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667085' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
  }
  .select-sm {
    padding: 6px 28px 6px 10px;
    font-size: calc(12px * var(--text-scale, 1));
    background-position: right 8px center;
  }
  .form-label {
    display: block;
    font-size: calc(12px * var(--text-scale, 1));
    font-weight: 600;
    color: rgb(var(--color-text-secondary));
    margin-bottom: 4px;
  }
  .form-hint {
    display: block;
    font-size: calc(12px * var(--text-scale, 1));
    color: rgb(var(--color-text-muted));
    margin-top: 4px;
  }
  .form-error {
    display: block;
    font-size: calc(12px * var(--text-scale, 1));
    color: rgb(var(--color-error));
    margin-top: 4px;
  }

  /* ---- Alert ---- */
  .alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    border-radius: var(--radius-input);
    font-size: calc(14px * var(--text-scale, 1));
    line-height: 1.5;
    border: 1px solid transparent;
  }
  .alert-info {
    background: rgb(var(--color-primary-soft));
    color: rgb(var(--color-primary));
    border-color: rgb(var(--color-primary) / 0.25);
  }
  .alert-success {
    background: rgb(var(--color-success-soft));
    color: rgb(var(--color-success));
    border-color: rgb(var(--color-success) / 0.25);
  }
  .alert-warning {
    background: rgb(var(--color-warning-soft));
    color: rgb(var(--color-warning));
    border-color: rgb(var(--color-warning) / 0.25);
  }
  .alert-error {
    background: rgb(var(--color-error-soft));
    color: rgb(var(--color-error));
    border-color: rgb(var(--color-error) / 0.25);
  }

  /* ---- Badge ---- */
  .badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-chip);
    font-size: calc(12px * var(--text-scale, 1));
    font-weight: 600;
    line-height: 1.5;
  }
  .badge-pill      { border-radius: var(--radius-pill); }
  .badge-neutral   { background: rgb(var(--color-surface-muted)); color: rgb(var(--color-text-secondary)); }
  .badge-primary   { background: rgb(var(--color-primary-soft)); color: rgb(var(--color-primary)); }
  .badge-success   { background: rgb(var(--color-success-soft)); color: rgb(var(--color-success)); }
  .badge-error     { background: rgb(var(--color-error-soft)); color: rgb(var(--color-error)); }
  .badge-warning   { background: rgb(var(--color-warning-soft)); color: rgb(var(--color-warning)); }

  /* ---- Table ---- */
  .table-th {
    text-align: left;
    padding: 10px 12px;
    font-size: calc(12px * var(--text-scale, 1));
    font-weight: 600;
    color: rgb(var(--color-text-secondary));
    background: rgb(var(--color-surface-muted));
    border-bottom: 1px solid rgb(var(--color-border));
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .table-td {
    padding: 10px 12px;
    font-size: calc(14px * var(--text-scale, 1));
    color: rgb(var(--color-text-body));
    border-bottom: 1px solid rgb(var(--color-border-subtle));
  }
  .table-row-hover tr:hover { background: rgb(var(--color-surface-muted)); }
  .table-divide > * + * { border-top: 1px solid rgb(var(--color-border-subtle)); }

  /* ---- Modal ---- */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.5);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
  }
  .modal-panel,
  .modal-panel-lg,
  .modal-panel-xl {
    background: rgb(var(--color-surface));
    color: rgb(var(--color-text));
    border: 1px solid rgb(var(--color-border));
    border-radius: var(--radius-popup);
    box-shadow: var(--shadow-popup);
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    padding: 24px;
  }
  .modal-panel    { max-width: 480px; }
  .modal-panel-lg { max-width: 720px; }
  .modal-panel-xl { max-width: 960px; }
  .modal-header {
    font-size: calc(18px * var(--text-scale, 1));
    font-weight: 700;
    color: rgb(var(--color-text));
    margin-bottom: 6px;
  }
  .modal-subtext {
    font-size: calc(14px * var(--text-scale, 1));
    color: rgb(var(--color-text-muted));
    margin-bottom: 16px;
  }

  /* ---- Sidebar primitives (fixed dark — do NOT follow data-theme) ---- */
  .sidebar-section-label {
    padding: 14px 12px 4px;
    font-size: calc(10px * var(--text-scale, 1));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
  }
  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-input);
    color: #cbd5e1;
    text-decoration: none;
    font-size: calc(13px * var(--text-scale, 1));
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
  }
  .sidebar-link:hover { background: rgb(255 255 255 / 0.08); color: #f1f5f9; }
  .sidebar-link-active {
    background: rgb(255 255 255 / 0.08);
    color: #ffffff;
    font-weight: 600;
    border-left: 3px solid var(--sidebar-active, #3b82f6);
    padding-left: 9px;
  }

  /* ---- Tabs ---- */
  .tab {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    font-size: calc(13px * var(--text-scale, 1));
    font-weight: 600;
    color: rgb(var(--color-text-muted));
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
  }
  .tab:hover { color: rgb(var(--color-text)); }
  .tab-active {
    color: rgb(var(--color-primary));
    border-bottom-color: rgb(var(--color-primary));
  }

  /* ---- Dividers ---- */
  .divider   { border: none; border-top: 1px solid rgb(var(--color-border-subtle)); margin: 12px 0; }
  .divider-v { border: none; border-left: 1px solid rgb(var(--color-border-subtle)); margin: 0 12px; align-self: stretch; }

  /* ---- Custom scrollbar (opt-in) ---- */
  .custom-scroll::-webkit-scrollbar        { width: 8px; height: 8px; }
  .custom-scroll::-webkit-scrollbar-track  { background: transparent; }
  .custom-scroll::-webkit-scrollbar-thumb  { background: rgb(var(--color-border-strong)); border-radius: var(--radius-pill); }
  .custom-scroll::-webkit-scrollbar-thumb:hover { background: rgb(var(--color-text-muted)); }
}
