/* =============================================================================
   CSS CUSTOM PROPERTIES - THEME SYSTEM
   Modern color system with comprehensive dark/light mode support
   ============================================================================= */

:root {
  /* Primary Colors - Light blues theme */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #8b93a6;
  --secondary-hover: #6b7280;
  --success: #059669;
  --success-hover: #047857;
  --info: #0ea5e9;
  --info-hover: #0284c7;
  --warning: #d97706;
  --warning-hover: #b45309;
  --danger: #dc2626;
  --danger-hover: #b91c1c;

    /* Disclaimer warning color */
    --disclaimer-color: var(--warning);

  /* Background Tokens - Clean Light Mode */
  --bg: #eef2f7;
  --bg-elev-1: #e2e8f0;
  --bg-elev-2: #d5dce6;
  --surface: #ffffff;
  --surface-alt: #e2e8f0;

  /* Map existing background variables */
  --bg-primary: var(--bg);
  --bg-secondary: var(--bg-elev-1);
  --bg-tertiary: var(--bg-elev-2); /* Middle gray-blue for better contrast */
  --bg-card: var(--surface);

  /* Text Tokens */
  --text: #1b232c;
  --text-muted: #344351;

  /* Map existing text variables */
  --text-primary: var(--text);
  --text-secondary: var(--text-muted);
  --chip-text: #1b232c;

  /* Border & Shadow - Light grays */
  --border: #cbd5e1;
  --border-hover: #94a3b8;
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.15), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.15), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  /* Metal-specific Colors - tuned for light mode (WCAG AA on #eef2f7) */
  --silver: #5f6673;
  --gold: #a04808;
  --platinum: #4b5563;
  --palladium: #6d35d0;

  /* Inventory Type Colors (darkened for text readability on light backgrounds) */
  --type-coin-bg: #b85f00;
  --type-coin-text: #ffffff;
  --type-round-bg: #5a6170;
  --type-round-text: #f8fafc;
  --type-bar-bg: #946d00;
  --type-bar-text: #ffffff;
  --type-note-bg: #047857;
  --type-note-text: #f8fafc;
  --type-set-bg: #8B5CF6;
  --type-set-text: #ffffff;
  --type-other-bg: #6d35d0;
  --type-other-text: #f8fafc;

  /* Component Spacing */
  --radius: 8px;
  --radius-lg: 12px;
  --spacing-xs: 0.2rem;
  --spacing-sm: 0.4rem;
  --spacing: 0.75rem;
  --spacing-lg: 1.25rem;
  --spacing-xl: 1.5rem;

  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  /* Primary Colors - Dark Mode */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #6b7280;
  --secondary-hover: #9ca3af;
  --success: #10b981;
  --success-hover: #059669;
  --info: #38bdf8;
  --info-hover: #0ea5e9;
  --warning: #f59e0b;
  --warning-hover: #d97706;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  /* Disclaimer warning color */
  --disclaimer-color: var(--danger);

  /* Metal-specific Colors - dark mode */
  --silver: #d1d5db;
  --gold: #fbbf24;
  --platinum: #f3f4f6;
  --palladium: #d8b4fe;

  /* Inventory Type Colors */
  --type-coin-bg: #b45309;
  --type-coin-text: #ffffff;
  --type-round-bg: #9ca3af;
  --type-round-text: #1e293b;
  --type-bar-bg: #fde047;
  --type-bar-text: #1e293b;
  --type-note-bg: #047857;
  --type-note-text: #ffffff;
  --type-set-bg: #a78bfa;
  --type-set-text: #1e293b;
  --type-other-bg: #8b5cf6;
  --type-other-text: #ffffff;

  /* Background Colors - Dark Mode */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;

  /* Text Colors - Dark Mode */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --chip-text: #f8fafc;

  /* Border & Shadow - Dark Mode */
  --border: #334155;
  --border-hover: #475569;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

[data-theme="sepia"] {
  /* Primary Colors - Sepia Mode */
  --primary: #b35c1f;
  --primary-hover: #934a17;
  --secondary: #8b7355;
  --secondary-hover: #6d5c3f;
  --success: #698f3f;
  --success-hover: #577a34;
  --info: #1d7a8a;
  --info-hover: #16616e;
  --warning: #d97706;
  --warning-hover: #b45309;
  --danger: #dc2626;
  --danger-hover: #b91c1c;

  /* Metal-specific Colors - Sepia tone (darkened for WCAG AA text contrast on warm bg) */
  --silver: #706b66;
  --gold: #80620a;
  --platinum: #5a5a5a;
  --palladium: #6b5640;

  /* Inventory Type Colors (darkened for text readability on sepia backgrounds) */
  --type-coin-bg: #a35008;
  --type-coin-text: #ffffff;
  --type-round-bg: #5e544a;
  --type-round-text: #ffffff;
  --type-bar-bg: #8a6b00;
  --type-bar-text: #ffffff;
  --type-note-bg: #066b52;
  --type-note-text: #ffffff;
  --type-set-bg: #7c3aed;
  --type-set-text: #ffffff;
  --type-other-bg: #6a3fa8;
  --type-other-text: #ffffff;

  /* Background Colors - Sepia Mode */
  --bg-primary: #f2e7d5;
  --bg-secondary: #e9ddc8;
  --bg-tertiary: #d0c4a8; /* Lighter — separates from border-hover */
  --bg-card: #f2e7d5;

  /* Text Colors - Sepia Mode */
  --text-primary: #3e2f1e;
  --text-secondary: #4f3f2c;
  --text-muted: #5c4e3a;
  --chip-text: #3e2f1e;

  /* Border & Shadow - Sepia Mode */
  --border: #d1c2a5;
  --border-hover: #a89878;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.12);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* =============================================================================
   BASE STYLES & RESET
   ============================================================================= */

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

html {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
}

body {
  max-width: 1600px;
  width: 100%;
  margin: var(--spacing-lg) auto;
  padding: var(--spacing);
  transition: var(--transition);
  overflow-x: hidden; /* Prevent horizontal overflow on body */
  box-sizing: border-box;
}

/* =============================================================================
   TYPOGRAPHY
   ============================================================================= */

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: var(--spacing);
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
}

.section-title {
  text-align: center;
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  margin: var(--spacing-lg) 0;
}

.modal-header .section-title {
  margin: 0;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
  font-size: 0.875rem;
}

/* =============================================================================
   LAYOUT COMPONENTS
   ============================================================================= */

.app-header {
  display: flex;
  align-items: center;
  margin-bottom: var(--spacing-xl);
  width: 100%;
  padding: var(--spacing);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  min-height: 120px; /* match dark mode banner height */
}

.app-logo {
  display: flex;
  align-items: center;
  margin: 0;
  height: 100%;
  cursor: pointer;
}

.app-logo svg {
  display: block;
}


/* StakTrakr Logo Styles */
.stackr-logo {
  max-width: 800px;
  width: 100%;
  height: auto;
}

/* Default state - show light mode */
.stackr-logo .light-mode { 
  display: block; 
}

.stackr-logo .dark-mode { 
  display: none; 
}

.stackr-logo .sepia-mode { 
  display: none; 
}

/* Dark theme */
[data-theme="dark"] .stackr-logo .light-mode { 
  display: none; 
}

[data-theme="dark"] .stackr-logo .dark-mode { 
  display: block; 
}

[data-theme="dark"] .stackr-logo .sepia-mode { 
  display: none; 
}

/* Light theme (explicit) */
[data-theme="light"] .stackr-logo .light-mode { 
  display: block; 
}

[data-theme="light"] .stackr-logo .dark-mode { 
  display: none; 
}

[data-theme="light"] .stackr-logo .sepia-mode { 
  display: none; 
}

/* Sepia theme */
[data-theme="sepia"] .stackr-logo .light-mode { 
  display: none; 
}

[data-theme="sepia"] .stackr-logo .dark-mode { 
  display: none; 
}

[data-theme="sepia"] .stackr-logo .sepia-mode { 
  display: block; 
}

/* System preference detection (only when no manual theme is set) */
@media (prefers-color-scheme: dark) {
  body:not([data-theme]) .stackr-logo .light-mode { 
    display: none; 
  }
  body:not([data-theme]) .stackr-logo .dark-mode { 
    display: block; 
  }
}

/* Responsive scaling */
@media (max-width: 768px) {
}

@media (max-width: 480px) {
  html {
    font-size: 14px; /* Down from 16px default — 12.5% global reduction for 360-412px phones */
  }
}

.container {
  display: grid;
  gap: var(--spacing-xl);
  max-width: 100%;
  overflow: hidden; /* Prevent container overflow */
  box-sizing: border-box;
}

section {
  background: var(--bg-card);
  padding: var(--spacing-xl);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: var(--transition);
  max-width: 100%;
  overflow: hidden; /* Ensure no content overflows the section */
  box-sizing: border-box;
}

.app-footer {
  margin-top: var(--spacing-xl);
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: var(--spacing);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.app-footer a {
  color: var(--primary);
}

.storage-line {
  margin-bottom: var(--spacing-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.footer-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.footer-badges {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.footer-badges img {
  vertical-align: middle;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  text-decoration: none;
  height: 20px;
  box-sizing: border-box;
  vertical-align: middle;
}

.version-badge--current {
  background: var(--success);
  color: #fff;
}

.version-badge--update {
  background: var(--warning);
  color: #fff;
  cursor: pointer;
}

.version-badge--static {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
}

.storage-line a {
  margin-left: var(--spacing-sm);
}

/* Multi-color storage bar (localStorage + IndexedDB) */
.storage-bar {
  display: inline-flex;
  vertical-align: middle;
  margin-left: var(--spacing-sm);
  width: 180px;
  height: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg-tertiary);
  overflow: hidden;
}

.storage-bar-ls {
  height: 100%;
  background-color: var(--primary);
  transition: width 0.3s ease;
  min-width: 0;
}

.storage-bar-idb {
  height: 100%;
  background-color: var(--success);
  transition: width 0.3s ease;
  min-width: 0;
}

/* Legend dots in storage text */
.storage-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin: 0 2px 0 6px;
  vertical-align: middle;
}

.storage-dot--ls { background-color: var(--primary); }
.storage-dot--idb { background-color: var(--success); }

section:hover {
  box-shadow: var(--shadow-lg);
}

.grid {
  display: grid;
  gap: var(--spacing);
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid-purity-row {
  grid-template-columns: 2fr 1fr 1fr auto;
}

.grid-name-year {
  grid-template-columns: 3fr 2fr;
}

.grid-grade {
  grid-template-columns: 1fr 1fr 1.5fr;
}

/* =============================================================================
   FORM ELEMENTS
   ============================================================================= */

form {
  display: grid;
  gap: var(--spacing);
}

input,
select,
button {
  font-family: inherit;
  font-size: 1rem;
  transition: var(--transition);
}

input,
select {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.currency-input {
  position: relative;
}

.currency-input input {
  padding-left: var(--currency-padding, 2rem);
}

.currency-input::before {
  content: var(--currency-symbol, "$");
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-weight: 500;
  pointer-events: none;
  z-index: 1;
}

/* =============================================================================
   BUTTONS - Enhanced for file:// protocol compatibility
   ============================================================================= */

/* File protocol compatibility fixes */
.btn {
  /* Force clickability for file:// protocol */
  pointer-events: auto !important;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Ensure header buttons are always clickable */
.app-header .btn {
  position: relative;
  z-index: 100;
  pointer-events: auto !important;
}

/* Force cursor pointer for all buttons */
button,
.btn,
input[type="button"],
input[type="submit"] {
  cursor: pointer !important;
}

/* Main button styles */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  min-height: 2.75rem;
  background: var(--primary);
  color: #f8fafc;
}

.btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(0);
}

.btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(248, 250, 252, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.btn:hover::before {
  left: 100%;
}

.btn.danger {
  background: var(--danger);
}

.btn.danger:hover {
  background: var(--danger-hover);
}

.btn.success {
  background: var(--success);
}

.btn.success:hover {
  background: var(--success-hover);
}

.btn.info {
  background: var(--info);
}

.btn.info:hover {
  background: var(--info-hover);
}

.btn.secondary {
  background: var(--secondary);
}

.btn.secondary:hover {
  background: var(--secondary-hover);
}

.btn.warning {
  background: var(--warning);
  color: var(--text-primary);
}

.btn.warning:hover {
  background: var(--warning-hover);
}

.btn.premium {
  background: var(--warning);
  color: var(--text-primary);
}

.btn.premium:hover {
  background: #b45309;
}

.btn.filters {
  background: #eab308;
  color: var(--text-primary);
}

.btn.filters:hover {
  background: #ca8a04;
}

/* =============================================================================
   SPOT PRICE CARDS — Sparkline Redesign
   ============================================================================= */

.spot-input {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 0;
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Spot price cards grid — 1col → 2col → 4col, never 3 */
.spot-cards-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .spot-cards-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 960px) {
  .spot-cards-grid { grid-template-columns: repeat(4, 1fr); }
}

.spot-card {
  position: relative;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 0;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  height: 100%;
}

/* Sparkline canvas — positioned behind card content */
.spot-sparkline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.35;
  pointer-events: none;
}

/* Card header: label + controls row */
.spot-card-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
  padding: var(--spacing) var(--spacing) 0;
}

.spot-card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.spot-card-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Range dropdown */
.spot-range-select {
  font-size: 0.65rem;
  padding: 0.1rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1.2;
}

.spot-range-select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* Sync icon button */
.spot-sync-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.spot-sync-icon:hover:not(:disabled) {
  color: var(--primary);
  border-color: var(--primary);
}

.spot-sync-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.spot-sync-icon.syncing svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Card value — above sparkline */
.spot-card-value {
  position: relative;
  z-index: 1;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 var(--spacing);
}

/* Spot price change indicators */
.spot-up { color: var(--success); }
.spot-down { color: var(--danger); }
.spot-unchanged { color: var(--warning); }

.spot-card-change {
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 2px 0;
  position: relative;
  z-index: 2;
  min-height: 1.1em;
}
.spot-change-up { color: var(--success); }
.spot-change-down { color: var(--danger); }

/* Portfolio card gain/loss percentage — subtle prefix left of value */
.gain-loss-pct {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.7;
  margin-right: 0.35em;
}

.spot-card-timestamp {
  position: relative;
  z-index: 1;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-weight: 400;
  line-height: 1.2;
  padding: 0 var(--spacing) var(--spacing);
}

/* Inline edit input (shift+click on price) */
.spot-inline-input {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  width: 7em;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-primary);
  color: var(--primary);
  padding: 0.1rem 0.25rem;
  outline: none;
}

/* Hide number spinners on inline input */
.spot-inline-input::-webkit-outer-spin-button,
.spot-inline-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.spot-inline-input[type=number] {
  -moz-appearance: textfield;
}

/* Settings Modal - API Provider Blocks */
.settings-section {
  margin-top: 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.api-providers {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.api-provider {
  padding: 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

[data-theme="dark"] .api-provider {
  background: var(--bg-tertiary);
  border-color: var(--border-hover);
}

.api-provider input[type="password"] {
  width: 100%;
}

.api-key-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.provider-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
  font-weight: 600;
  gap: 0.5rem;
}

.provider-doc-link {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.7;
  text-decoration: none;
  color: var(--primary);
}
.provider-doc-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.provider-history-pull {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
  flex-wrap: wrap;
}
.provider-history-pull label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0;
}
.provider-history-select {
  width: 110px;
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.8rem;
}
.api-history-btn {
  font-size: 0.8rem;
  padding: var(--spacing-xs) var(--spacing-sm);
}
.history-pull-cost {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}


.provider-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
  gap: 1rem;
}

.provider-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: center;
  text-align: center;
  margin-top: var(--spacing);
}

.provider-history {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  text-align: center;
}

.provider-history table {
  margin: 0 auto;
  border-collapse: collapse;
}

.provider-history th,
.provider-history td {
  padding: 0 0.5rem;
  text-align: center;
}

.provider-history th.provider-label {
  font-weight: 600;
  text-align: right;
}

.provider-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  justify-content: center;
}

.provider-checkbox-row label {
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.provider-checkbox-row .provider-metal-name {
  margin-top: 0.25rem;
}

.api-usage {
  margin: var(--spacing) auto 0;
}

.api-usage .usage-bar {
  display: flex;
  width: 100%;
  height: 8px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--secondary);
}

.api-usage .usage-bar .used {
  background: var(--danger);
}

.api-usage .usage-bar .remaining {
  background: var(--success);
}

.api-usage .usage-text {
  font-size: 0.75rem;
  text-align: center;
  margin-top: 0.25rem;
}

.cache-duration-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.api-key-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Provider Settings Section */
.provider-settings {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--spacing);
  margin: var(--spacing) 0;
  border: 1px solid var(--border);
}

.provider-settings h4 {
  margin: 0 0 var(--spacing) 0;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--spacing-sm);
}

.provider-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.provider-setting-row label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0;
}

.provider-cache-select,
.provider-history-input {
  width: 120px;
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.8rem;
}

/* Metal Selection */
.metal-selection {
  margin-top: var(--spacing);
}

.metal-selection > label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
}

.metal-checkboxes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-sm);
}

.metal-checkbox {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs);
  border-radius: var(--radius);
  transition: var(--transition);
  font-size: 0.8rem;
  cursor: pointer;
}

.metal-checkbox:hover {
  background: var(--bg-tertiary);
}

.metal-checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.metal-name {
  font-weight: 500;
  color: var(--text-primary);
}

.api-field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.provider-status {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
}

.provider-status .status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--warning);
}

.provider-status .status-text {
  color: var(--warning);
}

.provider-status.status-connected .status-dot {
  background: var(--success);
}

.provider-status.status-connected .status-text {
  color: var(--success);
}

.provider-status.status-error .status-dot {
  background: var(--danger);
}

.provider-status.status-error .status-text {
  color: var(--danger);
}

.settings-actions {
  margin-top: 1rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: nowrap;
}

/* API Header Status Row — compact per-provider indicators */
.api-header-status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
}

.api-header-status-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius);
}

.api-header-status-item .status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--warning);
}

.api-header-status-item.connected .status-dot {
  background: var(--success);
}

.api-header-status-item.disconnected .status-dot {
  background: var(--text-muted);
}

.api-header-status-item.error .status-dot {
  background: var(--danger);
}

.api-header-status-item .status-name {
  font-weight: 500;
  color: var(--text-primary);
}

.api-header-status-item .status-timestamp {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Last-used timestamp inside provider cards */
.status-last-used {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

/* Pinned provider tab (Numista) */
.settings-provider-tab.pinned {
  cursor: default;
}

/* Provider priority dropdown (STACK-90) */
.provider-priority-select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  min-width: 140px;
}

.settings-subtext {
  margin: 0.5rem 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Header toggle buttons (STACK-54) */
.header-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* Settings checkbox labels (STACK-54) */
.settings-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  cursor: pointer;
  font-size: 0.9375rem;
}

.settings-checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Header currency dropdown (STACK-54) */
.header-currency-dropdown {
  position: fixed;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  min-width: 220px;
  padding: 0.25rem 0;
}

.header-currency-item {
  display: block;
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.header-currency-item:hover {
  background: var(--bg-elev-1);
}

.header-currency-item.active {
  color: var(--primary);
  font-weight: 600;
}

.theme-buttons {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Larger icons for header theme buttons */
.app-header .theme-btn {
  font-size: 1.5rem;
}

/* Theme button styling - shows current theme */
.theme-btn {
  border: 2px solid var(--border);
  transition: var(--transition);
  font-size: 1.2rem;
  min-width: 3rem;
  position: relative;
  overflow: hidden;
}

.theme-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--primary);
}

.theme-btn.dark {
  background: #1e293b;
  color: #f8fafc;
  border-color: #334155;
}

.theme-btn.light {
  background: #f8fafc;
  color: #1e293b;
  border-color: #cbd5e1;
}

.theme-btn.sepia {
  background: #f2e7d5;
  color: #3e2f1e;
  border-color: #d1c2a5;
}

.theme-btn:hover::before {
  left: 100%;
}

.theme-display {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  min-width: 120px;
  text-align: center;
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* Info modal sizing */
#apiInfoModal .modal-content {
  max-width: 500px;
}

#apiInfoModal h3 {
  margin-bottom: 1rem;
}

#apiInfoModal .modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* API history modal sizing */
#apiHistoryModal .modal-content {
  width: 60vw;
  height: 60vh;
  max-width: none;
  max-height: none;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#apiHistoryModal .modal-content::before {
  display: none;
}

/* Storage report options modal */
#storageOptionsModal .modal-content {
  max-width: 400px;
  text-align: center;
}
#storageOptionsModal .options-buttons {
  display: flex;
  gap: var(--spacing);
  justify-content: center;
}
#storageOptionsModal .options-buttons .btn {
  flex: 1;
}

#apiHistoryModal .modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing-xl);
  position: relative;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
}

#apiHistoryModal .modal-header h2 {
  margin: 0;
  color: #f8fafc;
  text-align: center;
}

#apiHistoryModal .modal-body {
  padding: var(--spacing-xl);
  overflow: auto;
  flex: 1;
}

.api-history-footer {
  padding: var(--spacing);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
}

.api-history-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.api-history-table {
  display: flex;
  flex-direction: column;
}

.api-history-filter {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.api-history-filter input {
  flex: 1;
}

.api-history-table-wrapper {
  height: 70vh;
  width: 100%;
  overflow-y: auto;
}

#apiHistoryTable {
  width: 100%;
  min-width: 100%;
}

#apiHistoryTable th {
  cursor: pointer;
}

#catalogHistoryTable {
  width: 100%;
  min-width: 100%;
}

#catalogHistoryTable th {
  cursor: pointer;
}

.api-info-body {
  margin-bottom: 1rem;
  font-size: 0.875rem;
  background: var(--bg-tertiary);
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.api-info-body .info-provider-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.api-info-body ul {
  margin: 0.5rem 0 0 1.25rem;
}

.api-info-body li + li {
  margin-top: 0.25rem;
}

.api-info-body .info-docs-btn {
  margin-top: 0.75rem;
}

/* =============================================================================
   UNIFIED SETTINGS MODAL
   ============================================================================= */

/* Settings modal content — near full-screen
   Compound selector for higher specificity than base .modal-content */
.modal-content.settings-modal-content {
  width: 90vw;
  max-width: 1100px;
  height: 85vh;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

/* Hide base modal gradient line — settings header has its own */
.modal-content.settings-modal-content::before {
  display: none;
}

.settings-modal-content > .modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing) var(--spacing-xl);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.settings-modal-content > .modal-header h2 {
  margin: 0;
  color: #f8fafc;
}

/* Sidebar + content layout */
.settings-modal-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.settings-sidebar {
  width: 160px;
  min-width: 160px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--spacing-sm) 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}

.settings-nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.settings-nav-item.active {
  background: var(--bg-card);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  font-weight: 600;
}

.settings-nav-item svg {
  flex-shrink: 0;
}

/* Content area */
.settings-content-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-xl);
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--bg-secondary);
}

.settings-content-area::-webkit-scrollbar { width: 8px; }
.settings-content-area::-webkit-scrollbar-track { background: var(--bg-secondary); border-radius: var(--radius); }
.settings-content-area::-webkit-scrollbar-thumb { background-color: var(--primary); border-radius: var(--radius); }
.settings-content-area::-webkit-scrollbar-thumb:hover { background-color: var(--primary-hover); }

.settings-section-panel h3 {
  margin: 0 0 1rem 0;
  font-size: 1.125rem;
}

/* Settings groups (Site section) */
.settings-group {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.settings-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.settings-group-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

/* Settings fieldset — bordered card wrapping related settings (STAK-115) */
.settings-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
}
.settings-fieldset-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: var(--spacing);
}

/* Seed image grid (Images settings tab — STACK-96) */
.seed-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}
.seed-image-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  text-align: center;
  background: var(--bg-card);
  position: relative;
}
.seed-image-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: calc(var(--radius) - 2px);
  background: var(--bg-secondary);
}
.seed-image-card .seed-label {
  font-size: 0.75rem;
  margin-top: 0.35rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seed-image-card .seed-metal-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  margin-top: 0.2rem;
  text-transform: uppercase;
  font-weight: 600;
}
.seed-image-card .seed-metal-badge[data-metal="silver"] { background: #c0c0c0; color: #333; }
.seed-image-card .seed-metal-badge[data-metal="gold"] { background: #ffd700; color: #333; }
.seed-image-card .seed-metal-badge[data-metal="platinum"] { background: #e5e4e2; color: #333; }
.seed-image-card .seed-metal-badge[data-metal="palladium"] { background: #ced4da; color: #333; }
.seed-image-card .seed-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--danger, #dc3545);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.image-storage-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
.image-storage-stats .stat-item {
  background: var(--bg-secondary);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  color: var(--text-primary);
}
.image-pattern-table {
  width: 100%;
  font-size: 0.8rem;
  border-collapse: collapse;
}
.image-pattern-table th,
.image-pattern-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.image-pattern-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
}

/* Pattern rule form (Settings > Images) */
.pattern-rule-form-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.pattern-rule-field {
  flex: 1;
  min-width: 140px;
}
.pattern-rule-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}
.pattern-rule-field-narrow {
  flex: 0 0 120px;
  min-width: 100px;
}
.pattern-rule-field input[type="file"] {
  font-size: 0.8rem;
  max-width: 100%;
}

/* Pattern mode toggle (Keywords / Regex) */
.pattern-mode-toggle {
  display: inline-flex;
  gap: 2px;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.pattern-mode-btn {
  font-size: 0.65rem;
  padding: 1px 6px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 3px;
  cursor: pointer;
  line-height: 1.4;
}
.pattern-mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.pattern-rule-tip {
  display: block;
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.3;
}

/* Custom pattern rule rows */
.pattern-rule-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.pattern-rule-row:last-child { border-bottom: none; }
.pattern-rule-thumb {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-secondary);
}
.pattern-rule-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.pattern-rule-info .rule-pattern {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pattern-rule-info .rule-replacement {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pattern-rule-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.25rem;
}
.pattern-rule-actions .btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
}

/* Dual thumbnail wrapper (obverse + reverse side by side) */
.pattern-rule-thumbs {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.pattern-rule-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--text-secondary);
}

/* Allow pattern rule rows to wrap for inline edit form */
.pattern-rule-row { flex-wrap: wrap; }

/* Inline edit form for pattern rules */
.pattern-rule-edit-form {
  width: 100%;
  padding: 0.5rem 0 0.25rem;
  border-top: 1px dashed var(--border);
  margin-top: 0.25rem;
}
.pattern-rule-edit-form .edit-form-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.8rem;
}
.pattern-rule-edit-form .edit-form-fields label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.pattern-rule-edit-form .edit-form-fields input[type="text"] {
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
}
.pattern-rule-edit-form .edit-form-fields input[type="file"] {
  font-size: 0.75rem;
}
.pattern-rule-edit-form .edit-form-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

/* Image upload UI — dual obverse/reverse (STACK-32) */
.image-upload-group { margin-top: 0.25rem; }
.image-pattern-toggle-group { margin-top: 0.5rem; font-size: 0.85rem; }
.image-pattern-toggle-group .form-control { margin-top: 0.35rem; }
.image-pattern-toggle-group .pattern-rule-tip { display: block; margin-top: 0.2rem; color: var(--text-muted, #888); font-size: 0.78rem; }
.image-upload-sides {
  display: flex;
  gap: 1rem;
}
.image-upload-side {
  flex: 1;
  min-width: 0;
}
.image-side-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.image-upload-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.image-upload-preview {
  margin-top: 0.5rem;
  max-width: 120px;
}
.image-upload-preview img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.image-size-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

/* Chip grouping controls (blacklist & custom rules) */
.chip-grouping-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.chip-grouping-input {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
}

.chip-grouping-input-wide {
  flex: 2;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
}

.chip-grouping-table-container {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.25rem;
}

.chip-grouping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.chip-grouping-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.chip-grouping-table th,
.chip-grouping-table td {
  padding: 0.3rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.chip-grouping-table th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.chip-grouping-table td.chip-grouping-patterns {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-grouping-empty {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-style: italic;
}

.chip-grouping-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius);
  transition: background 0.1s;
}

.chip-grouping-delete:hover {
  background: rgba(var(--danger-rgb, 220, 53, 69), 0.12);
}

.chip-grouping-actions {
  white-space: nowrap;
}

.chip-grouping-edit,
.chip-grouping-save,
.chip-grouping-cancel {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius);
  transition: background 0.1s;
}

.chip-grouping-edit {
  color: var(--text-muted);
}

.chip-grouping-edit:hover {
  color: var(--info);
  background: rgba(var(--info-rgb, 13, 110, 253), 0.12);
}

.chip-grouping-save {
  color: var(--success);
}

.chip-grouping-save:hover {
  background: rgba(var(--success-rgb, 25, 135, 84), 0.12);
}

.chip-grouping-cancel {
  color: var(--text-muted);
}

.chip-grouping-cancel:hover {
  color: var(--danger);
  background: rgba(var(--danger-rgb, 220, 53, 69), 0.12);
}

/* Inline chip config — up/down reorder buttons */
.inline-chip-move {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius);
  transition: background 0.1s, color 0.1s;
}

.inline-chip-move:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--primary);
}

.inline-chip-move:disabled {
  opacity: 0.3;
  cursor: default;
}

.chip-grouping-edit-input {
  width: 100%;
  padding: 0.2rem 0.35rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input, var(--bg));
  color: var(--text);
  box-sizing: border-box;
}

.chip-grouping-edit-wide {
  min-width: 120px;
}

/* Theme picker */
.theme-picker {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.theme-option:hover {
  border-color: var(--primary);
}

.theme-option.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* Provider tabs */
.settings-provider-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin: 1rem 0 0 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.settings-provider-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.settings-provider-tab:hover {
  color: var(--text-primary);
}

.settings-provider-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.settings-provider-panel {
  padding-top: 1rem;
}

/* Settings action button — outlined style for in-panel actions */
.settings-action-btn {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 0.5rem 1.25rem;
  min-height: 2.25rem;
}
.settings-action-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* Info icon tooltip next to labels */
.settings-tooltip {
  cursor: help;
  opacity: 0.5;
  font-size: 0.85em;
  margin-left: 0.25rem;
}
.settings-tooltip:hover {
  opacity: 0.8;
}

/* Placeholder sections (Cloud) */
.settings-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  text-align: center;
  gap: 1rem;
}

.settings-placeholder p {
  font-size: 0.9375rem;
  margin: 0;
}

/* Footer bar */
.settings-footer {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  text-align: center;
  flex-shrink: 0;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Mobile: sidebar becomes 5×2 grid — all 10 tabs visible (STACK-70) */
@media (max-width: 768px) {
  .settings-modal-layout { flex-direction: column; }

  .settings-sidebar {
    width: 100%;
    min-width: unset;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: var(--spacing-xs);
    gap: 2px;
    flex-shrink: 0;
  }

  .settings-nav-item {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.35rem 0.25rem;
    font-size: 0.65rem;
    text-align: center;
    white-space: nowrap;
    min-height: 44px;
    border-radius: var(--radius);
  }

  .settings-nav-item svg { width: 14px; height: 14px; }

  .settings-nav-item.active {
    border-left: none;
    background: var(--primary);
    color: #f8fafc;
  }

  .settings-content-area { padding: var(--spacing); }

  /* Provider tabs: horizontal scroll on mobile (STACK-90) */
  .settings-provider-tabs { flex-wrap: nowrap; }
  .settings-provider-tab { white-space: nowrap; flex-shrink: 0; padding: 0.5rem 0.75rem; font-size: 0.75rem; }
}


.settings-card-grid {
  display: grid;
  gap: var(--spacing);
}

@media (min-width: 600px) {
  .settings-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: var(--spacing);
}

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

/* Cloud Sync modal layout */
#cloudSyncModal .modal-content {
  max-width: 400px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#cloudSyncModal .modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing-xl);
  position: relative;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
}

#cloudSyncModal .modal-header h2 {
  margin: 0;
  color: #f8fafc;
  text-align: center;
}

#cloudSyncModal .modal-body {
  padding: var(--spacing-xl);
  text-align: center;
}

/* Provider panels within Settings modal inherit scrollable content area */

/* Standardized modal layout for change log and details views */
/* shared modal content structure */
#changeLogModal .modal-content,
#itemModal .modal-content {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  width: 90%;
  max-width: 700px;
}

#detailsModal .modal-content {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
}

#changeLogModal .modal-content {
  max-width: 1200px;
  max-height: 80vh;
}

#changeLogModal .modal-header,
#detailsModal .modal-header,
#storageReportModal .modal-header,
#itemModal .modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing-xl);
  position: relative;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
}

#changeLogModal .modal-header h2,
#detailsModal .modal-header h2,
#storageReportModal .modal-header h2,
#itemModal .modal-header h2 {
  margin: 0;
  color: #f8fafc;
  text-align: center;
}

#changeLogModal .modal-body,
#itemModal .modal-body {
  padding: var(--spacing);
  overflow: auto;
  flex: 1;
}

#changeLogModal .modal-footer {
  padding: var(--spacing);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

#changeLogClearBtn {
  font-size: 1.25rem;
}

#detailsModal .modal-body {
  padding: var(--spacing-xl);
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#storageReportModal .modal-body {
  height: 80vh;
  padding: 0;
}

#changeLogTable {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

#changeLogTable th,
#changeLogTable td {
  padding: var(--spacing-xs);
  text-align: left;
  font-size: 0.75rem;
}

#changeLogTable td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#changeLogTable th:last-child,
#changeLogTable td:last-child {
  width: 5rem;
}

#changeLogTable td.action-cell {
  white-space: nowrap;
}

@media (max-width: 600px) {
  #changeLogTable th,
  #changeLogTable td {
    font-size: 0.6rem;
  }
}

#detailsModal {
  font-size: clamp(0.8rem, 1vw + 0.5rem, 1rem);
}

/* =============================================================================
   TOTALS CARDS
   ============================================================================= */

/* Summary cards grid — 1col → 2col+summary → 5col single row at ≥1200px */
.totals {
  display: grid;
  gap: var(--spacing-lg);
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .totals { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1200px) {
  .totals { grid-template-columns: repeat(5, 1fr); }
}

/* Below 1200px: All Metals spans full width with side-by-side layout */
.total-card-all {
  grid-column: 1 / -1;
}
@media (max-width: 1199px) {
  .total-card-all {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 0 var(--spacing-lg);
  }
  .total-card-all .total-title {
    grid-column: 1 / -1;
  }
  .total-card-all .total-item-bottom-line {
    grid-column: 1 / -1;
  }
}
@media (min-width: 1200px) {
  .total-card-all {
    grid-column: auto; /* no spanning — sits in the 5th column */
  }
}

.total-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

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

.total-title {
  font-size: 1.0625rem;
  font-weight: 700;
  margin-bottom: var(--spacing);
  color: var(--primary);
  text-align: center;
  padding-bottom: var(--spacing-sm);
  border-bottom: 2px solid var(--border);
}

.total-group {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: var(--spacing);
  margin: var(--spacing-sm) 0;
  border: 1px solid var(--border);
}

.total-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.375rem 0;
  border-bottom: 1px dashed var(--border);
}

.total-item:last-child {
  border-bottom: none;
}

.total-label {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.total-value {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}


.total-title {
  font-size: 1.0625rem;
  font-weight: 700;
  margin-bottom: var(--spacing);
  color: var(--text-primary);
  text-align: center;
  padding-bottom: var(--spacing-sm);
  border-bottom: 4px solid var(--border); /* fallback, will be overridden below */
  transition: border-color 0.2s, color 0.2s;
  cursor: pointer;
  user-select: none;
}

.total-title:hover {
  color: var(--primary);
}

/* Metal-specific underline accent */
.silver .total-title {
  border-bottom: 4px solid var(--silver);
}
.gold .total-title {
  border-bottom: 4px solid var(--gold);
}
.platinum .total-title {
  border-bottom: 4px solid var(--platinum);
}
.palladium .total-title {
  border-bottom: 4px solid var(--palladium);
}

/* All Metals combined card — uses primary accent */
.total-card-all .total-title {
  border-bottom: 4px solid var(--primary);
}

/* Gain/Loss bottom-line emphasis — the "bottom line" of each card */
.total-item-bottom-line {
  border-bottom: none;
  border-top: 2px solid var(--border);
  margin-top: 0.25rem;
  padding-top: 0.5rem;
}
.total-item-bottom-line .total-label {
  font-weight: 700;
  font-size: 0.875rem;
}
.total-item-bottom-line .total-value {
  font-weight: 700;
  font-size: 1rem;
}

/* =============================================================================
   TABLES - Main inventory table with interactive features
   
   Features implemented:
   - Fixed table layout for precise column control
   - Sortable headers with visual indicators
   - Clickable item names for editing
   - Collectable status checkboxes
   - Delete buttons with hover effects
   - Column resizing with drag handles
   - Responsive design with mobile optimizations
   - Hover effects and zebra striping for readability
   ============================================================================= */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-primary);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  table-layout: auto; /* Allow columns to size based on content */
}

.table-section {
  width: 100%;
  max-width: 100%;
  min-height: auto;
  box-sizing: border-box;
  /* Visual chrome — wraps portal-scroll + footer controls */
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  /* Override base section{overflow:hidden} — portal-scroll handles overflow,
     and hidden here would create an intermediate scroll container that
     breaks position:sticky on thead th in some browsers */
  overflow: visible;
}

/* Scroll container wrapping only the <table> — footer stays outside.
   max-height MUST be set so the container actually constrains content
   and becomes a real scroll container (required for position:sticky).
   JS updatePortalHeight() overrides with a precise row-based value. */
.portal-scroll {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 70vh;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--bg-secondary);
  scrollbar-gutter: stable;
}

.portal-scroll::-webkit-scrollbar { width: 8px; }
.portal-scroll::-webkit-scrollbar-track { background: var(--bg-secondary); }
.portal-scroll::-webkit-scrollbar-thumb { background-color: var(--primary); border-radius: var(--radius); }
.portal-scroll::-webkit-scrollbar-thumb:hover { background-color: var(--primary-hover); }

#inventoryTable {
  /* Use the available container width and allow responsive scaling
     to prevent right-side columns being clipped. Horizontal scrolling
     remains available via .table-section when necessary. */
  width: 100%;
  table-layout: auto;
  background: var(--bg-primary);
  /* override base table rules that block position:sticky on thead th:
     - border-collapse:separate keeps each cell's box independent
     - border-spacing:0 eliminates visual gaps (same look as collapse)
     - overflow:visible lets sticky reach the .table-section scroll container */
  border-collapse: separate;
  border-spacing: 0;
  overflow: visible;
}

#inventoryTable tbody {
  height: auto;
}

  .table-item-count {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius);
    display: inline-block;
  }

  .table-footer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.25rem;
    width: 100%;
  }

/* Bulk Edit Control Panel */
.bulk-edit-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.5rem 0;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  border-radius: var(--radius);
}

.bulk-edit-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bulk-edit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  font-weight: 500;
}

.bulk-edit-icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

.toggle-all-btn {
  background: var(--primary);
  color: white;
}

.toggle-all-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.save-all-btn {
  background: #28a745;
  color: white;
}

.save-all-btn:hover {
  background: #218838;
  transform: translateY(-1px);
}

.cancel-all-btn {
  background: #dc3545;
  color: white;
}

.cancel-all-btn:hover {
  background: #c82333;
  transform: translateY(-1px);
}

.bulk-edit-btn:active {
  transform: translateY(0);
}

th {
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: 600;
  padding: 0.375rem 0.25rem; /* Reduced padding for narrower rows */
  text-align: center;
  cursor: pointer;
  position: relative;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  transition: var(--transition);
  font-size: 0.8rem; /* Reduced from 0.95rem for more space */
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
}

/* Removed annoying th:hover animation effect */

td {
  padding: 0.2rem; /* Reduced padding for better density */
  border-bottom: 1px solid rgba(51, 65, 85, 0.5); /* Softer border for cell separation */
  border-right: 1px solid rgba(51, 65, 85, 0.3); /* Lighter right border */
  color: var(--text-primary);
  font-size: 0.75rem; /* Reduced from 0.875rem for inline editing */
  line-height: 1.2; /* Tighter line height */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  max-width: 20ch; /* Limit to approximately 20 characters */
}

/* Name column — constrain width so flex-based truncation kicks in */
td[data-column="name"] {
  max-width: 340px;
  width: auto;
  overflow: hidden; /* Constrain inner flex container to cell's computed width */
}

/* Name cell flex layout — name text truncates, tags stay visible */
.name-cell-content {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
}

/* Name text truncates with ellipsis */
.name-cell-content > .filter-text {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Table thumbnail — coin obverse preview */
.table-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-tertiary, #2a2a2a);
  vertical-align: middle;
}
/* Rectangular thumbnails for bars, notes, aurum, sets */
.table-thumb.table-thumb-rect {
  border-radius: var(--radius);
}
/* Back to top floating button */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}
.back-to-top:hover {
  background: var(--bg-elev-1);
}
[data-theme="dark"] .back-to-top {
  background: #1e293b;
  border-color: #475569;
  color: #f1f5f9;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .back-to-top:hover {
  background: #334155;
}

/* Reverse thumbnail — slight overlap for paired display */
.table-thumb + .table-thumb {
  margin-left: 2px;
}
/* Keep thumbnail in layout for IntersectionObserver but invisible until src is set */
.table-thumb:not([src]) {
  visibility: hidden;
}
/* Placeholder thumbnails — subtler than real images */
.table-thumb-placeholder {
  opacity: 0.55;
  filter: saturate(0.7);
}

/* Tags never shrink — always visible */
.name-cell-content > .year-tag,
.name-cell-content > .numista-tag,
.name-cell-content > .pcgs-tag,
.name-cell-content > .grade-tag,
.name-cell-content > .serial-tag,
.name-cell-content > .storage-tag,
.name-cell-content > .notes-indicator,
.name-cell-content > .purity-tag {
  flex-shrink: 0;
}

td[data-column="purchaseLocation"],
td[data-column="storageLocation"] {
  max-width: 9ch; /* Reduced from 18ch - compact location columns */
  width: 9ch;
  min-width: 9ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fixed date column — compact MM/DD/YY format */
td[data-column="date"],
th[data-column="date"] {
  max-width: 9ch;
  width: 9ch;
  min-width: 9ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Metal column with toggle capability and increased width */
#inventoryTable th[data-column="metal"],
#inventoryTable td[data-column="metal"] {
  max-width: 25ch; /* Increased metal column to prevent wrapping */
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
/* Transition only on td — transition:all on the sticky th breaks stacking */
#inventoryTable td[data-column="metal"] {
  transition: all 0.3s ease;
}

/* Metal column expansion on hover - CELLS ONLY */
#inventoryTable td[data-column="metal"]:hover {
  max-width: none;
  white-space: nowrap;
  z-index: 10;
  background: var(--bg-primary);
  box-shadow: var(--shadow);
  border-radius: var(--radius-sm);
}

/* Price column toggle styling */
#inventoryTable th[data-column="purchasePrice"] {
  cursor: pointer;
  /* position: sticky inherited from #inventoryTable thead th —
     sticky acts as relative for child/pseudo positioning */
}

#inventoryTable th[data-column="purchasePrice"]:after {
  content: "⇄";
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  opacity: 0.6;
}

[data-column].hidden,
[data-column].hidden-empty {
  display: none;
}

/* Collectable column header removed in portfolio redesign */

/* Base row styling */
tr {
  background: var(--bg-primary);
  transition: filter 0.2s ease-in-out;
}

/* Zebra striping */
tr:nth-child(even) {
  background: var(--bg-secondary);
}

/* Hover effect using a filter instead of background color */
tr:hover {
  filter: brightness(0.95);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1;
}

.sort-indicator {
  margin-left: 0.25rem;
  font-weight: bold;
  color: var(--primary);
  font-size: 0.7rem;
}

/* Utility column width classes */
.shrink {
  width: 1%;
  white-space: nowrap;
  min-width: 0;
}
/* Name column cells remain left aligned for readability */
#inventoryTable td[data-column="name"] {
  text-align: left;
}


/* Legacy "Enhanced Mobile Responsive Design" section removed —
   consolidated into canonical responsive block below line 5127 and
   card-view rules at end of file.  See STACK-38 / STACK-31. */

/* Clickable name cell styling */
.name-cell {
  text-align: left !important;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  cursor: pointer;
  padding: var(--spacing-sm);
}

.name-text {
  flex: 1;
  text-align: left;
  font-weight: 500;
  transition: var(--transition);
}

.name-text:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Make buttons in table cells smaller */
td .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  min-height: 1.8rem;
  line-height: 1;
  margin: 1px;
}

td .action-btn {
  width: 2rem;
  height: 2rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

td .action-icon {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

td .action-icon.danger {
  color: var(--danger);
}

/* Enhanced delete button styling */
td .action-icon.delete-btn {
  color: var(--danger);
  border-radius: var(--radius);
  padding: 0.25rem;
  /* Removed transition: all 0.2s ease; */
}

/* Removed hover effect to prevent flooding into other cells */

td .action-icon.success {
  color: var(--success);
}

td .filter-text {
  cursor: pointer;
  font-weight: 600;
}

.na-value {
  color: var(--text-muted);
  font-style: italic;
}

td .filter-text a,
td .filter-text a:visited {
  color: inherit;
}

/* Enhanced Inline Editing Styles */
td .inline-edit-icon,
td .save-inline,
td .cancel-inline {
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

td .inline-edit-icon {
  margin-right: 0.25rem;
  font-size: 1.1rem;
  display: inline-block;
  color: var(--text-muted);
  padding: 0.1rem;
  border-radius: var(--radius);
}

td .inline-edit-icon:hover {
  color: var(--primary);
  background: var(--bg-secondary);
  transform: scale(1.1);
}

/* Name cell inline edit icons */
td[data-column="name"] .inline-edit-icon {
  border-radius: 50%;
  padding: 2px;
}

td[data-column="name"] .inline-edit-icon:hover {
  opacity: 1 !important;
  background: var(--bg-elev-1);
  transform: translateY(-50%) scale(1.2);
}

td.editing {
  position: relative;
  background: var(--bg-tertiary) !important;
  border: 2px solid var(--primary) !important;
  border-radius: var(--radius);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

td.editing .inline-input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: inherit;
  font-weight: 500;
  padding: 0.2rem;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
  -moz-appearance: textfield;
}

td.editing .inline-input::-webkit-outer-spin-button,
td.editing .inline-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

td.editing .inline-input:focus {
  outline: none;
  background: var(--bg-primary);
  border-radius: var(--radius);
}

td.editing .save-inline,
td.editing .cancel-inline {
  position: absolute;
  right: 0.2rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  font-size: 0.9rem;
  padding: 0.2rem;
  margin: 0;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
}

td.editing .save-inline {
  right: 1.5rem;
  color: var(--success);
}

td.editing .save-inline:hover {
  background: var(--success);
  color: #f8fafc;
  transform: translateY(-50%) scale(1.2);
}

td.editing .cancel-inline {
  right: 0.2rem;
  color: var(--danger);
}

td.editing .cancel-inline:hover {
  background: var(--danger);
  color: #f8fafc;
  transform: translateY(-50%) scale(1.2);
}

/* Mobile inline editing adjustments */
@media (max-width: 768px) {
  td .inline-edit-icon {
    font-size: 1rem;
    margin-right: 0.15rem;
  }
  
  td.editing .inline-input {
    font-size: 0.75rem;
  }
  
  td.editing .save-inline,
  td.editing .cancel-inline {
    font-size: 0.8rem;
    padding: 0.15rem;
  }
  
  td.editing .save-inline {
    right: 1.2rem;
  }
}

@media (max-width: 480px) {
  td .inline-edit-icon {
    font-size: 0.9rem;
    margin-right: 0.1rem;
  }
  
  td.editing {
    border-width: 1px;
  }
  
  td.editing .inline-input {
    font-size: 0.7rem;
    padding: 0.15rem;
  }
  
  td.editing .save-inline,
  td.editing .cancel-inline {
    font-size: 0.75rem;
    padding: 0.1rem;
  }
}

td .filter-text:hover,
td .filter-text:focus {
  text-decoration: underline;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 0.1rem 0.2rem;
  margin: -0.1rem -0.2rem;
  transition: var(--transition);
}

/* Make toggle switches smaller */
td .switch {
  width: 32px;
  height: 18px;
}

td .slider {
  border-radius: 18px;
}

td .slider:before {
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
}

td input:checked + .slider:before {
  transform: translateX(14px);
}

/* Enhanced Resize handle styling */
.resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  width: 8px;
  height: 100%;
  background: transparent;
  cursor: col-resize;
  z-index: 10;
  transition: all 0.2s;
  border-right: 2px solid transparent;
}

.resize-handle:hover {
  background: rgba(59, 130, 246, 0.1);
  border-right-color: var(--primary);
  opacity: 0.8;
}

.resize-handle:active {
  background: rgba(59, 130, 246, 0.2);
  border-right-color: var(--primary-hover);
  opacity: 1;
  width: 10px;
}

/* Mobile resize handle adjustments */
@media (max-width: 768px) {
  .resize-handle {
    width: 10px;
    border-right-width: 3px;
  }
  
  .resize-handle:active {
    width: 12px;
  }
}

/* =============================================================================
   MODALS - Edit modal and analytics modal with charts
   
   Two modal types:
   1. Edit Modal: Item editing form with validation
   2. Details Modal: Analytics with pie charts and data breakdowns
   
   Features:
   - Backdrop blur and overlay effects
   - Smooth slide-in animation
   - Responsive sizing for all screen sizes
   - Keyboard navigation support
   - Auto-scrolling for content overflow
   ============================================================================= */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: var(--spacing);
  animation: modalFadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
}

.modal-content {
  background: rgba(248, 250, 252, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(248, 250, 252, 0.2);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  max-width: 1200px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 
    0 25px 50px -12px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(248, 250, 252, 0.05),
    inset 0 1px 0 rgba(248, 250, 252, 0.1);
  animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

[data-theme="dark"] .modal-content {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 
    0 25px 50px -12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(148, 163, 184, 0.05),
    inset 0 1px 0 rgba(148, 163, 184, 0.1);
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0.6;
}

/* =============================================================================
   VIEW ITEM MODAL — Coin showcase card with image display + enriched data

   Glass-morphism card matching existing modal system.
   Images displayed on a subtle dark field (coin presentation aesthetic).
   Sections separated by faint gradient dividers.
   ============================================================================= */

/* --- Modal content shell --- */
#viewItemModal .modal-content {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  width: 92%;
  max-width: 820px;
  max-height: 90vh;
}

/* --- Header with gradient banner --- */
#viewItemModal .modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing-sm) var(--spacing-xl);
  position: relative;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--spacing-sm);
}

.view-header-left {
  flex: 1;
  min-width: 0;
}

#viewItemModal .modal-header h2 {
  margin: 0;
  color: #f8fafc;
  font-size: 1.1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-header-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

/* --- Header action buttons (eBay, Edit, Close) --- */
.view-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.view-header-actions button {
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  white-space: nowrap;
}

.view-header-actions button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.view-header-actions .view-edit-btn {
  background: rgba(255, 255, 255, 0.9);
  color: #1e293b;
  border-color: transparent;
  font-weight: 600;
}

.view-header-actions .view-edit-btn:hover {
  background: #fff;
}

.view-header-actions .view-ebay-btn {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.2);
}

.view-header-actions .view-ebay-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

#viewItemModal .view-modal-catalog-id {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.85;
  background: rgba(128, 128, 128, 0.2);
  color: inherit;
  padding: 2px 8px;
  border-radius: 4px;
}

#viewItemModal .view-modal-count-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.85;
  background: rgba(128, 128, 128, 0.2);
  color: inherit;
  padding: 2px 8px;
  border-radius: 4px;
}

/* --- Scrollable body --- */
#viewItemModal .modal-body {
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

/* --- Image showcase section --- */
.view-image-section {
  background: linear-gradient(145deg, #1a1a2e, #16213e);
  padding: var(--spacing-lg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: var(--spacing-lg);
  position: relative;
}

/* Subtle coin-case texture overlay */
.view-image-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.3) 100%);
  pointer-events: none;
}

.view-image-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
  position: relative;
  z-index: 1;
}

/* Default: round coin frame */
.view-image-slot img {
  max-width: 180px;
  max-height: 180px;
  object-fit: contain;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

/* Rectangular frame for bars, notes, Aurum/Goldback — auto-fits aspect ratio */
.view-image-section.view-shape-rect .view-image-slot img {
  border-radius: var(--radius);
  max-width: 200px;
  max-height: 260px;
  width: auto;
  height: auto;
}

.view-image-section.view-shape-rect .view-image-placeholder {
  border-radius: var(--radius);
  width: 140px;
  height: 200px;
}

.view-image-slot img:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.view-image-slot .view-image-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(248, 250, 252, 0.55);
  font-weight: 500;
}

/* Placeholder when no image available */
.view-image-placeholder {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: rgba(255, 255, 255, 0.15);
}

/* --- Certification badge overlay on image section --- */
.view-cert-badge {
  position: absolute;
  bottom: var(--spacing-sm);
  right: calc(var(--spacing-sm) + 10px); /* extra padding for scrollbar clearance */
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.55);
  color: rgba(248, 250, 252, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  line-height: 1.2;
  white-space: nowrap;
}

/* --- Authority-specific grade + border colors --- */
.view-cert-badge[data-authority="PCGS"] {
  border-color: rgba(96, 165, 250, 0.4);
}
.view-cert-badge[data-authority="PCGS"] .view-cert-grade {
  color: #60a5fa;
}
.view-cert-badge[data-authority="NGC"] {
  border-color: rgba(251, 191, 36, 0.4);
}
.view-cert-badge[data-authority="NGC"] .view-cert-grade {
  color: #fbbf24;
}
.view-cert-badge[data-authority="ANACS"] {
  border-color: rgba(52, 211, 153, 0.4);
}
.view-cert-badge[data-authority="ANACS"] .view-cert-grade {
  color: #34d399;
}
.view-cert-badge[data-authority="ICG"] {
  border-color: rgba(167, 139, 250, 0.4);
}
.view-cert-badge[data-authority="ICG"] .view-cert-grade {
  color: #a78bfa;
}

/* Grade text — clickable when PCGS CoinFacts link available */
.view-cert-grade.view-cert-clickable {
  cursor: pointer;
  transition: var(--transition);
}
.view-cert-grade.view-cert-clickable:hover {
  text-decoration: underline;
  opacity: 0.85;
}

/* --- Verify checkmark states: gray → green → red --- */
.view-cert-verify {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.35); /* gray — never verified */
  transition: var(--transition);
  padding: 0.15rem;
  border-radius: 50%;
}

/* Inline verify badge in Grading section (STAK-124) */
.view-cert-verify-inline {
  margin-left: 0.4rem;
  vertical-align: middle;
  color: var(--text-muted);
}
.view-cert-verify-inline:hover {
  color: var(--text-secondary);
  background: var(--bg-tertiary);
}
.view-cert-verify-inline.pcgs-verified {
  color: #4ade80;
}
.view-cert-verify-inline.pcgs-verify-failed {
  color: #ef4444;
}
.view-cert-verify:hover {
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.1);
}
.view-cert-verify.pcgs-verifying {
  color: rgba(255, 255, 255, 0.3);
  animation: pcgs-pulse 1s ease-in-out infinite;
}
.view-cert-verify.pcgs-verified {
  color: #4ade80; /* green — passed */
}
.view-cert-verify.pcgs-verified:hover {
  color: #22c55e;
  background: rgba(74, 222, 128, 0.1);
}
.view-cert-verify.pcgs-verify-failed {
  color: #ef4444; /* red — failed */
}

/* Sepia theme — adjust colors on dark image bg */
[data-theme="sepia"] .view-cert-badge[data-authority="PCGS"] .view-cert-grade {
  color: #93bbfd;
}
[data-theme="sepia"] .view-cert-badge[data-authority="NGC"] .view-cert-grade {
  color: #fcd34d;
}
[data-theme="sepia"] .view-cert-badge[data-authority="ANACS"] .view-cert-grade {
  color: #6ee7b7;
}
[data-theme="sepia"] .view-cert-verify.pcgs-verified {
  color: #86efac;
}

/* --- Data sections --- */
.view-detail-section {
  padding: var(--spacing) var(--spacing-xl);
  border-bottom: 1px solid var(--border);
}

.view-detail-section:last-child {
  border-bottom: none;
}

.view-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin: 0 0 var(--spacing-sm) 0;
  padding-bottom: 2px;
  padding-left: 8px;
  border-left: 2px solid var(--primary);
}

.view-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px var(--spacing-lg);
}

.view-detail-grid.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}

.view-detail-grid.four-col {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.view-detail-item {
  display: flex;
  flex-direction: column;
  padding: 3px 0;
}

.view-detail-item.full-width {
  grid-column: 1 / -1;
}

.view-detail-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.view-detail-value {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
}

.view-detail-value.gain {
  color: var(--success);
  font-weight: 600;
}

.view-detail-value.loss {
  color: var(--danger);
  font-weight: 600;
}

.view-detail-value.muted {
  color: var(--text-secondary);
  font-style: italic;
}

/* --- Valuation section emphasis --- */
.view-detail-section.view-valuation-section {
  background: var(--bg-secondary);
}

/* --- Chart range pills --- */
.view-chart-range-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: var(--spacing-sm);
}

.view-chart-range-pill {
  padding: 2px 8px;
  font-size: 0.6rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.view-chart-range-pill:hover {
  background: var(--bg-tertiary);
}

.view-chart-range-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- Custom date range picker --- */
.view-chart-date-range {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.view-chart-date-input {
  padding: 1px 4px;
  font-size: 0.75rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  max-width: 110px;
}

.view-chart-date-input:hover {
  border-color: var(--primary);
}

.view-chart-date-input:focus {
  outline: none;
  border-color: var(--primary);
  color: var(--text-primary);
}

.view-chart-date-sep {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1;
}

/* --- Price history chart --- */
.view-chart-container {
  position: relative;
  width: 100%;
  height: 200px;
  margin-top: var(--spacing-sm);
}

.view-chart-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-style: italic;
}

/* --- Numista enrichment section — distinct separator --- */
.view-numista-section {
  padding: var(--spacing) var(--spacing-xl);
  background: var(--bg-secondary);
  border-top: 2px solid var(--border);
  position: relative;
}

.view-numista-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: var(--spacing-xl);
  right: var(--spacing-xl);
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0.3;
  margin-top: -2px;
}

.view-numista-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: var(--spacing-sm);
}

/* Numista section uses 3 columns by default for compact layout */
.view-numista-section .view-detail-grid {
  grid-template-columns: 1fr 1fr 1fr;
}

/* Image tooltip for obverse/reverse descriptions */
.view-image-slot {
  position: relative;
}

.view-image-slot[title] img {
  cursor: help;
}

/* Rarity bar */
.view-rarity-bar {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.view-rarity-track {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  max-width: 120px;
}

.view-rarity-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--danger));
  transition: width 0.4s ease;
}

.view-rarity-score {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* --- Notes section --- */
.view-notes-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
}

/* (Footer removed — action buttons now live in .view-header-actions) */

/* Clickable N# badge */
.view-modal-catalog-id[style*="cursor: pointer"]:hover {
  filter: brightness(1.2);
}

/* --- Responsive: mobile view modal (≤768px) --- */
@media (max-width: 768px) {
  /* Full-screen modal on phones — no chrome, maximum content */
  #viewItemModal .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    margin: 0;
  }

  #viewItemModal .modal-header {
    border-radius: 0;
    padding: var(--spacing-sm) var(--spacing);
    flex-wrap: wrap;
  }

  #viewItemModal .modal-header h2 {
    font-size: 0.95rem;
    line-height: 1.3;
  }

  .view-header-actions {
    gap: 4px;
  }

  .view-header-actions button {
    padding: 4px 8px;
    font-size: 0.7rem;
  }

  /* Images: side-by-side, flex-fill to use available width (STAK-124) */
  .view-image-section {
    flex-direction: row;
    justify-content: center;
    gap: var(--spacing);
    padding: var(--spacing);
  }

  .view-image-slot {
    flex: 1 1 0;
    min-width: 0;
  }

  .view-image-slot img {
    max-width: 100%;
    max-height: 160px;
    width: auto;
  }

  .view-image-placeholder {
    width: 100%;
    aspect-ratio: 1;
    font-size: 2rem;
  }

  .view-image-section.view-shape-rect .view-image-slot img {
    max-width: 100%;
    max-height: 200px;
  }

  .view-image-section.view-shape-rect .view-image-placeholder {
    width: 100%;
    aspect-ratio: 3/4;
  }

  .view-cert-badge {
    display: none; /* Hidden ≤768px — inline verify in Grading section instead */
  }

  /* 2-column data grid (down from 3/4) */
  .view-detail-grid,
  .view-detail-grid.three-col,
  .view-detail-grid.four-col {
    grid-template-columns: 1fr 1fr;
  }

  .view-chart-container {
    height: 160px;
  }

  .view-detail-section {
    padding: var(--spacing-sm) var(--spacing);
  }

  .view-numista-section {
    padding: var(--spacing-sm) var(--spacing);
  }

}

/* --- Extra-small phones (≤480px) — optimized for 360-412px viewports (STAK-124) --- */
@media (max-width: 480px) {
  .view-detail-grid,
  .view-detail-grid.three-col,
  .view-detail-grid.four-col {
    grid-template-columns: 1fr 1fr;
  }

  /* Tighter image gap at smallest screens */
  .view-image-section {
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .view-image-slot img {
    max-height: 150px;
  }

  .view-image-section.view-shape-rect .view-image-slot img {
    max-height: 180px;
  }

  /* Price History pills — ~5% larger for touch targets (STAK-124) */
  .view-chart-range-pill {
    padding: 3px 10px;
    font-size: 0.65rem;
  }
}

/* --- Sepia theme adjustments for image showcase --- */
[data-theme="sepia"] .view-image-section {
  background: linear-gradient(145deg, #2c1e0e, #3a2a18);
}

/* =============================================================================
   ABOUT MODAL STYLING - Enhanced splash page design
   ============================================================================= */

.about-modal-content {
  width: 75vw;
  max-width: 1200px;
  padding: 0;
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.about-modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing-xl);
  position: relative;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
}

.about-modal-header h1 {
  margin: 0;
  color: #f8fafc;
  text-align: center;
}

.about-title {
  font-size: 1.875rem;
  font-weight: 700;
  margin: 0;
  text-align: center;
  color: var(--text-primary);
}

.about-title #aboutAppName {
  color: var(--primary);
}

.about-title #aboutVersion {
  color: var(--text-secondary);
}

.modal-close {
  position: absolute;
  top: var(--spacing);
  right: var(--spacing);
  background: none;
  border: none;
  font-size: 1.5rem;
  color: rgba(248, 250, 252, 0.8);
  cursor: pointer;
  padding: var(--spacing-sm);
  border-radius: var(--radius);
  transition: var(--transition);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: #f8fafc;
  background: rgba(248, 250, 252, 0.1);
}

.about-modal-body {
  padding: var(--spacing-xl);
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--bg-secondary);
}


.about-modal-body::-webkit-scrollbar {
  width: 8px;
}

.about-modal-body::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: var(--radius);
}

.about-modal-body::-webkit-scrollbar-thumb {
  background-color: var(--primary);
  border-radius: var(--radius);
}

.about-modal-body::-webkit-scrollbar-thumb:hover {
  background-color: var(--primary-hover);
}

.about-description {
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--text-secondary);
  margin: var(--spacing-xl) 0;
  text-align: center;
  padding: var(--spacing-lg);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.about-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

.about-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 2rem;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}

a.about-badge:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.about-badge svg {
  width: 0.9rem;
  height: 0.9rem;
  flex-shrink: 0;
}

.about-alert {
  background: linear-gradient(135deg, #fef2f2, #f5f5f5);
  border: 1px solid #fecaca;
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  padding: var(--spacing-lg);
  margin: var(--spacing-xl) 0;
  position: relative;
  overflow: hidden;
}

[data-theme="dark"] .about-alert {
  background: linear-gradient(135deg, #2d1b1b, #1f1717);
  border-color: #991b1b;
}

.alert-header {
  display: flex;
  align-items: center;
  margin-bottom: var(--spacing);
  font-weight: 600;
  color: var(--danger);
}

.alert-icon {
  font-size: 1.2rem;
  margin-right: var(--spacing-sm);
}

.about-alert .alert-content {
  column-count: 2;
  column-gap: var(--spacing-lg);
}

.about-alert .alert-content p {
  margin: 0 0 var(--spacing);
  line-height: 1.6;
  color: var(--text-primary);
  break-inside: avoid;
}

.alert-actions {
  margin-top: var(--spacing-lg);
  text-align: center;
}

.about-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

@media (max-width: 768px) {
  .about-info-grid {
    grid-template-columns: 1fr;
  }
}

.about-info-grid .about-section {
  margin-bottom: 0;
}

.about-section {
  margin-bottom: var(--spacing-xl);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--spacing-lg);
  border: 1px solid var(--border);
}

.about-section .section-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: var(--spacing);
  padding-bottom: var(--spacing-sm);
  border-bottom: 2px solid var(--border);
}

.changelog-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.changelog-list li {
  padding: var(--spacing-sm) 0;
  border-bottom: 1px dashed var(--border);
  color: var(--text-secondary);
  line-height: 1.5;
}

.changelog-list li:last-child {
  border-bottom: none;
}

.changelog-list li::before {
  content: "•";
  color: var(--primary);
  font-weight: bold;
  font-size: 1.2em;
  margin-right: var(--spacing-sm);
}


.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing);
}

.resource-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing) var(--spacing-lg);
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  font-size: 0.875rem;
}

.resource-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.acceptance-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  line-height: 1.5;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.about-accept-btn {
  background: linear-gradient(135deg, var(--success), #047857);
  color: #f8fafc;
  font-size: 1.125rem;
  padding: var(--spacing) var(--spacing-xl);
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.about-accept-btn:hover {
  background: linear-gradient(135deg, #047857, #065f46);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Responsive adjustments for about modal */
@media (max-width: 768px) {
  .about-modal-content {
    width: 95vw;
    margin: var(--spacing-sm);
    max-height: 95vh;
  }

  .about-title {
    font-size: 1.5rem;
  }

  .resources-grid {
    grid-template-columns: 1fr;
  }

  .about-modal-body {
    padding: var(--spacing);
  }

  .about-alert .alert-content {
    column-count: 1;
  }
}

@media (max-width: 480px) {
  .about-title {
    font-size: 1.25rem;
  }

  .about-description {
    font-size: 1rem;
    padding: var(--spacing);
  }

  .about-modal-header {
    padding: var(--spacing);
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-xl);
  margin-bottom: var(--spacing-lg);
  flex: 0 0 auto;
  overflow: visible;
}

.details-panel {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: var(--spacing-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
  overflow: visible;
}

.details-breakdown {
  flex: 0 0 auto;
  overflow: visible;
  padding-right: var(--spacing-sm);
}

.details-panel-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0;
  text-align: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--spacing-sm);
}

.breakdown-item {
  padding: var(--spacing-sm) 0;
  border-bottom: 1px dashed var(--border);
}

.breakdown-item:last-child {
  border-bottom: none;
}

.breakdown-header {
  display: flex;
  align-items: center;
  margin-bottom: 0.25rem;
}

.breakdown-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.4rem;
  flex-shrink: 0;
}

.breakdown-label {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.875rem;
  flex: 1;
}

.breakdown-meta {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
}

/* 2x2 financial grid for breakdown rows */
.breakdown-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.125rem 0.75rem;
  font-size: 0.8rem;
}

.breakdown-cell {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.1rem 0;
}

.breakdown-cell-label {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.breakdown-cell-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.breakdown-purchase .breakdown-cell-value { color: var(--text-primary); }
.breakdown-melt .breakdown-cell-value { color: var(--primary); }
.breakdown-retail .breakdown-cell-value { color: var(--text-secondary); }
.breakdown-gain .breakdown-cell-value { color: var(--success); }
.breakdown-loss .breakdown-cell-value { color: var(--danger); }

.chart-canvas-container {
  position: relative;
  width: 100%;
  max-width: 300px;
  max-height: 300px;
  aspect-ratio: 1;
  margin: 0 auto;
  flex: 0 0 auto;
}

.chart-canvas {
  max-height: 300px !important;
}

/* Chart metric toggle — segmented button bar for details modal */
.chart-metric-toggle {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: 0 auto 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: fit-content;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-primary);
  padding: 0.5rem 0;
}
.chart-metric-btn {
  padding: 0.5rem 1.25rem;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.chart-metric-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}
.chart-metric-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}
.chart-metric-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}
.chart-metric-btn:hover {
  background: var(--bg-hover);
}
.chart-metric-btn.active {
  background: var(--primary);
  color: #fff;
}

/* =============================================================================
   NUMISTA MODAL - Removed (X-Frame-Options blocks iframes on hosted sites)
   Numista pages now open in popup windows via js/numista-modal.js
   ============================================================================= */

/* Pagination section removed — replaced by portal (scrollable table) view */

.change-log-label {
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
}

.btn.silver {
  background: var(--silver);
  color: var(--text-primary);
}

.btn.silver:hover {
  background: #9ca3af;
}

.table-disclaimer {
  font-size: 0.75rem;
  color: var(--disclaimer-color);
  font-style: italic;
  text-align: center;
}

.table-subtitle {
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  margin-bottom: 0.25rem;
}

.backup-link {
  text-decoration: underline;
  cursor: pointer;
}


.beta-warning {
  margin-top: var(--spacing-xs);
  font-size: 0.75rem;
  color: var(--warning);
  text-align: center;
}

/* =============================================================================
   SEARCH
   ============================================================================= */

.search-section {
  margin-bottom: var(--spacing);
}

.search-container {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
}

#searchInput {
  flex: 1;
}

.modern-icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.5rem;
  min-width: 2.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.modern-icon-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.modern-icon-btn:active {
  transform: translateY(0);
}

.modern-icon-btn:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.modern-icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  transition: transform 0.2s ease;
}

.modern-icon-btn:hover svg {
  transform: scale(1.1);
}

/* Theme-specific adjustments */
[data-theme="dark"] .modern-icon-btn {
  background: var(--bg-tertiary);
  border-color: var(--border);
}

[data-theme="dark"] .modern-icon-btn:hover {
  background: var(--primary);
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

[data-theme="sepia"] .modern-icon-btn {
  background: var(--bg-tertiary);
  border-color: var(--border);
}

[data-theme="sepia"] .modern-icon-btn:hover {
  background: var(--primary);
  box-shadow: 0 2px 8px rgba(139, 69, 19, 0.2);
}

/* Enhanced search action buttons with text labels */
.search-action-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  height: 2.75rem;
  padding: 0.5rem 0.75rem;
  min-width: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
}

.search-action-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.search-action-btn:active {
  transform: translateY(0);
}

.search-action-btn:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.search-action-btn svg {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.search-action-btn:hover svg {
  transform: scale(1.1);
}

/* Specific button color variations */
.search-action-btn.add-btn:hover {
  background: var(--success);
  border-color: var(--success);
}

.search-action-btn.clear-btn:hover {
  background: var(--warning);
  border-color: var(--warning);
}

.search-action-btn.log-btn:hover {
  background: var(--info);
  border-color: var(--info);
}

/* Theme-specific adjustments for search action buttons */
[data-theme="dark"] .search-action-btn {
  background: var(--bg-tertiary);
  border-color: var(--border);
}

[data-theme="dark"] .search-action-btn.add-btn:hover {
  background: var(--success);
  box-shadow: 0 2px 12px rgba(34, 197, 94, 0.3);
}

[data-theme="dark"] .search-action-btn.clear-btn:hover {
  background: var(--warning);
  box-shadow: 0 2px 12px rgba(245, 158, 11, 0.3);
}

[data-theme="dark"] .search-action-btn.log-btn:hover {
  background: var(--info);
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

[data-theme="sepia"] .search-action-btn {
  background: var(--bg-tertiary);
  border-color: var(--border);
}

[data-theme="sepia"] .search-action-btn.add-btn:hover {
  background: var(--success);
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}

[data-theme="sepia"] .search-action-btn.clear-btn:hover {
  background: var(--warning);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

[data-theme="sepia"] .search-action-btn.log-btn:hover {
  background: var(--info);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

.autocomplete-dropdown {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 10100;
  max-height: 12rem;
  overflow-y: auto;
}

.autocomplete-item {
  padding: var(--spacing-sm) var(--spacing);
  cursor: pointer;
}

.autocomplete-item.active,
.autocomplete-item:hover {
  background: var(--bg-secondary);
}

.autocomplete-item mark {
  background: transparent;
  color: var(--info);
  font-weight: 600;
}

.fuzzy-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: var(--spacing-xs) 0;
  font-style: italic;
}


.filter-select {
  width: 8rem;
  height: 1.375rem;
}

.icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  min-width: 2.75rem;
}

/* =============================================================================
   SEARCH FILTERS (INTEGRATED)
   ============================================================================= */

.search-filters {
  margin-top: var(--spacing-sm);
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.filter-row {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.filter-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing);
}

.control-group {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.control-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}


.control-select {
  appearance: none;
  padding: 0.25rem 1.5rem 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.875rem;
  width: 4rem;
  min-width: 0;
  text-align: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' fill='none' stroke='currentColor' stroke-width='1.5'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.35rem center;
  background-size: 0.65rem;
  cursor: pointer;
  transition: var(--transition);
}

.control-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-alpha);
}

.control-select:hover {
  border-color: var(--border-hover);
}

/* =============================================================================
  ORIGINAL FILTER STYLES
  ============================================================================= */

.active-filters {
  display: flex;
  flex: 1 1 100%; /* allow the filters area to take full row so chips can center */
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  justify-content: center; /* center chips within available width */
  padding: 0 var(--spacing-sm);
  order: 1;
}

.control-settings {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing);
  margin-top: var(--spacing-sm);
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--border);
}

.chip-min-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0;
}

.chip-min-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.8rem;
  min-width: 60px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  justify-content: center;
  padding: 0 var(--spacing-sm);
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  color: var(--chip-text);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  height: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  text-align: center;
  white-space: nowrap;
  user-select: none;
  margin: 0.05rem;
  max-width: fit-content;
  box-sizing: border-box;
}

.filter-chip:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chip-close {
  margin-left: 0.35rem;
  font-weight: 700;
  opacity: 0.95;
  cursor: pointer;
}

.filter-chip:active {
  transform: translateY(0);
}

/* Chip sort toggle — segmented A-Z / Qty control */
.chip-sort-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chip-sort-btn {
  padding: 0.2rem 0.6rem;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chip-sort-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

.chip-sort-btn:hover {
  background: var(--bg-secondary);
}

.chip-sort-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Chip context menu (right-click on name/dynamic chips) */
.chip-context-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg, 0 4px 12px rgba(0,0,0,0.15));
  z-index: 10000;
  min-width: 160px;
  padding: 0.25rem 0;
}

.chip-context-menu-item {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.1s;
}

.chip-context-menu-item:hover {
  background: var(--bg-hover, var(--border));
}

.chip-confirm-message {
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.chip-confirm-buttons {
  display: flex;
  gap: 0.35rem;
  padding: 0.25rem 0.75rem 0.5rem;
}

.chip-confirm-yes,
.chip-confirm-no {
  flex: 1;
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}

.chip-confirm-yes {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.chip-confirm-yes:hover {
  opacity: 0.85;
}

.chip-confirm-no {
  background: var(--bg-card);
  color: var(--text-primary);
}

.chip-confirm-no:hover {
  background: var(--bg-hover, var(--border));
}

.search-results-info {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: right;
  margin-left: 0; /* remove auto margin which can push chips out of center */
}

.search-results-info:not(:empty) {
  margin-top: 0;
}

/* Clear all filters button */
.filter-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  background: var(--error);
  color: white;
  padding: 0.25rem 0.75rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  height: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  text-align: center;
  white-space: nowrap;
  user-select: none;
  margin: 0.05rem 0 0.05rem 0.5rem;
  max-width: fit-content;
  box-sizing: border-box;
}

.filter-clear-btn:hover {
  background: var(--error-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.filter-clear-btn:active {
  transform: translateY(0);
}

/* =============================================================================
   IMPORT/EXPORT SECTION
   ============================================================================= */

.import-export-section h2 {
  text-align: center;
  font-weight: 600;
  margin-bottom: var(--spacing);
  color: var(--primary);
  font-size: 1.125rem;
}

.file-blocks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing);
}

.import-block,
.export-block {
  flex: 1;
}

.import-export-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-sm);
}

.import-export-grid .btn,
.import-export-grid label.btn {
  height: 2.75rem;
  padding: var(--spacing-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: 0;
  line-height: 1;
  width: 100%;
}

.import-export-grid label.btn {
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.import-export-grid label.btn input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.import-csv-grid,
.import-json-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-sm);
}

.import-progress {
  width: 100%;
  margin-top: var(--spacing-sm);
  display: none;
}

.import-progress-text {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: var(--spacing-sm);
  display: none;
}

/* =============================================================================
   TOGGLE SWITCHES
   ============================================================================= */

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  transition: var(--transition);
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #f8fafc;
  transition: var(--transition);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

input:disabled + .slider {
  background-color: var(--text-muted);
  opacity: 0.6;
}

/* =============================================================================
   BOATING ACCIDENT SECTION
   ============================================================================= */

.boating-accident-section {
  text-align: center;
}

.backup-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing);
  margin-top: var(--spacing);
}

.backup-buttons .btn {
  width: 100%;
  min-height: 2.75rem;
  font-size: 0.9rem;
  padding: var(--spacing) var(--spacing-lg);
}


/* =============================================================================
   FILTERS MODAL
   ============================================================================= */

#filtersModal .modal-content {
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#filtersModal .modal-header {
  background: linear-gradient(135deg, #eab308, #ca8a04);
  color: var(--text-primary);
  padding: var(--spacing-xl);
  position: relative;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
}

#filtersModal .modal-body {
  padding: var(--spacing-xl);
  overflow-y: auto;
  flex: 1;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.filter-group label {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.filter-select {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: var(--transition);
}

.filter-select:focus {
  outline: none;
  border-color: #eab308;
  box-shadow: 0 0 0 3px rgb(234 179 8 / 0.1);
}

.exclude-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.25rem;
  font-size: 0.8rem;
}

.date-range-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-sm);
}

.date-range-inputs input {
  padding: var(--spacing-sm) var(--spacing);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: var(--transition);
}

.date-range-inputs input:focus {
  outline: none;
  border-color: #eab308;
  box-shadow: 0 0 0 3px rgb(234 179 8 / 0.1);
}

.filter-actions {
  display: flex;
  gap: var(--spacing);
  justify-content: flex-end;
  padding-top: var(--spacing);
  border-top: 1px solid var(--border);
}

.filter-actions .btn {
  min-width: 120px;
}

/* =============================================================================
   ACTION BUTTON GRIDS
   ============================================================================= */

.action-buttons {
  display: grid;
  gap: var(--spacing-sm);
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

/* =============================================================================
   RESPONSIVE DESIGN - Consolidated Media Queries
   
   Breakpoint strategy:
   - 1200px: Large desktop - reduce chart complexity, stack some elements
   - 992px: Desktop - simplify totals grid, reduce modal sizes
   - 768px: Tablet - stack most elements, smaller fonts, compact controls
   - 480px: Mobile - single column layout, minimal spacing, touch-friendly
   
   Key responsive features:
   - Flexible grid layouts that adapt to screen size
   - Progressive enhancement from mobile-first approach
   - Touch-friendly button and input sizing
   - Readable font sizes across all devices
   - Optimized table display with column adjustments
   ============================================================================= */

/* STACK-71: Single-column details at tablet widths, aligned with card-view breakpoint */
@media (max-width: 1350px) {
  .details-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1200px) {
  #detailsModal .modal-content {
    max-width: 900px;
  }
}

@media (max-width: 992px) {
  #detailsModal .modal-content {
    max-width: 900px;
  }
}

@media (max-width: 768px) {
  body {
    max-width: 100%;
    margin: var(--spacing) auto;
    padding: var(--spacing-sm);
  }

  /* Compact header: logo left, 2×2 buttons right (STAK-126) */
  .app-header {
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing);
    padding: var(--spacing-sm);
  }

  .app-logo {
    margin: 0;
    flex: 1;
    min-width: 0;
  }

  .app-logo .stackr-logo {
    max-width: 100%;
    height: auto;
  }

  section {
    padding: var(--spacing);
  }


    .table-controls {
      flex-direction: column;
      align-items: stretch;
      gap: var(--spacing-sm);
    }

  /* Search toolbar: single row with icon-only buttons (STAK-126) */
  .search-container {
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: var(--spacing-xs);
  }

  .search-container #searchInput {
    flex: 1;
    min-width: 0;
  }

  .search-action-btn span {
    display: none;
  }

  .search-action-btn {
    padding: 0.5rem;
    width: 2.75rem;
    min-width: 2.75rem;
    height: 2.75rem;
    justify-content: center;
  }

  .totals {
    gap: var(--spacing-sm);
  }

  .total-card {
    padding: var(--spacing-sm);
  }

  .total-group {
    padding: var(--spacing-xs);
    margin: var(--spacing-xs) 0;
  }

  .total-item {
    padding: 0.2rem 0;
  }

  .total-label {
    font-size: 0.7rem;
  }

  .total-value {
    font-size: 0.8rem;
  }

  .total-title {
    font-size: 0.85rem;
    margin-bottom: var(--spacing-xs);
    padding-bottom: var(--spacing-xs);
    border-bottom-width: 3px;
  }

  .total-item-bottom-line .total-label {
    font-size: 0.75rem;
  }

  .total-item-bottom-line .total-value {
    font-size: 0.85rem;
  }

  .import-export-grid {
    grid-template-columns: 1fr;
  }

  .details-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing);
  }

  #detailsModal .modal-content {
    max-width: 95%;
    padding: var(--spacing);
  }

  .grid-2,
  .grid-name-year,
  .grid-grade {
    grid-template-columns: 1fr;
  }

  .grid-purity-row {
    grid-template-columns: 1fr 1fr;
  }

  .action-buttons {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.5rem;
  }

  .modal-content {
    margin: 0.25rem;
    padding: 0.6rem;
  }

  .total-card {
    padding: var(--spacing-xs);
  }

  .total-label {
    font-size: 0.65rem;
  }

  .total-value {
    font-size: 0.75rem;
  }

  .total-title {
    font-size: 0.8rem;
  }

  .total-item-bottom-line .total-value {
    font-size: 0.8rem;
  }

  .spot-input {
    padding: var(--spacing);
  }

  /* Min-width reductions for 360px viewports (STAK-124) */
  .header-currency-menu {
    min-width: 180px;
  }

  .search-container #searchInput {
    min-width: 160px;
  }
}

/* Additional mobile table adjustments — removed ≤768px rules (card view handles them) */

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

  .action-buttons {
    grid-template-columns: repeat(2, 1fr);
  }
}
#inventoryTable td.icon-col {
  width: 3.5rem;
  padding: 0.25rem;
  text-align: center;
  vertical-align: middle;
  position: relative;
}

#inventoryTable th.icon-col {
  width: 3.5rem;
  padding: 0.25rem;
  text-align: center;
  vertical-align: middle;
  /* position: sticky inherited from #inventoryTable thead th —
     sticky acts as relative for child/pseudo positioning */
}

/* Enhanced action icons without hover animations */
#inventoryTable td.icon-col .action-icon {
  /* Removed transition animation */
  border-radius: var(--radius);
  padding: 0.2rem;
  cursor: pointer;
}

/* Enhanced styling for edit icons - no hover effects for clean interface */
#inventoryTable td.icon-col .action-icon.edit-icon {
  color: var(--primary);
  font-weight: bold;
}

#inventoryTable td.icon-col .action-icon.view-icon {
  color: var(--text-secondary);
}

#inventoryTable td.icon-col .action-icon.view-icon:hover {
  color: var(--primary);
}

/* Actions column styling */
#inventoryTable td[data-column="actions"] {
  text-align: center;
  padding: 0.2rem;
}

#inventoryTable td[data-column="actions"] .icon-btn {
  margin: 0;
}

/* Style the edit toggle button based on mode */
#inventoryTable td[data-column="actions"] .edit-toggle {
  color: var(--primary);
}

#inventoryTable td[data-column="actions"] .edit-toggle:hover {
  color: var(--primary-dark);
}

/* Actions header styling */
/* Row editing styles */
#inventoryTable tbody tr.editing-row {
  background: var(--bg-secondary) !important;
  border: 2px solid var(--primary);
  outline: none;
}

#inventoryTable tbody tr.editing-row .inline-edit-input {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.15rem; /* Reduced padding for better fit */
  border-radius: 3px;
  font-size: 0.7rem; /* Smaller font for better fit */
  width: 100%;
  box-sizing: border-box;
  min-width: 60px; /* Ensure minimum usable width */
}

#inventoryTable tbody tr.editing-row .inline-edit-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

#inventoryTable tbody tr.editing-row .save-row {
  color: var(--success);
}

#inventoryTable tbody tr.editing-row .cancel-row {
  color: var(--danger);
}

#inventoryTable th.icon-col {
  font-size: 0.7rem;
  line-height: 1.1;
}

#inventoryTable td.icon-col {
  font-size: 0.75rem;
}

/* Icon sizing in action cells */
#inventoryTable th.icon-col svg,
#inventoryTable td.icon-col .action-icon {
  width: 1rem;
  height: 1rem;
}

#inventoryTable td[data-column="purchaseLocation"],
#inventoryTable td[data-column="storageLocation"] {
  max-width: 20ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#inventoryTable th,
#inventoryTable td {
  text-align: center;
}

#inventoryTable th[data-column="name"],
#inventoryTable td[data-column="name"] {
  text-align: left;
}

.info-link {
  margin-left: 0.25rem;
  font-size: 0.75rem;
}

#typeSummary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  justify-content: center;
  align-items: center;
  margin-top: var(--spacing-sm);
  padding: var(--spacing-sm);
  min-height: 2rem;
  max-height: 8rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--bg-secondary);
}

#typeSummary::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#typeSummary::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: var(--radius);
}

#typeSummary::-webkit-scrollbar-thumb {
  background-color: var(--primary);
  border-radius: var(--radius);
}

#typeSummary::-webkit-scrollbar-thumb:hover {
  background-color: var(--primary-hover);
}

/* Header Icons */
.header-icon {
  width: 1rem;
  height: 1rem;
  margin: 0 auto 0.25rem;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-icon.vault-icon {
  fill: currentColor;
  stroke: none;
}

/* Header Text Styling */
.header-text {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
  margin-top: 0.15rem;
  line-height: 1;
}

/* Actions column — merged edit/copy/delete */
#inventoryTable th.actions-col,
#inventoryTable td.actions-cell {
  width: 5rem;
  min-width: 4.5rem;
}

.actions-row {
  display: flex;
  gap: 0.1rem;
  justify-content: center;
  align-items: center;
}

/* Icon column styling */
.icon-col {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  min-width: 3.5rem;
}

.icon-col .header-icon {
  margin: 0 auto 0.25rem;
}

/* Action column styling — no sticky positioning needed (table fits viewport) */
#inventoryTable th.icon-col {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

#inventoryTable td.icon-col {
  background: inherit;
  color: inherit;
}

/* Icon button base for action cells */
#inventoryTable .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0.15rem;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  /* No transition — hover effects disabled to prevent repaint at sticky header boundary */
}

#inventoryTable .icon-btn:focus {
  outline: 2px solid rgba(59,130,246,0.25);
  outline-offset: 2px;
}

/* Removed hover effect to prevent cell flooding */

#inventoryTable .icon-svg { width: 1.05rem; height: 1.05rem; display: block; fill: currentColor; color: inherit; }
.edit-svg { color: inherit; }
.delete-svg { color: inherit; }

/* CANONICAL RESPONSIVE TABLE RULES — Progressive disclosure + portfolio layout
   Single source of truth for all inventory table responsive behavior.
   Card view (≤768px) lives at end of file.  See STACK-38 / STACK-31. */

@media (max-width: 1200px) {
  #inventoryTable th[data-column="gainLoss"],
  #inventoryTable td[data-column="gainLoss"] {
    display: none;
  }
}

@media (max-width: 1024px) {
  #inventoryTable th[data-column="purchaseLocation"],
  #inventoryTable td[data-column="purchaseLocation"] {
    display: none;
  }
  #inventoryTable { font-size: 0.8rem; }
  #inventoryTable th, #inventoryTable td { padding: 0.3rem 0.2rem; }
}

/* Sticky icon columns: remove left border so they blend with adjacent cells */
#inventoryTable th.icon-col,
#inventoryTable td.icon-col {
  border-left: none;
}

th {
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

/* Make header icons/text use muted header color so they don't pop */
#inventoryTable thead th {
  color: var(--text-secondary);
  background: var(--bg-secondary);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  position: sticky;
  top: 0;
  z-index: 2;
  /* Override generic th { transition: var(--transition) } — transition:all on
     sticky elements creates temporary compositor layers during scroll that can
     break stacking order, causing data rows to paint above the header */
  transition: none;
}

/* Ensure uniform font family for entire table */
#inventoryTable {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#inventoryTable thead th .header-icon,
#inventoryTable thead th .header-text {
  color: var(--text-secondary);
}

/* Icon column header should visually match other headers */
#inventoryTable thead th.icon-col {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.35rem 0.4rem;
}

/* Icon cells in the body: inherit color so they match the row's text color and striping */
 #inventoryTable tbody td.icon-col {
  color: inherit;
  padding: 0.25rem 0.35rem;
}

/* Icon button visual blending */
#inventoryTable .icon-btn {
  background: transparent; /* keep inline with row */
  color: var(--text-secondary);
  box-shadow: none;
}

/* Removed hover effect to prevent cell flooding */

#inventoryTable .icon-btn:active { transform: translateY(0); }

/* Slightly smaller icon size in cells to reduce visual weight */
#inventoryTable .icon-svg { width: 0.95rem; height: 0.95rem; }

/* Dense table mode: reduce paddings, font-size and icon sizes for a compact view */
#inventoryTable {
  font-size: 0.86rem; /* slightly smaller overall */
}

#inventoryTable th,
#inventoryTable td {
  padding: 0.18rem 0.28rem; /* tighter padding */
}

/* Increase header height to accommodate sort arrows */
#inventoryTable thead th {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

#inventoryTable .icon-btn { width: 2rem; height: 2rem; }
#inventoryTable .icon-svg { width: 0.9rem; height: 0.9rem; }

/* Force tbody into a lower stacking context so positioned td cells
   (metal, actions) never paint above the sticky thead (z-index: 2) */
#inventoryTable tbody {
  position: relative;
  z-index: 1;
}

/* Tighter row height with improved visual separation */
#inventoryTable tbody tr {
  min-height: 2rem;
  background: var(--bg-primary);
  border-bottom: 2px solid var(--bg-secondary);
}

/* Alternating row background using theme tokens */
#inventoryTable tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

/* Neutralise generic tr:hover on header row — filter/position on a tr ancestor
   breaks position:sticky on child th elements */
#inventoryTable thead tr:hover {
  filter: none;
  box-shadow: none;
  position: static;
  z-index: auto;
}

/* Hover state for data rows — override generic tr:hover which sets
   position:relative + z-index:1, causing rows to paint above the sticky thead */
#inventoryTable tbody tr:hover {
  background: var(--bg-tertiary);
  filter: none;
  box-shadow: none;
  position: static;
  z-index: auto;
}

/* Prevent any data cell from elevating above the sticky header (z-index:2) */
#inventoryTable tbody td {
  z-index: auto;
}

/* Keep visual clarity on very small screens */
@media (max-width: 480px) {
  #inventoryTable { font-size: 0.75rem; }
  #inventoryTable th, #inventoryTable td { padding: 0.14rem 0.12rem; }
  #inventoryTable .icon-btn { width: 1.8rem; height: 1.8rem; }
  #inventoryTable .icon-svg { width: 0.8rem; height: 0.8rem; }
}


.center-align {
  text-align: center !important;
}

.center-align td {
  text-align: center !important;
}

/* Type-specific color helpers */
.type-coin { color: var(--type-coin-bg); }
.type-round { color: var(--type-round-bg); }
.type-bar { color: var(--type-bar-bg); }
.type-note { color: var(--type-note-bg); }
.type-set { color: var(--type-set-bg); }
.type-other { color: var(--type-other-bg); }

/* =============================================================================
   CATALOG LINK STYLING
   Enhanced N# column with database/catalog icons representing external database
   ============================================================================= */

.catalog-link {
  display: inline;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  transition: opacity 0.2s ease;
}

/* Light mode - bold blue */
:root .catalog-link {
  color: #1d4ed8;
}

.catalog-link:hover {
  text-decoration: underline;
  opacity: 0.8;
}

/* Dark mode - light blue */
[data-theme="dark"] .catalog-link {
  color: #60a5fa;
}

/* Sepia mode - bold blue */
[data-theme="sepia"] .catalog-link {
  color: #1d4ed8;
}

/* eBay price link styling */
.ebay-price-link {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
}

.ebay-price-link:hover {
  opacity: 0.8;
}

.ebay-search-svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.ebay-price-link:hover .ebay-search-svg {
  color: var(--text-primary);
}

/* Retail/Gain-Loss confidence styling — estimated (melt fallback) vs confirmed (manual) */
.retail-estimated {
  font-style: italic;
  color: var(--text-muted);
}
.retail-confirmed {
  font-weight: 600;
}
.gainloss-estimated {
  font-style: italic;
  color: var(--text-muted);
}

/* Responsive catalog link with improved mobile experience */
@media (max-width: 768px) {
  .catalog-link {
    font-size: 0.7rem;
  }
}

@media (max-width: 600px) {
  .catalog-link {
    font-size: 0.65rem;
  }
}

@media (max-width: 480px) {
  .catalog-link {
    font-size: 0.6rem;
  }
}

/* =============================================================================
   NUMISTA TAG — Inline N# badge on inventory table Name cell
   ============================================================================= */
.numista-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.3rem;
  margin-left: 0.25rem;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
}

.numista-tag:hover,
.numista-tag:focus-visible {
  background: var(--primary);
  color: #fff;
  outline: none;
}

/* Dark theme overrides */
[data-theme="dark"] .numista-tag {
  background: rgba(255, 255, 255, 0.1);
  color: #60a5fa;
}
[data-theme="dark"] .numista-tag:hover,
[data-theme="dark"] .numista-tag:focus-visible {
  background: #60a5fa;
  color: #1a1a2e;
}

/* Sepia theme overrides */
[data-theme="sepia"] .numista-tag {
  background: rgba(0, 0, 0, 0.08);
  color: #1d4ed8;
}
[data-theme="sepia"] .numista-tag:hover,
[data-theme="sepia"] .numista-tag:focus-visible {
  background: #1d4ed8;
  color: #fff;
}

/* =============================================================================
   PCGS TAG — Inline PCGS# badge on inventory table Name cell
   ============================================================================= */
.pcgs-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.3rem;
  margin-left: 0.25rem;
  border-radius: var(--radius);
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
}

.pcgs-tag:hover,
.pcgs-tag:focus-visible {
  background: #2563eb;
  color: #fff;
  outline: none;
}

/* Dark theme overrides */
[data-theme="dark"] .pcgs-tag {
  background: rgba(37, 99, 235, 0.2);
  color: #60a5fa;
}
[data-theme="dark"] .pcgs-tag:hover,
[data-theme="dark"] .pcgs-tag:focus-visible {
  background: #2563eb;
  color: #fff;
}

/* Sepia theme overrides */
[data-theme="sepia"] .pcgs-tag {
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
}
[data-theme="sepia"] .pcgs-tag:hover,
[data-theme="sepia"] .pcgs-tag:focus-visible {
  background: #1d4ed8;
  color: #fff;
}

/* =============================================================================
   YEAR TAG — Inline year badge on inventory table Name cell
   ============================================================================= */
.year-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  margin-left: 0.35rem;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-secondary, #666);
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
}

/* Dark theme overrides */
[data-theme="dark"] .year-tag {
  background: rgba(255, 255, 255, 0.08);
  color: #9ca3af;
}

/* Sepia theme overrides */
[data-theme="sepia"] .year-tag {
  background: rgba(0, 0, 0, 0.06);
  color: #78716c;
}

/* =============================================================================
   PURITY TAG — Inline purity badge on inventory table Name cell
   ============================================================================= */

.purity-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  margin-left: 0.35rem;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-secondary, #666);
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
}

[data-theme="dark"] .purity-tag {
  background: rgba(255, 255, 255, 0.08);
  color: #9ca3af;
}

[data-theme="sepia"] .purity-tag {
  background: rgba(0, 0, 0, 0.06);
  color: #78716c;
}

/* =============================================================================
   GRADE TAG — Inline grade badge on inventory table Name cell
   Color-coded by grading authority: PCGS=blue, NGC=gold, ANACS=green, ICG=purple
   ============================================================================= */
.grade-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  margin-left: 0.35rem;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-secondary, #666);
  text-decoration: none;
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
}

/* Clickable grade tags (have cert number) */
.grade-tag[data-clickable="true"] {
  cursor: pointer;
  transition: var(--transition);
}
.grade-tag[data-clickable="true"]:hover,
.grade-tag[data-clickable="true"]:focus-visible {
  filter: brightness(0.85);
  outline: none;
}

/* Authority color coding — Light theme */
.grade-tag[data-authority="PCGS"] {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
}
.grade-tag[data-authority="NGC"] {
  background: rgba(217, 119, 6, 0.12);
  color: #d97706;
}
.grade-tag[data-authority="ANACS"] {
  background: rgba(5, 150, 105, 0.12);
  color: #059669;
}
.grade-tag[data-authority="ICG"] {
  background: rgba(124, 58, 237, 0.12);
  color: #7c3aed;
}

/* Clickable hover overrides — Light theme */
.grade-tag[data-clickable="true"][data-authority="PCGS"]:hover,
.grade-tag[data-clickable="true"][data-authority="PCGS"]:focus-visible {
  background: #2563eb;
  color: #fff;
}
.grade-tag[data-clickable="true"][data-authority="NGC"]:hover,
.grade-tag[data-clickable="true"][data-authority="NGC"]:focus-visible {
  background: #d97706;
  color: #fff;
}
.grade-tag[data-clickable="true"][data-authority="ANACS"]:hover,
.grade-tag[data-clickable="true"][data-authority="ANACS"]:focus-visible {
  background: #059669;
  color: #fff;
}
.grade-tag[data-clickable="true"][data-authority="ICG"]:hover,
.grade-tag[data-clickable="true"][data-authority="ICG"]:focus-visible {
  background: #7c3aed;
  color: #fff;
}

/* Dark theme overrides */
[data-theme="dark"] .grade-tag {
  background: rgba(255, 255, 255, 0.08);
  color: #9ca3af;
}
[data-theme="dark"] .grade-tag[data-authority="PCGS"] {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
}
[data-theme="dark"] .grade-tag[data-authority="NGC"] {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}
[data-theme="dark"] .grade-tag[data-authority="ANACS"] {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
}
[data-theme="dark"] .grade-tag[data-authority="ICG"] {
  background: rgba(167, 139, 250, 0.15);
  color: #a78bfa;
}
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="PCGS"]:hover,
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="PCGS"]:focus-visible {
  background: #60a5fa;
  color: #1a1a2e;
}
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="NGC"]:hover,
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="NGC"]:focus-visible {
  background: #fbbf24;
  color: #1a1a2e;
}
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="ANACS"]:hover,
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="ANACS"]:focus-visible {
  background: #34d399;
  color: #1a1a2e;
}
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="ICG"]:hover,
[data-theme="dark"] .grade-tag[data-clickable="true"][data-authority="ICG"]:focus-visible {
  background: #a78bfa;
  color: #1a1a2e;
}

/* Sepia theme overrides */
[data-theme="sepia"] .grade-tag {
  background: rgba(0, 0, 0, 0.06);
  color: #78716c;
}
[data-theme="sepia"] .grade-tag[data-authority="PCGS"] {
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
}
[data-theme="sepia"] .grade-tag[data-authority="NGC"] {
  background: rgba(180, 83, 9, 0.1);
  color: #b45309;
}
[data-theme="sepia"] .grade-tag[data-authority="ANACS"] {
  background: rgba(4, 120, 87, 0.1);
  color: #047857;
}
[data-theme="sepia"] .grade-tag[data-authority="ICG"] {
  background: rgba(109, 40, 217, 0.1);
  color: #6d28d9;
}
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="PCGS"]:hover,
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="PCGS"]:focus-visible {
  background: #1d4ed8;
  color: #fff;
}
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="NGC"]:hover,
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="NGC"]:focus-visible {
  background: #b45309;
  color: #fff;
}
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="ANACS"]:hover,
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="ANACS"]:focus-visible {
  background: #047857;
  color: #fff;
}
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="ICG"]:hover,
[data-theme="sepia"] .grade-tag[data-clickable="true"][data-authority="ICG"]:focus-visible {
  background: #6d28d9;
  color: #fff;
}

/* =============================================================================
   SERIAL TAG — Inline serial number badge (purple tint)
   ============================================================================= */
.serial-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.1rem 0.3rem;
  margin-left: 0.25rem;
  border-radius: var(--radius);
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
  max-width: 8ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .serial-tag {
  background: rgba(139, 92, 246, 0.18);
  color: #a78bfa;
}

[data-theme="sepia"] .serial-tag {
  background: rgba(109, 40, 217, 0.1);
  color: #6d28d9;
}

/* =============================================================================
   STORAGE TAG — Inline storage location badge (muted, truncated)
   ============================================================================= */
.storage-tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.6rem;
  font-weight: 500;
  padding: 0.1rem 0.3rem;
  margin-left: 0.25rem;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-muted);
  vertical-align: middle;
  line-height: 1.2;
  white-space: nowrap;
  max-width: 8ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .storage-tag {
  background: rgba(255, 255, 255, 0.06);
  color: #6b7280;
}

[data-theme="sepia"] .storage-tag {
  background: rgba(0, 0, 0, 0.05);
  color: #a8a29e;
}

/* =============================================================================
   NOTES INDICATOR — Small icon when item has notes
   ============================================================================= */
.notes-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.25rem;
  color: var(--text-muted);
  vertical-align: middle;
  line-height: 1;
  cursor: pointer;
}

.notes-indicator:hover {
  color: var(--primary);
}

.notes-indicator svg {
  width: 0.75rem;
  height: 0.75rem;
}

[data-theme="dark"] .notes-indicator {
  color: #6b7280;
}

[data-theme="sepia"] .notes-indicator {
  color: #a8a29e;
}

/* =============================================================================
   PCGS VERIFY BUTTON — Small checkmark icon inside grade tag
   ============================================================================= */
.pcgs-verify-btn {
  display: inline-flex;
  align-items: center;
  margin-left: 0.2rem;
  cursor: pointer;
  opacity: 0.5;
  transition: var(--transition);
  vertical-align: middle;
}

.pcgs-verify-btn:hover {
  opacity: 1;
}

.pcgs-verify-btn.pcgs-verifying {
  opacity: 0.3;
  animation: pcgs-pulse 1s ease-in-out infinite;
}

.pcgs-verify-btn.pcgs-verified {
  opacity: 1;
  color: #16a34a;
}

.pcgs-verify-btn.pcgs-verify-failed {
  opacity: 1;
  color: #dc2626;
}

@keyframes pcgs-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

[data-theme="dark"] .pcgs-verify-btn.pcgs-verified {
  color: #4ade80;
}

[data-theme="sepia"] .pcgs-verify-btn.pcgs-verified {
  color: #15803d;
}

[data-theme="dark"] #certVerifiedIcon { color: #4ade80; }
[data-theme="sepia"] #certVerifiedIcon { color: #15803d; }

/* =============================================================================
   FORM INFO ICON — Always-visible (i) link icon in form labels
   ============================================================================= */
.form-info-icon {
  color: var(--warning, #f59e0b);
  text-decoration: none;
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.25rem;
}
.form-info-icon:visited,
.form-info-icon:hover,
.form-info-icon:active,
.form-info-icon:link {
  color: var(--warning, #f59e0b);
}
.form-info-icon:hover {
  opacity: 0.8;
}
.form-info-icon svg {
  stroke: currentColor;
}

/* =============================================================================
   ITEM MODAL ACTION BAR — Search Numista left, Cancel/Submit right
   ============================================================================= */
.item-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  gap: 0.5rem;
}

.item-modal-actions-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.item-modal-actions-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =============================================================================
   NUMISTA RESULTS MODAL — Stacked modal for search results / field picker
   ============================================================================= */
#numistaResultsModal {
  z-index: 10000;
}

.numista-results-modal-content {
  max-width: 600px;
  width: 90%;
}

.numista-results-list {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.numista-result-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-secondary);
}

.numista-result-card:hover {
  border-color: var(--primary);
  background: var(--bg-tertiary);
}

.numista-result-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.numista-result-images {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.numista-result-card img,
.numista-selected-preview .numista-result-images img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg-primary);
}

.numista-img-placeholder {
  width: 48px;
  height: 48px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* Search refinement bar above results — sticky so it stays visible while scrolling */
.numista-refine-search {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  padding: 0.25rem 0 0.5rem;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-secondary);
}

.numista-refine-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.numista-refine-btn {
  padding: 0.5rem 1rem;
  white-space: nowrap;
  font-size: 0.85rem;
}

.numista-result-info {
  flex: 1;
  min-width: 0;
}

.numista-result-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.numista-result-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.numista-result-id {
  font-size: 0.7rem;
  color: var(--primary);
  font-weight: 600;
}

/* Field picker area */
.numista-field-picker {
  padding: 0.5rem 0;
}

.numista-selected-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  margin-bottom: 0.75rem;
}

/* .numista-selected-preview img — handled by .numista-result-images img above */

.numista-field-checkboxes {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.35rem 0.5rem;
  align-items: center;
  margin: 0 0 0.75rem 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.numista-fields-heading {
  grid-column: 1 / -1;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}

.numista-field-checkboxes input[type="checkbox"] {
  margin: 0;
}

.numista-field-label {
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
  text-align: right;
  color: var(--text-secondary, var(--text-primary));
}

.numista-field-input {
  min-width: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
}

.numista-field-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.numista-field-input:focus {
  border-color: var(--primary);
  outline: none;
}

.numista-field-current {
  grid-column: 3;
  font-size: 0.65rem;
  color: var(--text-muted, #999);
  margin-top: -0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.numista-field-warn {
  grid-column: 1 / -1;
  font-size: 0.7rem;
  color: var(--danger, #f44336);
  font-style: italic;
  margin-top: -0.2rem;
  padding-left: 1.5rem;
}

.numista-fill-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.numista-no-results {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Enhanced no-results: retry search + quick-picks */
.numista-no-results-enhanced {
  padding: 1rem;
}

.numista-retry-search p {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.75rem;
}

.numista-retry-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.numista-retry-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.numista-retry-btn {
  white-space: nowrap;
}

.numista-quick-picks-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.numista-quick-picks-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 280px;
  overflow-y: auto;
}

.numista-quick-pick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}

.numista-quick-pick:hover {
  background: var(--bg-hover);
}

.quick-pick-id {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.85rem;
  min-width: 5rem;
}

.quick-pick-name {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-pick-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 0.1rem 0.4rem;
  border-radius: 0.75rem;
}

/* =============================================================================
   SPOT LOOKUP MODAL — Historical spot price search (STACK-49)
   ============================================================================= */
#spotLookupModal {
  z-index: 10000;
}

.spot-lookup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.spot-lookup-table th {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.spot-lookup-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.spot-lookup-table tr:last-child td {
  border-bottom: none;
}

.spot-lookup-offset {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 0.75rem;
  background: var(--bg-secondary);
  color: var(--text-muted);
}

.spot-lookup-offset.exact {
  background: var(--primary);
  color: #fff;
}

.spot-lookup-use-btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
}

.spot-lookup-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.spot-lookup-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.spot-lookup-fetch-btn {
  margin-top: 1rem;
}

#typeSummary .summary-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.4rem;
  min-height: 1.25rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  margin: 0.05rem;
  line-height: 1.1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  max-width: fit-content;
}

#typeSummary .summary-chip:hover {
  transform: translateY(-1px) scale(1.05);
  box-shadow: var(--shadow);
  filter: brightness(1.1);
}

#typeSummary .summary-chip:active {
  transform: translateY(0) scale(1.02);
}

/* Enhanced chip styling for better visual hierarchy */
#typeSummary .type-chip,
#typeSummary .metal-chip {
  font-weight: 700;
  border-width: 2px;
}

#typeSummary .purchase-chip,
#typeSummary .storage-chip,
#typeSummary .name-chip {
  font-weight: 500;
  font-style: italic;
  border-style: dashed;
}

.type-chip.coin {
  background-color: var(--type-coin-bg);
  color: var(--type-coin-text);
}
.type-chip.round {
  background-color: var(--type-round-bg);
  color: var(--type-round-text);
}
.type-chip.bar {
  background-color: var(--type-bar-bg);
  color: var(--type-bar-text);
}
.type-chip.note {
  background-color: var(--type-note-bg);
  color: var(--type-note-text);
}
.type-chip.set {
  background-color: var(--type-set-bg);
  color: var(--type-set-text);
}
.type-chip.other {
  background-color: var(--type-other-bg);
  color: var(--type-other-text);
}

/* =============================================================================
   CONTROL SETTINGS - NEW LAYOUT
   Positioned at bottom right of filters card
   ============================================================================= */

.control-settings {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--spacing-sm);
  box-shadow: var(--shadow-sm);
  min-width: fit-content;
  align-self: flex-start;
}

.chip-control,
.items-control,
.group-names-control {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  white-space: nowrap;
}

/* Anchor dropdown controls to lower right */
.control-settings {
  display: flex;
  gap: var(--spacing);
  justify-content: flex-end;
  align-items: flex-end;
  flex-wrap: wrap;
}

.chip-label,
.items-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0;
  min-width: fit-content;
}

.chip-select,
.table-select {
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.75rem;
  min-width: 50px;
  cursor: pointer;
  transition: var(--transition);
}

.chip-select:focus,
.table-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.chip-select:hover,
.table-select:hover {
  border-color: var(--primary);
}

/* Responsive adjustments for control settings */
@media (max-width: 768px) {
  /* Keep filter controls horizontal, compact (STAK-126) */
  .filter-controls {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-xs);
  }

  .control-label {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .filter-controls {
    gap: var(--spacing-xs);
  }

  .control-label {
    font-size: 0.65rem;
  }
  
  .control-select {
    width: 100%;
  }
}

/* Debug modal styling */
#debugModalContent {
  max-height: 60vh;
  overflow-y: auto;
  font-family: monospace;
  white-space: pre-wrap;
}

/* =============================================================================
   ENCRYPTION UI STYLES
   Master password and encryption management interface
   ============================================================================= */

.encryption-section {
  background: var(--bg-card);
  border: 2px solid var(--primary) !important;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.encryption-status {
  margin-bottom: 1rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-indicator.status-success .status-dot {
  background: var(--success);
  animation: pulse-success 2s infinite;
}

.status-indicator.status-warning .status-dot {
  background: var(--warning);
}

.status-indicator.status-error .status-dot {
  background: var(--danger);
  animation: pulse-error 2s infinite;
}

.status-indicator.status-info .status-dot {
  background: var(--info);
}

@keyframes pulse-success {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes pulse-error {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-text {
  font-weight: 500;
  color: var(--text-primary);
}

.form-row {
  margin-bottom: 1rem;
}

.form-row label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
  color: var(--text-primary);
}

.form-row input[type="password"] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 0.875rem;
}

.form-row input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary)20;
}

.encryption-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.encryption-actions .btn {
  flex: 0 0 auto;
}

.encryption-info {
  background: var(--bg-secondary);
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.encryption-info strong {
  color: var(--text-primary);
}

.data-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.status-item {
  padding: 0.5rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
}

.status-item.status-success {
  background: var(--success)20;
  color: var(--success);
  border: 1px solid var(--success)40;
}

.status-item.status-warning {
  background: var(--warning)20;
  color: var(--warning);
  border: 1px solid var(--warning)40;
}

.status-item.status-info {
  background: var(--info)20;
  color: var(--info);
  border: 1px solid var(--info)40;
}

.encryption-warning {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--warning)15;
  border: 1px solid var(--warning)40;
  border-radius: var(--radius);
  color: var(--text-primary);
}

.encryption-warning strong {
  color: var(--warning);
}

.change-password-section {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: var(--radius);
  margin-top: 1rem;
  border: 1px solid var(--border);
}

.change-password-section h4 {
  margin: 0 0 1rem 0;
  color: var(--text-primary);
}

/* Dark mode encryption styles */
[data-theme="dark"] .encryption-section {
  background: var(--bg-card);
  border-color: var(--primary) !important;
}

[data-theme="dark"] .status-indicator {
  background: var(--bg-secondary);
}

[data-theme="dark"] .form-row input[type="password"] {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-primary);
}

[data-theme="dark"] .encryption-info {
  background: var(--bg-secondary);
}

[data-theme="dark"] .change-password-section {
  background: var(--bg-secondary);
  border-color: var(--border);
}

/* Sepia mode encryption styles */
[data-theme="sepia"] .encryption-section {
  background: var(--bg-card);
  border-color: var(--primary) !important;
}

[data-theme="sepia"] .status-indicator {
  background: var(--bg-secondary);
}

[data-theme="sepia"] .form-row input[type="password"] {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-primary);
}

[data-theme="sepia"] .encryption-info {
  background: var(--bg-secondary);
}

[data-theme="sepia"] .change-password-section {
  background: var(--bg-secondary);
  border-color: var(--border);
}

/* =============================================================================
   VAULT ENCRYPTED BACKUP STYLES
   Password input groups, strength bar, match indicator, separator
   ============================================================================= */

.password-input-group {
  display: flex;
  gap: 0;
}

.password-input-group input[type="password"],
.password-input-group input[type="text"] {
  flex: 1;
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.password-toggle {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}

.password-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.strength-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.375rem;
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease, background 0.3s ease;
  width: 0%;
}

.strength-text {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  font-weight: 500;
}

.password-match {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  font-weight: 500;
}

.vault-separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
  width: 100%;
}

.vault-dot-pulse {
  animation: vault-pulse 1.5s ease-in-out infinite;
}

@keyframes vault-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Dark mode vault styles */
[data-theme="dark"] .password-toggle {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-secondary);
}

[data-theme="dark"] .password-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

[data-theme="dark"] .strength-bar {
  background: var(--border);
}

/* Sepia mode vault styles */
[data-theme="sepia"] .password-toggle {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-secondary);
}

[data-theme="sepia"] .password-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

[data-theme="sepia"] .strength-bar {
  background: var(--border);
}

/* =============================================================================
   MODERN RESPONSIVE TABLE REDESIGN
   ============================================================================= */

/* Fix storage location width to 25 characters max */
#inventoryTable td[data-column="storageLocation"] {
  max-width: 25ch !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Metal column toggle with increased width */
#inventoryTable td[data-column="metal"] {
  max-width: 25ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}

/* Remove ellipsis from action buttons - clean look */
#inventoryTable td.icon-col {
  text-overflow: clip !important;
  overflow: clip !important;
}

/* Enhanced delete button styling - restore red */
#inventoryTable td.icon-col .action-icon.danger {
  color: var(--error) !important;
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  /* Removed transition: all 0.2s ease; */
}

/* Removed hover effect to prevent cell flooding */

/* Portfolio column styling */
#inventoryTable td[data-column="meltValue"],
#inventoryTable td[data-column="retailPrice"],
#inventoryTable td[data-column="gainLoss"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Legacy "Responsive column hiding" section removed —
   consolidated into canonical responsive block and card-view rules.
   See STACK-38 / STACK-31. */

/* Smooth table scrolling */
#inventoryTable {
  scroll-behavior: smooth;
  border-collapse: separate;
  border-spacing: 0;
}

/* Modern table cell styling */
#inventoryTable td {
  border-bottom: 1px solid var(--border);
}

/* Legacy price column styling - consolidated above */

/* Legacy price toggle styling - no longer used but kept for compatibility */
.price-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.price-toggle:hover {
  background: var(--primary);
  color: white !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Purchase location styling and column width */
#inventoryTable th[data-column="purchaseLocation"],
#inventoryTable td[data-column="purchaseLocation"] {
  max-width: 140px !important; /* Reduced from default ~200px to 2/3 size */
  width: 140px !important;
}

.purchase-link {
  color: var(--primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
  vertical-align: middle;
}

.purchase-link:hover {
  color: var(--primary-hover);
}

.purchase-link-icon {
  flex-shrink: 0;
}

/* Purchase Price column — fixed width */
#inventoryTable th[data-column="purchasePrice"],
#inventoryTable td[data-column="purchasePrice"] {
  max-width: 110px !important;
  width: 110px !important;
  min-width: 110px !important;
  text-align: right;
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Melt, Retail, Gain/Loss columns — auto-size to content */
#inventoryTable th[data-column="meltValue"],
#inventoryTable td[data-column="meltValue"],
#inventoryTable th[data-column="retailPrice"],
#inventoryTable td[data-column="retailPrice"],
#inventoryTable th[data-column="gainLoss"],
#inventoryTable td[data-column="gainLoss"] {
  width: auto !important;
  min-width: unset !important;
  max-width: none !important;
  text-align: right;
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

/* Price headers — inherit system font from .header-text */
#inventoryTable th[data-column="purchasePrice"],
#inventoryTable th[data-column="meltValue"],
#inventoryTable th[data-column="retailPrice"],
#inventoryTable th[data-column="gainLoss"] {
  font-weight: 600;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* Price data cells — monospace for numeric alignment */
#inventoryTable td[data-column="purchasePrice"],
#inventoryTable td[data-column="meltValue"],
#inventoryTable td[data-column="retailPrice"],
#inventoryTable td[data-column="gainLoss"] {
  font-family: var(--font-mono, 'Courier New', monospace);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Text columns use main font family */
#inventoryTable td[data-column="name"],
#inventoryTable td[data-column="metal"],
#inventoryTable td[data-column="purchaseLocation"],
#inventoryTable td[data-column="date"] {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Numerical value consistency across all numeric columns */
#inventoryTable td[data-column="qty"],
#inventoryTable td[data-column="weight"],
#inventoryTable td[data-column="purchasePrice"],
#inventoryTable td[data-column="meltValue"],
#inventoryTable td[data-column="retailPrice"],
#inventoryTable td[data-column="gainLoss"] {
  font-family: var(--font-mono, 'Courier New', monospace) !important;
  font-size: 0.85rem !important;
  font-weight: 500 !important;
  text-align: right !important;
}

/* Completely disable ALL hover effects on action icons to prevent cell flooding */
#inventoryTable .icon-btn:hover,
#inventoryTable .action-icon:hover,
#inventoryTable .icon-btn:focus,
#inventoryTable .action-icon:focus {
  background: transparent !important;
  transform: none !important;
  box-shadow: none !important;
  outline: none !important;
}

/* Allow inline edit icons to remain functional with subtle hover */
#inventoryTable .inline-edit-icon:hover {
  opacity: 1 !important;
  background: rgba(59, 130, 246, 0.1) !important;
  border-radius: 50% !important;
}

/* Subtle color variations for different numeric types */
#inventoryTable td[data-column="qty"] {
  color: rgba(59, 130, 246, 0.9); /* Soft blue for quantities */
}

#inventoryTable td[data-column="weight"] {
  color: rgba(107, 114, 128, 0.95); /* Muted gray for weights */
}

#inventoryTable td[data-column="purchasePrice"] {
  color: rgba(34, 197, 94, 0.9); /* Soft green for purchase prices */
}

#inventoryTable td[data-column="meltValue"] {
  color: rgba(245, 158, 11, 0.9); /* Soft amber for melt values */
}

#inventoryTable td[data-column="retailPrice"] {
  color: rgba(59, 130, 246, 0.95); /* Primary blue for retail values */
}

/* =============================================================================
   SETTINGS GOLDBACK PANEL (STACK-45)
   ============================================================================= */

.settings-goldback-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.settings-goldback-table th,
.settings-goldback-table td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.settings-goldback-table th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* Hide number spinners on denomination price inputs and quick-fill */
.settings-goldback-table input[type="number"]::-webkit-outer-spin-button,
.settings-goldback-table input[type="number"]::-webkit-inner-spin-button,
#goldbackQuickFillInput::-webkit-outer-spin-button,
#goldbackQuickFillInput::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.settings-goldback-table input[type="number"],
#goldbackQuickFillInput {
  -moz-appearance: textfield;
}

/* Style links inside the goldback settings panel */
#settingsPanel_goldback a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
#settingsPanel_goldback a:hover {
  text-decoration: underline;
  opacity: 0.85;
}
#settingsPanel_goldback a:visited {
  color: var(--primary);
}

/* =============================================================================
   SETTINGS CHANGE LOG PANEL
   ============================================================================= */

.settings-changelog-actions {
  margin-bottom: var(--spacing);
}

.settings-changelog-wrap {
  overflow-y: auto;
  max-height: 55vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#settingsChangeLogTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

#settingsChangeLogTable thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-secondary, var(--bg));
}

#settingsChangeLogTable th {
  padding: 0.35rem 0.5rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

#settingsChangeLogTable td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

#settingsChangeLogTable tr {
  cursor: pointer;
  transition: background 0.1s;
}

#settingsChangeLogTable tbody tr:hover {
  background: var(--hover-bg, rgba(0,0,0,0.03));
}

#settingsChangeLogTable .action-btn {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
}

/* Log sub-tabs (inside Activity Log panel) */
.settings-log-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin: 1rem 0 0 0;
}

.settings-log-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.settings-log-tab:hover {
  color: var(--text-primary);
}

.settings-log-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.settings-log-panel {
  padding-top: 1rem;
}

/* Price history filter + clear row */
.settings-pricehistory-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: var(--spacing);
}

.settings-filter-input {
  flex: 1;
  max-width: 280px;
  padding: 0.35rem 0.6rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

.settings-filter-input:focus {
  border-color: var(--primary);
}

/* Shared table styles for all log sub-tab tables */
#settingsSpotHistoryTable,
#settingsCatalogHistoryTable,
#settingsPriceHistoryTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

#settingsSpotHistoryTable thead,
#settingsCatalogHistoryTable thead,
#settingsPriceHistoryTable thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-secondary, var(--bg));
}

#settingsSpotHistoryTable th,
#settingsCatalogHistoryTable th,
#settingsPriceHistoryTable th {
  padding: 0.35rem 0.5rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

#settingsSpotHistoryTable td,
#settingsCatalogHistoryTable td,
#settingsPriceHistoryTable td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* Empty-state message row */
.settings-log-empty td {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem 0.5rem;
  font-style: italic;
}

/* =============================================================================
   BULK EDIT MODAL
   ============================================================================= */

.bulk-edit-content {
  width: 95vw;
  max-width: 1400px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.bulk-edit-content .modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #f8fafc;
  padding: var(--spacing) var(--spacing-xl);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  flex-shrink: 0;
}

.bulk-edit-content .modal-header h2 {
  margin: 0;
  color: #f8fafc;
  text-align: center;
}

.bulk-edit-body {
  display: flex;
  gap: 1.5rem;
  overflow: hidden;
  padding: var(--spacing);
  flex: 1;
  min-height: 0;
}

.bulk-edit-fields {
  width: 300px;
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 70vh;
  padding-right: var(--spacing);
  border-right: 1px solid var(--border);
}

.bulk-edit-fields h3 {
  margin: 0 0 var(--spacing) 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.bulk-edit-field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.bulk-edit-field-row:hover {
  background: var(--hover-bg, rgba(0,0,0,0.03));
}

.bulk-edit-field-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
}

.bulk-edit-field-row label {
  flex-shrink: 0;
  width: 90px;
  margin-bottom: 0;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bulk-edit-field-row .field-input {
  flex: 1;
  width: auto;
  min-width: 0;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  background: var(--bg);
  color: var(--text);
  transition: opacity 0.15s, border-color 0.15s;
}

.bulk-edit-field-row .field-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bulk-edit-field-row .field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.bulk-edit-field-row textarea.field-input {
  resize: vertical;
  min-height: 2.4rem;
}

.bulk-edit-items {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bulk-edit-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: var(--spacing);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bulk-edit-toolbar input[type="search"] {
  flex: 1;
  min-width: 150px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
}

.bulk-edit-toolbar input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
}

.bulk-edit-toolbar .btn {
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}

.bulk-edit-count-badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  white-space: nowrap;
}

.bulk-edit-table-wrap {
  overflow-y: auto;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bulk-edit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.bulk-edit-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
}

.bulk-edit-table th {
  padding: 0.5rem 0.6rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.bulk-edit-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
}

.bulk-edit-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.bulk-edit-table tr {
  cursor: pointer;
  transition: background 0.1s;
}

.bulk-edit-table tbody tr:hover {
  background: var(--hover-bg, rgba(0,0,0,0.03));
}

.bulk-edit-selected {
  background: rgba(59, 130, 246, 0.08) !important;
}

[data-theme="dark"] .bulk-edit-selected {
  background: rgba(59, 130, 246, 0.18) !important;
}

[data-theme="sepia"] .bulk-edit-selected {
  background: rgba(139, 92, 42, 0.08) !important;
}

/* Pinned section — selected items not matching current search */
.bulk-edit-pinned-header td {
  background: var(--bg-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 0.35rem 0.75rem;
  cursor: default;
}

.bulk-edit-pinned-header:hover {
  background: var(--bg-secondary) !important;
}

.bulk-edit-pinned {
  border-left: 3px solid var(--primary);
}

.bulk-edit-pinned.bulk-edit-selected {
  background: rgba(59, 130, 246, 0.12) !important;
}

[data-theme="dark"] .bulk-edit-pinned.bulk-edit-selected {
  background: rgba(59, 130, 246, 0.22) !important;
}

[data-theme="sepia"] .bulk-edit-pinned.bulk-edit-selected {
  background: rgba(139, 92, 42, 0.12) !important;
}

.bulk-edit-pinned-divider td {
  height: 2px;
  padding: 0;
  background: var(--border);
}

.bulk-edit-pinned-divider,
.bulk-edit-pinned-divider:hover {
  cursor: default;
  background: none !important;
}

.bulk-edit-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: var(--spacing) var(--spacing-xl);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bulk-edit-footer .btn {
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
}

.bulk-edit-footer .btn-danger {
  margin-left: auto;
}

.bulk-edit-numista-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  transition: border-color 0.15s, color 0.15s;
}

.bulk-edit-numista-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Responsive: stack on small screens */
@media (max-width: 768px) {
  .bulk-edit-body {
    flex-direction: column;
  }
  .bulk-edit-fields {
    width: 100%;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: var(--spacing);
  }
  .bulk-edit-content {
    width: 98vw;
    max-height: 95vh;
  }
}

/* =============================================================================
   CARD VIEW — Inventory table ≤768px  (STACK-31 / STACK-38)
   Converts each <tr> into a flexbox-based card. Labels generated from
   data-label attributes on <td> elements via ::before pseudo-elements.
   ============================================================================= */

@media (max-width: 1350px) {
  /* Hide table header — card labels replace column headers */
  #inventoryTable thead {
    display: none;
  }

  /* Remove table layout so rows become blocks */
  #inventoryTable,
  #inventoryTable tbody {
    display: block;
    width: 100%;
    border-spacing: 0;
  }

  /* Each row becomes a card (flexbox wrap for reliable spanning) */
  #inventoryTable tbody tr {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
  }

  /* All cells: half-width by default (2-column pairs).
     Reset all table-layout width/max-width constraints from .shrink, .expand,
     .icon-col, and data-column selectors — card view uses flex-basis only. */
  #inventoryTable tbody td,
  #inventoryTable tbody td.shrink,
  #inventoryTable tbody td.expand,
  #inventoryTable tbody td.icon-col {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    flex: 0 0 50% !important;
    box-sizing: border-box;
    padding: 0.2rem 0.35rem;
    border: none;
    font-size: 0.95rem;
    color: var(--text-primary);
    width: unset !important;
    max-width: none !important;
    min-width: 0 !important;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  /* Label pseudo-element from data-label attribute */
  #inventoryTable tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-right: 0.5rem;
    flex-shrink: 0;
  }

  /* Name — full-width card title, no label */
  #inventoryTable tbody td[data-column="name"] {
    flex: 0 0 100% !important;
    order: -2;
    font-size: 1.05rem;
    font-weight: 600;
    justify-content: flex-start;
    padding-bottom: 0.25rem;
    text-align: left;
  }
  #inventoryTable tbody td[data-column="name"]::before {
    display: none;
  }

  /* Metal — full-width subtitle row */
  #inventoryTable tbody td[data-column="metal"] {
    flex: 0 0 100% !important;
    order: -1;
    font-size: 0.9rem;
    justify-content: flex-start;
    padding-bottom: 0.35rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
  }
  #inventoryTable tbody td[data-column="metal"]::before {
    display: none;
  }

  /* Actions — full-width bottom row, centered, no label */
  #inventoryTable tbody td[data-column="actions"],
  #inventoryTable tbody td.icon-col[data-column="actions"] {
    flex: 0 0 100% !important;
    width: unset !important;
    max-width: none !important;
    justify-content: center;
    padding-top: 0.35rem;
    margin-top: 0.25rem;
    border-top: 1px solid var(--border);
  }
  #inventoryTable tbody td[data-column="actions"]::before {
    display: none;
  }

  /* Hide lower-priority fields in card view */
  #inventoryTable tbody td[data-column="date"],
  #inventoryTable tbody td[data-column="type"],
  #inventoryTable tbody td[data-column="purchaseLocation"] {
    display: none !important;
  }

  /* Override hideEmptyColumns() display:none for visible card fields */
  #inventoryTable tbody td[data-column="name"],
  #inventoryTable tbody td[data-column="metal"],
  #inventoryTable tbody td[data-column="qty"],
  #inventoryTable tbody td[data-column="weight"],
  #inventoryTable tbody td[data-column="purchasePrice"],
  #inventoryTable tbody td[data-column="meltValue"],
  #inventoryTable tbody td[data-column="retailPrice"],
  #inventoryTable tbody td[data-column="gainLoss"],
  #inventoryTable tbody td[data-column="actions"] {
    display: flex !important;
  }

  /* eBay search SVG icons: hide in card view to save space */
  #inventoryTable tbody td .ebay-search-svg {
    display: none;
  }

  /* Action row layout inside card — centered */
  #inventoryTable tbody td[data-column="actions"] .actions-row {
    display: flex;
    gap: 1rem;
    justify-content: center;
    width: 100%;
  }

  /* Touch-friendly action buttons (44px minimum per Apple HIG) */
  #inventoryTable tbody td[data-column="actions"] .icon-btn {
    width: 2.75rem;
    height: 2.75rem;
    padding: 0.4rem;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
  }

  #inventoryTable tbody td[data-column="actions"] .icon-svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  /* View button: primary accent in card view */
  #inventoryTable tbody td[data-column="actions"] .icon-btn.view-icon {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }

  #inventoryTable tbody td[data-column="actions"] .icon-btn.view-icon .icon-svg {
    fill: #fff;
  }

  /* Cards scroll naturally — remove portal max-height */
  .portal-scroll {
    max-height: none !important;
    overflow: visible;
    -webkit-overflow-scrolling: touch;
  }

  /* Name cell: name on line 1, all chips wrap horizontally on line 2 */
  #inventoryTable tbody td[data-column="name"] .name-cell-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
  }

  /* Name text takes full width → forces chips to next line */
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .filter-text {
    flex: 0 0 100%;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
    font-size: 1.05rem;
  }

  /* Table thumb in card view — slightly larger */
  #inventoryTable tbody td[data-column="name"] .table-thumb {
    width: 36px;
    height: 36px;
  }

  /* Chips: horizontal row, touch-friendly size */
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .year-tag,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .numista-tag,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .pcgs-tag,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .grade-tag,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .serial-tag,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .storage-tag,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .notes-indicator,
  #inventoryTable tbody td[data-column="name"] .name-cell-content > .purity-tag {
    flex-shrink: 0;
    font-size: 0.8rem !important;
    padding: 0.2rem 0.5rem !important;
    min-height: 1.75rem;
    display: inline-flex;
    align-items: center;
  }

  /* Bump card body text sizes for readability */
  #inventoryTable tbody td {
    font-size: 0.95rem;
  }

  #inventoryTable tbody td::before {
    font-size: 0.8rem;
  }

  #inventoryTable tbody td[data-column="metal"] {
    font-size: 0.9rem;
  }

  /* Compact pagination footer for card view */
  .table-footer-controls {
    flex-wrap: wrap;
    gap: var(--spacing-xs);
    justify-content: center;
  }

  .table-item-count {
    font-size: 0.85rem;
  }

  .table-footer-controls select {
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
    max-width: 6rem;
  }
}

/* Header: scale logo and center buttons — mobile only (STACK-70) */
@media (max-width: 768px) {
  .app-header {
    min-height: auto;
    padding: var(--spacing-sm);
    align-items: stretch;
  }

  .app-header > div {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-sm);
  }

  .app-logo {
    width: 100%;
    justify-content: center;
    transform: scale(1.3);
    transform-origin: center top;
    margin-bottom: -1rem;
  }

  .stackr-logo {
    max-width: 100% !important;
  }
}

/* =============================================================================
   DETAILS MODAL — Narrow viewport fixes ≤640px  (STACK-38)
   Stacks panels vertically, single-column breakdown, reduced chart.
   ============================================================================= */

@media (max-width: 640px) {
  #detailsModal .modal-content {
    width: 98vw;
    max-width: 98vw;
    max-height: 98vh;
    padding: var(--spacing-sm);
  }

  .details-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-sm);
  }

  .breakdown-grid {
    grid-template-columns: 1fr;
    gap: 0.125rem;
  }

  /* Reduce breakdown font sizes */
  .breakdown-label {
    font-size: 0.8rem;
  }

  .breakdown-meta {
    font-size: 0.7rem;
  }

  .breakdown-grid {
    font-size: 0.75rem;
  }

  .breakdown-cell-label {
    font-size: 0.7rem;
  }
}

/* =============================================================================
   ADDITIONAL SMALL-VIEWPORT FIXES  (STACK-38)
   Targets zoom-induced short viewports, filter controls, and form grids.
   ============================================================================= */

/* Short viewport (e.g. 300% zoom on 1080p → ~360px height) */
@media (max-height: 500px) {
  .portal-scroll {
    max-height: 50vh;
  }
}

/* Filter controls + form grids at narrow widths */
@media (max-width: 640px) {
  .filter-controls {
    flex-wrap: wrap;
    gap: var(--spacing-xs);
    justify-content: center;
  }

  .grid-2,
  .grid-purity-row {
    grid-template-columns: 1fr;
  }
}

/* =============================================================================
   MOBILE-OPTIMIZED MODALS  (STACK-70)
   Full-screen modals, touch-sized inputs, hidden charts, landscape card view.
   ============================================================================= */

/* --- Phase 1: Full-screen modal base ------------------------------------ */
@media (max-width: 768px) {
  .modal { padding: 0; }

  .modal-content {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh; height: 100dvh;
    max-height: 100vh; max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    animation: none;
  }

  /* Specificity overrides for modals that set their own width */
  .modal-content.settings-modal-content,
  #itemModal .modal-content,
  #detailsModal .modal-content,
  .bulk-edit-content,
  .about-modal-content {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh; height: 100dvh;
    max-height: 100vh; max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  /* Remove header border-radius on fullscreen modals */
  .modal-content .modal-header,
  .about-modal-header,
  .bulk-edit-content .modal-header { border-radius: 0; }

  .modal-content::before { border-radius: 0; }

  /* Exempt small utility modals — keep as centered popups */
  #apiInfoModal .modal-content,
  #notesModal .modal-content,
  #notesViewModal .modal-content,
  #storageOptionsModal .modal-content,
  #cloudSyncModal .modal-content {
    width: 95vw !important;
    max-width: 400px !important;
    height: auto;
    max-height: 90vh; max-height: 90dvh;
    border-radius: var(--radius-lg);
  }

  /* --- Phase 3: Item modal — touch-friendly inputs & stacked actions ---- */
  #itemModal .modal-content { display: flex; flex-direction: column; }
  #itemModal .modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing);
    -webkit-overflow-scrolling: touch;
  }

  /* Touch-sized inputs: 44px min height (Apple HIG) */
  #itemModal input,
  #itemModal select,
  #itemModal textarea {
    min-height: 44px;
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
  }

  #itemModal .btn { min-height: 44px; font-size: 0.9rem; }

  /* Stack action rows: Save/Cancel on top, lookup buttons below */
  .item-modal-actions {
    flex-direction: column;
    gap: var(--spacing);
    padding-top: var(--spacing);
    border-top: 1px solid var(--border);
  }
  .item-modal-actions-left { justify-content: center; order: 2; }
  .item-modal-actions-right { width: 100%; }
  .item-modal-actions-right .btn { flex: 1; }

  /* --- Phase 4: Details modal — hide charts, stack panels --------------- */
  .chart-canvas-container { display: none !important; }
  .chart-metric-toggle { display: none; }

  .details-grid { grid-template-columns: 1fr; gap: var(--spacing); }
  .details-panel { padding: var(--spacing); }
  #detailsModal .modal-body { overflow-y: auto; flex: 1; }

  /* Breakdown grid: keep 2-col for compact financial data */
  .breakdown-grid { grid-template-columns: 1fr 1fr; gap: 0.125rem 0.5rem; }

  /* --- Phase 6: Bulk edit modal — full-screen stacking ------------------ */
  .bulk-edit-content { display: flex; flex-direction: column; }
  .bulk-edit-body {
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
  }
  .bulk-edit-fields {
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .bulk-edit-fields input,
  .bulk-edit-fields select { min-height: 44px; }
  .bulk-edit-items { flex: 1; overflow-y: auto; }
}

/* =============================================================================
   CARD VIEW STYLES — Selectable card designs A/B/C/D (STAK-118)
   ============================================================================= */

/* Container — hidden by default, JS toggles display */
.card-view-grid {
  display: none;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding: 0 0.25rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* Single column on mobile */
.card-view-grid > article {
  flex: 1 1 100%;
  min-width: 0;
}

/* 2-column grid on tablets */
@media (min-width: 640px) {
  .card-view-grid > article { flex: 0 1 calc(50% - 0.35rem); max-width: calc(50% - 0.35rem); }
}

/* 3-column grid on desktop */
@media (min-width: 1100px) {
  .card-view-grid > article { flex: 0 1 calc(33.333% - 0.45rem); max-width: calc(33.333% - 0.45rem); }
}

/* --- Shared card primitives --- */
.cv-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.cv-chip-year { background: var(--bg-tertiary); color: var(--text-muted); }
.cv-chip-grade { background: var(--primary); color: #fff; }
.cv-chip-qty { background: var(--bg-tertiary); color: var(--text-muted); }
.cv-chip-weight { background: var(--bg-tertiary); color: var(--text-muted); }
.cv-chip-type {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cv-chip-type.coin { background: var(--type-coin-bg, #b85f00); color: var(--type-coin-text, #fff); }
.cv-chip-type.bar { background: var(--type-bar-bg, #946d00); color: var(--type-bar-text, #fff); }

.cv-gain { color: var(--success); }
.cv-loss { color: var(--danger); }

.cv-images-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.cv-images-center { justify-content: center; }
.cv-chips-row { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.cv-chips-center { justify-content: center; }
.cv-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.35rem;
  letter-spacing: -0.01em;
}
.cv-item-name-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cv-arrow { margin: 0 0.2rem; opacity: 0.5; }

/* Metal accent colors */
.metal-silver { --metal-color: var(--silver); }
.metal-gold { --metal-color: var(--gold); }
.metal-platinum { --metal-color: var(--platinum); }
.metal-palladium { --metal-color: var(--palladium); }

/* Coin image in cards */
.card-view-grid .coin-img {
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.card-view-grid .coin-img.bar-shape { border-radius: var(--radius); }

/* No-image placeholder — metal-tinted glass orb / rect */
.cv-no-image {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: radial-gradient(ellipse at 35% 30%, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0.05) 40%, transparent 70%),
              linear-gradient(145deg, var(--metal-color, var(--bg-tertiary)), var(--bg-tertiary));
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.18), inset 0 -2px 4px rgba(0,0,0,0.15);
  opacity: 0.65;
}
/* Metal-specific tints inherited from parent .metal-* class */
.metal-silver .cv-no-image { --metal-color: #C0C0C0; }
.metal-gold .cv-no-image { --metal-color: #FFD700; }
.metal-platinum .cv-no-image { --metal-color: #E5E4E2; }
.metal-palladium .cv-no-image { --metal-color: #CED0DD; }

/* Table thumbnails — rect items use contain */
.table-thumb.table-thumb-rect { object-fit: contain; }

/* Table placeholder — same glass effect */
.table-thumb-placeholder.table-no-image {
  background: radial-gradient(ellipse at 35% 30%, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0.05) 40%, transparent 70%),
              linear-gradient(145deg, var(--metal-color, var(--bg-tertiary)), var(--bg-tertiary));
  box-shadow: inset 0 0.5px 1px rgba(255,255,255,0.18), inset 0 -1px 2px rgba(0,0,0,0.12);
  opacity: 0.55;
}

/* --- Card A: Sparkline Header --- */
.card-a {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--metal-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  position: relative;
}
.card-a:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-a:active { transform: scale(0.985); box-shadow: var(--shadow-sm); }
.card-a .card-a-chart-wrap {
  position: relative;
  height: 150px;
  padding: 0.25rem 0.5rem 0;
}
.card-a .card-a-chart-wrap canvas { width: 100% !important; height: 100% !important; }
.card-a .card-body { padding: 0.5rem 0.75rem 0.65rem; }
.card-a .cv-chips-img-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.card-a .cv-chips-row { margin-bottom: 0; }
.card-a .cv-images-sm { display: flex; gap: 0.25rem; flex-shrink: 0; align-items: center; }
.card-a .cv-images-sm .coin-img { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex-shrink: 0; }
.card-a .cv-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 0.78rem;
  gap: 0.5rem;
}
.card-a .cv-value-journey { color: var(--text-muted); font-weight: 400; }
.card-a .cv-value-gain { font-weight: 700; font-size: 0.82rem; white-space: nowrap; }

/* --- Card B: Full-Bleed Overlay --- */
.card-b {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--metal-color, var(--border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  position: relative;
  min-height: 160px;
}
.card-b:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-b:active { transform: scale(0.985); }
.card-b .sparkline-bg {
  position: absolute;
  inset: 0;
  opacity: 0.18;
  pointer-events: none;
}
[data-theme="dark"] .card-b .sparkline-bg { opacity: 0.22; }
[data-theme="sepia"] .card-b .sparkline-bg { opacity: 0.15; }
.card-b .sparkline-bg svg { width: 100%; height: 100%; }
.card-b .card-content {
  position: relative;
  z-index: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
}
.card-b .coin-img { width: 80px; height: 80px; border: 2px solid var(--border); }
.card-b .cv-value-hero {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.card-b .cv-value-detail { font-size: 0.72rem; color: var(--text-muted); }

/* --- Card C: Split Card --- */
.card-c {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--metal-color, var(--border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  display: flex;
  min-height: 120px;
}
.card-c:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-c:active { transform: scale(0.985); }
.card-c .cv-image-col {
  flex: 0 0 100px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem;
  position: relative;
  box-shadow: inset -1px 0 3px rgba(0,0,0,0.08);
}
.card-c .cv-image-col::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 0% 50%, var(--metal-color, transparent) 0%, transparent 70%);
  opacity: 0.18;
  pointer-events: none;
}
/* Rect items in split card — constrained height */
.card-c .coin-img.bar-shape {
  width: 80px;
  height: 56px;
  border-radius: var(--radius);
}
.card-c .coin-img { width: 56px; height: 56px; }
.card-c .cv-sparkline-strip { display: none; }
.card-c .cv-data-col {
  flex: 1;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.3rem;
}
.card-c .cv-item-name { font-size: 0.82rem; }
.card-c .cv-chips-row { gap: 0.2rem; }
.card-c .cv-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 0.75rem;
  padding-top: 0.2rem;
  border-top: 1px solid var(--border);
  margin-top: 0.15rem;
  gap: 0.5rem;
}
.card-c .cv-value-journey { color: var(--text-muted); }
.card-c .cv-value-gain { font-weight: 700; font-size: 0.78rem; white-space: nowrap; }


/* --- Phase 5: Landscape card view (STACK-70) ----------------------------
   Touch devices between 769–1024px get card view via JS-applied
   body.force-card-view class. Rules mirror the ≤768px card block
   (STACK-31, lines ~7342–7593) — keep both in sync during edits.
   ----------------------------------------------------------------------- */

/* Landscape touch: 2-column card grid */
body.force-card-view #inventoryTable thead { display: none; }

body.force-card-view #inventoryTable,
body.force-card-view #inventoryTable tbody {
  display: block;
  width: 100%;
  border-spacing: 0;
}

body.force-card-view #inventoryTable tbody {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

body.force-card-view #inventoryTable tbody tr {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.75rem;
  cursor: pointer;
}

body.force-card-view #inventoryTable tbody td,
body.force-card-view #inventoryTable tbody td.shrink,
body.force-card-view #inventoryTable tbody td.expand,
body.force-card-view #inventoryTable tbody td.icon-col {
  display: flex !important;
  justify-content: space-between;
  align-items: baseline;
  flex: 0 0 50% !important;
  box-sizing: border-box;
  padding: 0.2rem 0.35rem;
  border: none;
  font-size: 0.95rem;
  color: var(--text-primary);
  width: unset !important;
  max-width: none !important;
  min-width: 0 !important;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

body.force-card-view #inventoryTable tbody td::before {
  content: attr(data-label);
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 0.5rem;
  flex-shrink: 0;
}

/* Name — full-width card title */
body.force-card-view #inventoryTable tbody td[data-column="name"] {
  flex: 0 0 100% !important;
  order: -2;
  font-size: 1.05rem;
  font-weight: 600;
  justify-content: flex-start;
  padding-bottom: 0.25rem;
  text-align: left;
}
body.force-card-view #inventoryTable tbody td[data-column="name"]::before { display: none; }

/* Metal — full-width subtitle */
body.force-card-view #inventoryTable tbody td[data-column="metal"] {
  flex: 0 0 100% !important;
  order: -1;
  font-size: 0.9rem;
  justify-content: flex-start;
  padding-bottom: 0.35rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
body.force-card-view #inventoryTable tbody td[data-column="metal"]::before { display: none; }

/* Actions — full-width bottom row */
body.force-card-view #inventoryTable tbody td[data-column="actions"],
body.force-card-view #inventoryTable tbody td.icon-col[data-column="actions"] {
  flex: 0 0 100% !important;
  width: unset !important;
  max-width: none !important;
  justify-content: center;
  padding-top: 0.35rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--border);
}
body.force-card-view #inventoryTable tbody td[data-column="actions"]::before { display: none; }

/* Hide lower-priority fields */
body.force-card-view #inventoryTable tbody td[data-column="date"],
body.force-card-view #inventoryTable tbody td[data-column="type"],
body.force-card-view #inventoryTable tbody td[data-column="purchaseLocation"] {
  display: none !important;
}

/* Override hideEmptyColumns() for visible card fields */
body.force-card-view #inventoryTable tbody td[data-column="name"],
body.force-card-view #inventoryTable tbody td[data-column="metal"],
body.force-card-view #inventoryTable tbody td[data-column="qty"],
body.force-card-view #inventoryTable tbody td[data-column="weight"],
body.force-card-view #inventoryTable tbody td[data-column="purchasePrice"],
body.force-card-view #inventoryTable tbody td[data-column="meltValue"],
body.force-card-view #inventoryTable tbody td[data-column="retailPrice"],
body.force-card-view #inventoryTable tbody td[data-column="gainLoss"],
body.force-card-view #inventoryTable tbody td[data-column="actions"] {
  display: flex !important;
}

/* eBay search SVG icons: hide in card view */
body.force-card-view #inventoryTable tbody td .ebay-search-svg { display: none; }

/* Action row layout inside card */
body.force-card-view #inventoryTable tbody td[data-column="actions"] .actions-row {
  display: flex;
  gap: 1rem;
  justify-content: center;
  width: 100%;
}

/* Touch-friendly action buttons (44px minimum) */
body.force-card-view #inventoryTable tbody td[data-column="actions"] .icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0.4rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

/* View button: primary accent in card view */
body.force-card-view #inventoryTable tbody td[data-column="actions"] .icon-btn.view-icon {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

body.force-card-view #inventoryTable tbody td[data-column="actions"] .icon-btn.view-icon .icon-svg {
  fill: #fff;
}

body.force-card-view #inventoryTable tbody td[data-column="actions"] .icon-svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Cards scroll naturally — remove portal max-height */
body.force-card-view .portal-scroll {
  max-height: none !important;
  overflow: visible;
  -webkit-overflow-scrolling: touch;
}

/* Name cell: name on line 1, chips wrap on line 2 */
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}

body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .filter-text {
  flex: 0 0 100%;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  font-size: 1.05rem;
}

/* Chips: horizontal row, touch-friendly */
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .year-tag,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .numista-tag,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .pcgs-tag,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .grade-tag,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .serial-tag,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .storage-tag,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .notes-indicator,
body.force-card-view #inventoryTable tbody td[data-column="name"] .name-cell-content > .purity-tag {
  flex-shrink: 0;
  font-size: 0.8rem !important;
  padding: 0.2rem 0.5rem !important;
  min-height: 1.75rem;
  display: inline-flex;
  align-items: center;
}

/* Compact pagination footer for card view */
body.force-card-view .table-footer-controls {
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  justify-content: center;
}

body.force-card-view .table-item-count { font-size: 0.85rem; }

body.force-card-view .table-footer-controls select {
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  max-width: 6rem;
}

/* Landscape orientation: 2-column card grid */
@media (max-width: 1350px) and (orientation: landscape) {
  #inventoryTable tbody {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
}

/* =============================================================================
   ITEM PRICE HISTORY — Management UI (STAK-109)
   ============================================================================= */

/* Retail Price field history icon link */
.field-history-link {
  cursor: pointer;
  opacity: 0.5;
  font-size: 0.85em;
  margin-left: 0.25rem;
  transition: opacity 0.2s ease;
  vertical-align: middle;
}
.field-history-link:hover {
  opacity: 1;
}

/* Item Price History modal stacks above the edit modal */
#itemPriceHistoryModal {
  z-index: 10000;
}

/* Delete button in price history tables */
.price-history-delete-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  color: var(--text-secondary, #888);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.15rem 0.45rem;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.price-history-delete-btn:hover {
  color: var(--danger, #dc3545);
  border-color: var(--danger, #dc3545);
  background: rgba(220, 53, 69, 0.08);
}
