:root {
  --color-primary: #1e3a5f;
  --color-primary-light: #2d4a7c;
  --color-primary-dark: #152a42;
  --color-secondary: #2a7f8e;
  --color-secondary-light: #3aa8ba;
  --color-success: #2d7d32;
  --color-warning: #c47800;
  --color-danger: #b71c1c;
  --color-info: #1565c0;
  --status-there: #2d7d32;
  --status-depleted: #b71c1c;
  --status-unknown: #c47800;
  --status-discarded: #546e7a;
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-surface-hover: #f5f5f5;
  --color-border: #e0e0e0;
  --color-border-focus: #1e3a5f;
  --color-text: #1a1a2e;
  --color-text-secondary: #5a5a6e;
  --color-text-muted: #9a9aae;
  --frozen-bg: #f0f4f8;
  --frozen-shadow: 4px 0 8px -4px rgba(0,0,0,0.1);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 22px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.08);
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --header-height: 56px;
  --row-height: 44px;
  --header-row-height: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f1419;
    --color-surface: #1a1f2e;
    --color-surface-hover: #23293a;
    --color-border: #2d3748;
    --color-text: #e8eaed;
    --color-text-secondary: #a0a8b8;
    --color-text-muted: #6a7282;
    --frozen-bg: #151c2a;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { font-family: var(--font-sans); font-size: var(--text-base); line-height: 1.5; color: var(--color-text); background: var(--color-bg); min-height: 100vh; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

.app-header { position: sticky; top: 0; z-index: 100; height: var(--header-height); background: var(--color-surface); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; padding: 0 var(--space-md); gap: var(--space-md); box-shadow: var(--shadow-sm); }
.header-left { display: flex; align-items: center; gap: var(--space-sm); }
.logo-icon { width: 28px; height: 28px; color: var(--color-primary); flex-shrink: 0; }
.app-title { font-size: var(--text-xl); font-weight: 600; color: var(--color-text); white-space: nowrap; }
.main-nav { display: flex; gap: var(--space-xs); }
.nav-btn { padding: var(--space-xs) var(--space-md); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: 500; color: var(--color-text-secondary); background: transparent; transition: all var(--transition-fast); white-space: nowrap; }
.nav-btn:hover { color: var(--color-primary); background: var(--color-surface-hover); }
.nav-btn.active { color: var(--color-primary); background: rgba(30,58,95,0.1); }
.header-right { display: flex; align-items: center; gap: var(--space-sm); }
.user-badge { font-size: var(--text-sm); color: var(--color-text-secondary); white-space: nowrap; }
.icon-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-md); color: var(--color-text-secondary); transition: all var(--transition-fast); }
.icon-btn:hover { color: var(--color-primary); background: var(--color-surface-hover); }
.icon-btn svg { width: 20px; height: 20px; }

.app-main { flex: 1; padding: var(--space-md); max-width: 100%; overflow-x: auto; }

.view { animation: fadeIn var(--transition-base); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.view-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-md); margin-bottom: var(--space-md); }
.view-header h2 { font-size: var(--text-xl); font-weight: 600; }
.header-actions { display: flex; gap: var(--space-sm); }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-md); align-items: center; margin-bottom: var(--space-md); padding: var(--space-md); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.search-wrapper { position: relative; flex: 1; min-width: 200px; max-width: 400px; }
.search-icon { position: absolute; left: var(--space-md); top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--color-text-muted); pointer-events: none; }
.search-wrapper input { width: 100%; padding: var(--space-sm) var(--space-md) var(--space-sm) 44px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg); color: var(--color-text); font-size: var(--text-sm); transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
.search-wrapper input:focus { outline: none; border-color: var(--color-border-focus); box-shadow: 0 0 0 3px rgba(30,58,95,0.15); }
.search-loading { position: absolute; right: var(--space-md); top: 50%; transform: translateY(-50%); color: var(--color-primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

.multi-select-toolbar { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-sm) var(--space-md); background: rgba(30,58,95,0.1); border-radius: var(--radius-md); border: 1px solid rgba(30,58,95,0.2); }
.selection-count { font-weight: 500; color: var(--color-primary); font-size: var(--text-sm); }
.bulk-actions { display: flex; gap: var(--space-xs); }
.export-buttons { display: flex; gap: var(--space-sm); }

.filter-chips { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-bottom: var(--space-md); min-height: 28px; }
.filter-chip { display: inline-flex; align-items: center; gap: var(--space-xs); padding: var(--space-xs) var(--space-sm); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: var(--text-xs); color: var(--color-text-secondary); }
.filter-chip button { padding: 0; margin-left: var(--space-xs); color: inherit; }
.filter-chip button:hover { color: var(--color-danger); }

.table-container { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; position: relative; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table thead { position: sticky; top: var(--header-height); z-index: 10; background: var(--color-surface); }
.data-table th { padding: var(--space-sm) var(--space-md); text-align: left; font-weight: 600; color: var(--color-text-secondary); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 2px solid var(--color-border); white-space: nowrap; user-select: none; }
.data-table th.frozen { position: sticky; left: 0; z-index: 20; background: var(--frozen-bg); box-shadow: var(--frozen-shadow); }
.data-table th.frozen:first-child { left: 0; z-index: 21; }
.data-table td { padding: var(--space-sm) var(--space-md); border-bottom: 1px solid var(--color-border); vertical-align: middle; white-space: nowrap; }
.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: var(--color-surface-hover); }
.data-table tbody tr.selected { background: rgba(30,58,95,0.08); border-left: 3px solid var(--color-primary); }
.data-table tbody tr:nth-child(even) { background: rgba(30,58,95,0.02); }
.data-table td.frozen { position: sticky; left: 0; z-index: 15; background: var(--frozen-bg); box-shadow: var(--frozen-shadow); }
.data-table td.frozen:first-child { left: 0; z-index: 16; }
.data-table .checkbox-cell { width: 40px; text-align: center; padding: 0; }
.data-table .checkbox-cell input { width: 18px; height: 18px; accent-color: var(--color-primary); cursor: pointer; }
.data-table .status-badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: var(--text-xs); font-weight: 500; text-transform: capitalize; }
.data-table .status-there { background: rgba(45,125,50,0.15); color: var(--status-there); }
.data-table .status-depleted { background: rgba(183,28,28,0.15); color: var(--status-depleted); }
.data-table .status-unknown { background: rgba(196,120,0,0.15); color: var(--color-warning); }
.data-table .status-discarded { background: rgba(84,110,122,0.15); color: var(--status-discarded); }
.data-table .cell-actions { display: flex; gap: var(--space-xs); }
.data-table .cell-actions .icon-btn { width: 28px; height: 28px; padding: 0; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-xl) var(--space-md); text-align: center; color: var(--color-text-muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: var(--space-md); opacity: 0.5; }
.empty-state p { font-size: var(--text-base); }

.pagination { display: flex; align-items: center; justify-content: center; gap: var(--space-sm); padding: var(--space-md); }
.pagination button { padding: var(--space-xs) var(--space-md); border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); font-size: var(--text-sm); transition: all var(--transition-fast); }
.pagination button:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.active { background: var(--color-primary); border-color: var(--color-primary); color: white; }
.pagination .page-info { font-size: var(--text-sm); color: var(--color-text-secondary); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs); padding: var(--space-sm) var(--space-md); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: 500; white-space: nowrap; transition: all var(--transition-fast); border: 1px solid transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-light); border-color: var(--color-primary-light); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover:not(:disabled) { background: var(--color-surface-hover); border-color: var(--color-primary); color: var(--color-primary); }
.btn-danger { background: var(--color-danger); color: white; border-color: var(--color-danger); }
.btn-danger:hover:not(:disabled) { background: #c62828; border-color: #c62828; }
.btn-ghost { background: transparent; color: var(--color-text-secondary); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--color-surface-hover); color: var(--color-primary); }
.btn-block { width: 100%; }
.btn-sm { padding: var(--space-xs) var(--space-sm); font-size: var(--text-xs); }

.form-group { margin-bottom: var(--space-md); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { display: block; margin-bottom: var(--space-xs); font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: var(--space-sm) var(--space-md); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); color: var(--color-text); font-size: var(--text-sm); transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--color-border-focus); box-shadow: 0 0 0 3px rgba(30,58,95,0.15); }
.form-group input::placeholder { color: var(--color-text-muted); }
.form-group input[readonly] { background: var(--color-bg); color: var(--color-text-secondary); }
.form-group select { cursor: pointer; }
.form-group textarea { resize: vertical; min-height: 60px; }
.form-hint { margin-top: var(--space-xs); font-size: var(--text-xs); color: var(--color-text-muted); }
.form-actions { display: flex; justify-content: flex-end; gap: var(--space-sm); margin-top: var(--space-lg); padding-top: var(--space-md); border-top: 1px solid var(--color-border); }
.password-wrapper { position: relative; }
.password-wrapper .toggle-visibility { position: absolute; right: var(--space-sm); top: 50%; transform: translateY(-50%); padding: var(--space-xs); color: var(--color-text-muted); }
.password-wrapper input { padding-right: 44px; }
.checkbox-label { display: flex; align-items: center; gap: var(--space-sm); cursor: pointer; font-weight: 400; }
.checkbox-label input { width: 18px; height: 18px; accent-color: var(--color-primary); }

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-md); }
.login-card { width: 100%; max-width: 400px; padding: var(--space-xl); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); text-align: center; }
.login-icon { width: 56px; height: 56px; color: var(--color-primary); margin: 0 auto var(--space-md); }
.login-card h1 { font-size: var(--text-2xl); font-weight: 700; margin-bottom: var(--space-xs); }
.login-subtitle { color: var(--color-text-secondary); margin-bottom: var(--space-lg); }
.login-hint { margin-top: var(--space-lg); font-size: var(--text-sm); color: var(--text-muted); text-align: center; }

.columns-hint, .credentials-hint { font-size: var(--text-sm); color: var(--color-text-secondary); margin-bottom: var(--space-md); }
.columns-table-container { overflow-x: auto; }
.columns-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.columns-table th, .columns-table td { padding: var(--space-sm) var(--space-md); text-align: left; border-bottom: 1px solid var(--color-border); }
.columns-table th { font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; color: var(--color-text-secondary); }
.columns-table tbody tr:hover { background: var(--color-surface-hover); }
.columns-table .drag-handle { cursor: grab; color: var(--color-text-muted); }
.columns-table .drag-handle:active { cursor: grabbing; }
.columns-table .toggle-switch { position: relative; width: 44px; height: 24px; }
.columns-table .toggle-switch input { opacity: 0; width: 0; height: 0; }
.columns-table .toggle-switch .slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: var(--color-border); border-radius: 999px; transition: var(--transition-fast); }
.columns-table .toggle-switch .slider::before { content: ''; position: absolute; left: 2px; top: 2px; width: 20px; height: 20px; background: white; border-radius: 50%; box-shadow: var(--shadow-sm); transition: var(--transition-fast); }
.columns-table .toggle-switch input:checked + .slider { background: var(--color-primary); }
.columns-table .toggle-switch input:checked + .slider::before { transform: translateX(20px); }
.columns-actions { display: flex; justify-content: flex-end; gap: var(--space-sm); margin-top: var(--space-md); padding-top: var(--space-md); border-top: 1px solid var(--color-border); }

.audit-filters { display: flex; gap: var(--space-sm); flex-wrap: wrap; }
.audit-filters select, .audit-filters input { padding: var(--space-xs) var(--space-md); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); color: var(--color-text); font-size: var(--text-sm); }

.toast-container { position: fixed; bottom: var(--space-lg); right: var(--space-lg); z-index: 1000; display: flex; flex-direction: column; gap: var(--space-sm); max-width: 360px; }
.toast { display: flex; align-items: flex-start; gap: var(--space-sm); padding: var(--space-md); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); animation: slideIn var(--transition-base); }
.toast.success { border-left: 4px solid var(--color-success); }
.toast.error { border-left: 4px solid var(--color-danger); }
.toast.warning { border-left: 4px solid var(--color-warning); }
.toast svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 2px; }
.toast.success svg { color: var(--color-success); }
.toast.error svg { color: var(--color-danger); }
.toast.warning svg { color: var(--color-warning); }
.toast-content { flex: 1; font-size: var(--text-sm); }
.toast-close { color: var(--color-text-muted); padding: 0; }
@keyframes slideIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

.modal-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; padding: var(--space-md); opacity: 0; visibility: hidden; transition: opacity var(--transition-base), visibility var(--transition-base); }
.modal-overlay:not([hidden]) { opacity: 1; visibility: visible; }
.modal { width: 100%; max-width: 720px; max-height: 85vh; background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; transform: scale(0.95); transition: transform var(--transition-base); }
.modal-overlay:not([hidden]) .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-md) var(--space-lg); border-bottom: 1px solid var(--color-border); }
.modal-header h3 { font-size: var(--text-lg); font-weight: 600; }
.modal-body { padding: var(--space-lg); overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--space-sm); padding: var(--space-md) var(--space-lg); border-top: 1px solid var(--color-border); background: var(--color-bg); }

.detail-card { display: flex; flex-direction: column; gap: var(--space-lg); }
.detail-section h4 { font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-secondary); margin-bottom: var(--space-sm); padding-bottom: var(--space-xs); border-bottom: 1px solid var(--color-border); }
.detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-sm) var(--space-md); font-size: var(--text-sm); }
.detail-grid dt { color: var(--color-text-secondary); font-weight: 500; }
.detail-grid dd { color: var(--color-text); word-break: break-word; }
.detail-grid dd.empty { color: var(--color-text-muted); font-style: italic; }

.editor-sections { display: flex; flex-direction: column; gap: var(--space-lg); }
.editor-section { padding: var(--space-md); background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.editor-section h4 { font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-secondary); margin-bottom: var(--space-md); padding-bottom: var(--space-sm); border-bottom: 1px solid var(--color-border); }

@media (min-width: 768px) {
  .editor-sections { flex-direction: row; flex-wrap: wrap; }
  .editor-section { flex: 1; min-width: 300px; }
  .editor-section[data-section="basic"] { flex-basis: 100%; }
  .editor-section[data-section="dates"] { flex-basis: 100%; }
}

@media (max-width: 767px) {
  .form-row { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-wrapper { max-width: none; }
  .multi-select-toolbar { flex-wrap: wrap; }
  .bulk-actions { flex: 1; display: flex; flex-wrap: wrap; gap: var(--space-xs); }
  .bulk-actions .btn { flex: 1; min-width: 120px; justify-content: center; }
  .export-buttons { justify-content: flex-end; }
  .view-header { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; justify-content: space-between; }
  .header-actions .btn { flex: 1; justify-content: center; }
}

@media (max-width: 480px) {
  .app-header { padding: 0 var(--space-sm); }
  .app-title { font-size: var(--text-lg); }
  .main-nav { overflow-x: auto; flex-wrap: nowrap; padding-bottom: var(--space-xs); }
  .nav-btn { padding: var(--space-xs) var(--space-sm); font-size: var(--text-xs); }
  .app-main { padding: var(--space-sm); }
  .modal { max-width: 100%; max-height: 100vh; border-radius: 0; margin: 0; height: 100vh; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-overlay:not([hidden]) .modal { transform: translateY(0); }
  .modal { transform: translateY(100%); }
}