/* ===== Shorter — M3 Design Tokens + Role Theming ===== */
/* All structural layouts are CSS-only. Tailwind CDN is optional enhancement. */

:root {
  /* --- M3 Baseline Tokens --- */
  --md-sys-color-primary: #0e7c66;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #b2f5e3;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-surface-variant: #f1f5f9;
  --md-sys-color-on-surface: #1c1b1f;
  --md-sys-color-on-surface-variant: #64748b;
  --md-sys-color-background: #f8fafc;
  --md-sys-color-outline: #e2e8f0;
  --md-sys-color-outline-variant: #cbd5e1;
  --md-sys-color-error: #dc2626;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-warning: #d97706;

  /* --- Shape --- */
  --md-sys-shape-corner-xs: 4px;
  --md-sys-shape-corner-sm: 8px;
  --md-sys-shape-corner-md: 12px;
  --md-sys-shape-corner-lg: 16px;
  --md-sys-shape-corner-xl: 28px;

  /* --- Elevation --- */
  --md-sys-elevation-0: none;
  --md-sys-elevation-1: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);
  --md-sys-elevation-2: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --md-sys-elevation-3: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);

  /* --- Typography --- */
  --md-sys-typescale-body-font: "Inter", "Noto Sans TC", system-ui, sans-serif;
  --md-sys-typescale-mono-font: "JetBrains Mono", "Fira Code", "Consolas", monospace;

  /* --- Sidebar --- */
  --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 ===== */

[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);
  --md-sys-color-primary: #6366f1;
  --md-sys-color-primary-container: #e0e7ff;
}

[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);
  --md-sys-color-primary: #0e7c66;
  --md-sys-color-primary-container: #d1fae5;
}

[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);
  --md-sys-color-primary: #3b82f6;
  --md-sys-color-primary-container: #dbeafe;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--md-sys-typescale-body-font);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-background);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
a { color: var(--md-sys-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, var(--md-sys-color-background) 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: var(--md-sys-color-on-surface);
  margin-top: 16px;
}

.login-header p {
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
  margin: 6px 0 0;
}

.brand-mark-lg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-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: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}

.login-actions button:hover {
  color: var(--md-sys-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: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  flex-shrink: 0;
}

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

.topbar-subtitle {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  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(--md-sys-shape-corner-sm);
  color: var(--md-sys-color-on-surface-variant);
  transition: background 0.15s;
}

.topbar-hamburger:hover {
  background: var(--md-sys-color-surface-variant);
}

/* ===== 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(--md-sys-shape-corner-sm);
  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(--md-sys-shape-corner-sm);
  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: 11px;
  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: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-md);
  box-shadow: var(--md-sys-elevation-3);
  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(--md-sys-shape-corner-sm);
  color: var(--md-sys-color-on-surface);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-dropdown-item:hover {
  background: var(--md-sys-color-surface-variant);
}

.sidebar-dropdown-item.active {
  background: rgba(99,102,241,0.08);
  color: var(--md-sys-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: 11px;
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
}

.sidebar-dropdown-empty {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}

.sidebar-dropdown-footer {
  border-top: 1px solid var(--md-sys-color-outline);
  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: 10px;
  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(--md-sys-shape-corner-sm);
  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(--md-sys-shape-corner-sm);
  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(--md-sys-shape-corner-sm);
  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(--md-sys-shape-corner-sm);
  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: 10px;
  color: var(--sidebar-text-muted);
  text-transform: capitalize;
}

.sidebar-logout-btn {
  background: none;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--md-sys-shape-corner-sm);
  color: var(--sidebar-text-muted);
  font-size: 11px;
  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: 10px;
  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: var(--md-sys-color-on-surface);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
  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: var(--md-sys-color-on-surface-variant);
  line-height: 1.7;
}

.empty-state-card {
  padding: 40px 32px;
  border: 2px dashed var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-lg);
  background: var(--md-sys-color-surface);
  text-align: center;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 8px;
}

.empty-state-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface-variant);
  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: var(--md-sys-color-background);
  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: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-md);
  box-shadow: var(--md-sys-elevation-1);
  transition: box-shadow 0.2s;
}

.card:hover { box-shadow: var(--md-sys-elevation-2); }

.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(--md-sys-shape-corner-sm);
  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: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
}
.btn-secondary:hover { background: var(--md-sys-color-surface-variant); }

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

.btn-text {
  background: transparent;
  color: var(--md-sys-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(--md-sys-shape-corner-sm);
  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: var(--md-sys-color-primary);
  color: var(--md-sys-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: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
}
button.btn-secondary:hover, a.btn-secondary:hover { background: var(--md-sys-color-surface-variant); border-color: var(--md-sys-color-outline-variant); }

button.btn-danger, a.btn-danger {
  background: transparent;
  color: var(--md-sys-color-error);
  border: 1px solid var(--md-sys-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(--md-sys-shape-corner-sm);
  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: var(--md-sys-color-on-surface-variant);
  margin-bottom: 4px;
}

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

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

.field-input::placeholder { color: var(--md-sys-color-on-surface-variant); 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: var(--md-sys-color-surface);
  padding: 12px 0 4px;
  z-index: 5;
  border-top: 1px solid var(--md-sys-color-outline);
  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: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-primary);
}

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

.status-msg {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  min-height: 18px;
  line-height: 1.6;
}

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

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

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

.record-card:hover {
  box-shadow: var(--md-sys-elevation-1);
}

.record-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--md-sys-color-on-surface);
}

.record-meta {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
}

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

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

.link-card:hover { box-shadow: var(--md-sys-elevation-2); }

.link-card.selected {
  border-color: var(--md-sys-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: var(--md-sys-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 var(--md-sys-color-outline);
  font-size: 12px;
}

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

dialog {
  border: none;
  border-radius: var(--md-sys-shape-corner-lg);
  box-shadow: var(--md-sys-elevation-3);
  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(--md-sys-typescale-mono-font);
  font-size: 13px;
  word-break: break-all;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
}

.note {
  padding: 10px 14px;
  background: var(--md-sys-color-surface-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  font-size: 13px;
  line-height: 1.6;
  color: var(--md-sys-color-on-surface);
}

/* 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: var(--md-sys-color-surface-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  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: var(--md-sys-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: var(--md-sys-color-primary-container);
  color: var(--md-sys-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: var(--md-sys-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: var(--md-sys-color-on-surface-variant);
}

.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 var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-sm);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
}

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

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

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

/* Preview details toggle */
.preview-details {
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-md);
  overflow: hidden;
}

.preview-details summary {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background 0.15s;
}

.preview-details summary:hover {
  background: var(--md-sys-color-surface-variant);
}

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

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

.hidden { display: none !important; }
.muted { color: var(--md-sys-color-on-surface-variant); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-mono { font-family: var(--md-sys-typescale-mono-font); }
.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 var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-lg);
  box-shadow: var(--md-sys-elevation-2);
  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: var(--md-sys-color-primary);
  color: var(--md-sys-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: var(--md-sys-color-primary);
  text-decoration: none;
  word-break: break-all;
  font-family: var(--md-sys-typescale-mono-font);
}
.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: var(--md-sys-color-primary-container); }
.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(--md-sys-shape-corner-sm, 8px);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: var(--md-sys-elevation-2);
  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); }
}
