@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

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

:root {
  --bg: #fafafa;
  --surface: #fff;
  --border: #e4e4e7;
  --text: #18181b;
  --text-secondary: #71717a;
  --text-tertiary: #a1a1aa;
  --accent: #18181b;
  --accent-hover: #27272a;
  --selected-bg: #f0f4ff;
  --selected-border: #6366f1;
  --danger: #ef4444;
  --danger-border: #fecaca;
  --danger-border-hover: #fca5a5;
  --danger-bg-hover: #fef2f2;
  --hover-bg: #f4f4f5;
  --btn-hover-border: #d4d4d8;
  --focus-ring: rgba(99, 102, 241, 0.1);
  --modal-backdrop: rgba(0, 0, 0, 0.4);
  --shadow-color: rgba(0, 0, 0, 0.15);
  --selected-mix-base: white;
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090b;
    --surface: #18181b;
    --border: #27272a;
    --text: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --accent: #fafafa;
    --accent-hover: #e4e4e7;
    --selected-bg: #1e1b4b;
    --selected-border: #818cf8;
    --danger: #f87171;
    --danger-border: #7f1d1d;
    --danger-border-hover: #991b1b;
    --danger-bg-hover: #1c0a0a;
    --hover-bg: #27272a;
    --btn-hover-border: #3f3f46;
    --focus-ring: rgba(129, 140, 248, 0.2);
    --modal-backdrop: rgba(0, 0, 0, 0.6);
    --shadow-color: rgba(0, 0, 0, 0.4);
    --selected-mix-base: #18181b;
  }
}

[data-theme="dark"] {
  --bg: #09090b;
  --surface: #18181b;
  --border: #27272a;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --accent: #fafafa;
  --accent-hover: #e4e4e7;
  --selected-bg: #1e1b4b;
  --selected-border: #818cf8;
  --danger: #f87171;
  --danger-border: #7f1d1d;
  --danger-border-hover: #991b1b;
  --danger-bg-hover: #1c0a0a;
  --hover-bg: #27272a;
  --btn-hover-border: #3f3f46;
  --focus-ring: rgba(129, 140, 248, 0.2);
  --modal-backdrop: rgba(0, 0, 0, 0.6);
  --shadow-color: rgba(0, 0, 0, 0.4);
  --selected-mix-base: #18181b;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { text-decoration: none; color: inherit; }

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 11;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

header h1 span {
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: 0.15em;
}

nav { display: flex; align-items: center; gap: 1.5rem; }

nav a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: color 0.15s;
}

nav a:hover { color: var(--text); }

/* ── Container ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

#search {
  flex: 1;
  max-width: 360px;
  padding: 0.5rem 0.75rem;
  padding-left: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") 0.6rem center no-repeat;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search::placeholder { color: var(--text-tertiary); }

#search:focus {
  outline: none;
  border-color: var(--selected-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.count {
  color: var(--text-tertiary);
  font-size: 0.8rem;
  margin-left: auto;
}

.sel-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--selected-border);
  background: var(--selected-bg);
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
}

.keyboard-hint {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-family: monospace;
  line-height: 1;
}

/* ── Table ── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex: 1;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

thead th:hover { color: var(--text); }

thead th.sorted-asc::after  { content: ' \2191'; opacity: 0.5; }
thead th.sorted-desc::after { content: ' \2193'; opacity: 0.5; }

/* Numeric columns right-aligned */
thead th:nth-child(n+3):not(:last-child) { text-align: right; }
td:nth-child(n+3):not(:last-child) { text-align: right; }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: var(--hover-bg); }

tbody tr.selected {
  background: color-mix(in srgb, var(--row-color, var(--selected-border)) 10%, var(--selected-mix-base));
}

tbody tr.selected td:first-child {
  box-shadow: inset 3px 0 0 var(--row-color, var(--selected-border));
}

td {
  padding: 0.55rem 0.75rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

td:first-child { font-weight: 500; }

.null { color: var(--text-tertiary); }

td a {
  color: var(--selected-border);
  font-weight: 500;
  font-size: 0.8rem;
  transition: opacity 0.15s;
}

td a:hover { opacity: 0.7; }

/* ── Comparison Panel ── */
.comparison-panel {
  margin-bottom: 1rem;
  animation: slideDown 0.25s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.comparison-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.comparison-images {
  position: relative;
  width: 100%;
  aspect-ratio: 3.5 / 1;
  background: #fff url('/img/grid.svg') center center / 100% auto repeat-y;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.bar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1.75);
}

.bar-no-image {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  text-align: center;
  mix-blend-mode: normal;
}

.comparison-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.comparison-controls label {
  flex-shrink: 0;
}

.comparison-controls input[type="range"] {
  width: 120px;
  accent-color: var(--primary, #6366f1);
}

.comparison-legend { display: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}

.btn:hover {
  background: var(--bg);
  border-color: var(--btn-hover-border);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

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

.btn-secondary {
  color: var(--text-secondary);
}

/* ── Admin ── */
.page-title {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group.wide { grid-column: 1 / -1; }

label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
input[type="url"] {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  outline: none;
  border-color: var(--selected-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: min(560px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px var(--shadow-color);
}

.modal h2 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 4px 12px var(--shadow-color);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Theme Toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: color 0.15s, border-color 0.15s;
  width: 32px;
  height: 32px;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--btn-hover-border);
}

.theme-toggle svg { width: 16px; height: 16px; }


/* ── Print ── */
@media print {
  header, .toolbar, .comparison-panel { display: none; }
  tbody tr { display: none; }
  tbody tr.selected { display: table-row; }
  .table-wrap { border: none; border-radius: 0; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  header { padding: 0 1rem; }
  .container { padding: 1rem; }
  #search { max-width: none; }
  .keyboard-hint { display: none; }
  thead th, td { padding: 0.45rem 0.5rem; }
  td { font-size: 0.8rem; }
  thead th { font-size: 0.7rem; }
}
