:root {
  --bg: linear-gradient(135deg, #0f172a, #0b2e44);
  --card: #0f1f34;
  --accent: #00c2a8;
  --text: #e4ebf5;
  --muted: #9ab0c9;
  --border: #1f334c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  padding: 1.5rem;
}

h1, h2 { margin: 0 0 0.5rem 0; }
h3 { margin: 0.2rem 0 0.4rem 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 1.25rem;
}

.muted { color: var(--muted); margin: 0; }

.pill {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.pill.error {
  background: #3d0b14;
  border-color: #d85c6b;
  color: #ffd7dc;
}

.token-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  width: auto;
  padding: 0.55rem 0.9rem;
  margin: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
}

.tab.active {
  background: var(--accent);
  color: #0b1a2c;
  border-color: transparent;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

label {
  display: block;
  font-weight: 600;
  margin: 0.6rem 0 0.25rem;
}

input, select, button, textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1rem;
}
textarea { resize: vertical; }

/* Ensure dropdown text stays readable on native menus */
select option {
  color: #0f1f34;
  background: #ffffff;
}
select option:disabled {
  color: #8b9bb0;
}

button {
  margin-top: 0.75rem;
  background: var(--accent);
  color: #0b1a2c;
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

button:hover { transform: translateY(-1px); box-shadow: 0 5px 20px rgba(0, 194, 168, 0.35); }
button:active { transform: translateY(0); }

.hint { color: var(--muted); font-size: 0.9rem; }

.stack { display: flex; flex-direction: column; gap: 0.35rem; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.inline {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.5rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

#companyList {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.company-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 600;
}

.company-pill button {
  width: auto;
  margin: 0;
  padding: 0.4rem 0.65rem;
  font-size: 0.9rem;
}

#status { margin-top: 0.5rem; min-height: 1.4rem; color: var(--muted); }

.table-wrapper {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th, td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

thead { background: rgba(255, 255, 255, 0.04); }

tbody tr:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }

#documentsTable th[data-sort-key] {
  position: relative;
  padding-right: 1.6rem;
  cursor: pointer;
  user-select: none;
}

#documentsTable th.sort-active {
  color: var(--accent);
}

#documentsTable th[data-sort-key]::after {
  content: '';
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  opacity: 0;
  transition: opacity 0.12s ease, border-color 0.12s ease;
}

#documentsTable th.sort-asc::after {
  opacity: 1;
  border-bottom: 0;
  border-top: 8px solid var(--accent);
}

#documentsTable th.sort-desc::after {
  opacity: 1;
  border-top: 0;
  border-bottom: 8px solid var(--accent);
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  background: rgba(0, 194, 168, 0.15);
  border: 1px solid rgba(0, 194, 168, 0.4);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.settings-block {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.02);
}

.hidden { display: none; }

.inline-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.inline-actions button {
  width: auto;
  margin: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  body { padding: 1rem; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .token-area { width: 100%; justify-content: space-between; }
  .filters { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
}
