:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cbd1db;
  --text: #1a1d23;
  --text-muted: #667085;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff4ff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.25rem;
  letter-spacing: -0.01em;
}
h2 { font-weight: 600; letter-spacing: -0.01em; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  margin-right: 1.5rem;
  color: var(--text);
}
.topbar .brand::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 3px;
  background: var(--primary);
  display: inline-block;
}
.topbar-left { display: flex; align-items: center; }
.topbar nav { display: flex; gap: 0.25rem; }
.topbar nav a {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--primary-soft); color: var(--primary); }

.logout-form { display: flex; align-items: center; gap: 0.75rem; }
.logout-form span { color: var(--text-muted); font-size: 0.9rem; }
.logout-form button {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
}
.logout-form button:hover { background: var(--bg); color: var(--text); }

main { padding: 2rem 1.5rem 4rem; max-width: 1100px; margin: 0 auto; }

/* ---------- Login ---------- */
.login-box {
  max-width: 360px;
  margin: 10vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
.login-box h1 { text-align: center; margin-bottom: 1.5rem; }
.login-box form { display: flex; flex-direction: column; gap: 1rem; }
.login-box label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
.login-box button { margin-top: 0.25rem; padding: 0.65rem 1rem; }

/* ---------- Panels / cards ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; }

/* ---------- Forms ---------- */
textarea {
  width: 100%;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.88rem;
  padding: 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
}
textarea:focus, input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.hint {
  color: var(--text-muted);
  font-size: 0.88rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.hint code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.85em;
}

.error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fda29b;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
}

.form-actions { margin-top: 1rem; display: flex; justify-content: flex-end; }

/* ---------- Entries (results) ---------- */
.batch-meta { color: var(--text-muted); font-size: 0.9rem; margin: -0.75rem 0 1.5rem; }

.entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.entry h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.entry h2 .index { color: var(--text-muted); font-weight: 500; }
.entry h2 .entry-download {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
}
.inn-line { margin: 0 0 0.25rem; font-size: 0.92rem; }
.company-meta { margin: 0 0 0.75rem; color: var(--text-muted); font-size: 0.85rem; }

.entry table { margin-top: 0.75rem; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.entry table { border: none; }
th, td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); }
thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tr.current td { font-weight: 600; }
tr.current td:first-child { position: relative; }
tr.current td:first-child::before {
  content: "";
  position: absolute;
  left: -1px; top: 0; bottom: 0;
  width: 3px;
  background: var(--success);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  vertical-align: middle;
}
.badge.status-active { color: var(--success); border-color: #a6e9bd; background: var(--success-soft); }
.badge.alert { color: var(--danger); border-color: #fda29b; background: var(--danger-soft); }

.name-match { color: var(--danger); font-weight: 700; }

/* ---------- Buttons & inputs ---------- */
button, .button {
  cursor: pointer;
  border: none;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  transition: background 0.15s ease;
}
button:hover, .button:hover { background: var(--primary-hover); }
button:active, .button:active { background: #1e40af; }

input {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 0.92rem;
  background: var(--surface);
  color: var(--text);
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

@media (max-width: 640px) {
  main { padding: 1.25rem 1rem 3rem; }
  .topbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; }
  .entry { padding: 1rem; }
}
