/* =====================================================
   OpenAlex Search – Stylesheet
   ===================================================== */

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

:root {
  --primary:       #2563EB;
  --primary-hover: #1D4ED8;
  --primary-light: #EFF6FF;
  --accent:        #7C3AED;
  --success:       #059669;
  --warning:       #D97706;
  --danger:        #DC2626;

  --bg:            #F1F5F9;
  --surface:       #FFFFFF;
  --border:        #E2E8F0;
  --border-dark:   #CBD5E1;

  --text:          #0F172A;
  --text-muted:    #64748B;
  --text-light:    #94A3B8;

  --sidebar-w:     300px;
  --header-h:      56px;
  --tabs-h:        46px;
  --radius:        8px;
  --radius-sm:     4px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.header-logo svg { opacity: .9; }

.header-tagline {
  margin-left: auto;
  font-size: 12px;
  opacity: .75;
}

.header-tagline a { color: #fff; text-decoration: none; }

/* ── Entity Tabs ─────────────────────────────────────── */
.entity-tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 20px;
  gap: 2px;
  position: sticky;
  top: var(--header-h);
  z-index: 99;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.tab-btn {
  height: var(--tabs-h);
  padding: 0 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--primary); }

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Layout ──────────────────────────────────────────── */
.main-content {
  display: flex;
  height: calc(100vh - var(--header-h) - var(--tabs-h));
  overflow: hidden;
}

/* ── Filter Sidebar ──────────────────────────────────── */
.filter-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h2 { font-size: 14px; font-weight: 600; }

.btn-clear-filters {
  font-size: 12px;
  color: var(--danger);
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.btn-clear-filters:hover { background: #FEF2F2; }

.filter-body { flex: 1; overflow-y: auto; padding: 8px 0; }

/* Filter Groups */
.filter-group {
  border-bottom: 1px solid var(--border);
}

.filter-group-header {
  width: 100%;
  background: none;
  border: none;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  transition: background .15s;
}
.filter-group-header:hover { background: var(--bg); }

.filter-group-header .chevron {
  transition: transform .2s;
  font-size: 10px;
}
.filter-group-header.open .chevron { transform: rotate(180deg); }

.filter-group-body {
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.filter-group-body.collapsed { display: none; }

/* Filter Controls */
.filter-field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.filter-field input[type="text"],
.filter-field input[type="number"],
.filter-field select {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

.filter-row { display: flex; gap: 6px; }
.filter-row .filter-field { flex: 1; }
.filter-row label { font-size: 10px; }

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.filter-checkbox input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--primary);
}
.filter-checkbox span { font-size: 13px; cursor: pointer; }

.btn-apply-filters {
  width: calc(100% - 24px);
  margin: 8px 12px;
  height: 34px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-apply-filters:hover { background: var(--primary-hover); }

/* ── Results Area ────────────────────────────────────── */
.results-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-bar-wrapper {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
#search-input::placeholder { color: var(--text-light); }

.btn-search {
  height: 38px;
  padding: 0 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-search:hover { background: var(--primary-hover); }

/* Controls Bar */
.controls-bar {
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.results-count { font-size: 13px; color: var(--text-muted); margin-right: auto; }
.results-count strong { color: var(--text); font-weight: 600; }

.controls-right { display: flex; align-items: center; gap: 8px; }

.controls-right select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  cursor: pointer;
}
.controls-right select:focus { border-color: var(--primary); }

.btn-export {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, border-color .15s;
}
.btn-export:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-export.csv:hover { border-color: var(--success); color: var(--success); }
.btn-export.excel:hover { border-color: #217346; color: #217346; }

/* Table */
.table-wrapper {
  flex: 1;
  overflow: auto;
}

#results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#results-table thead { position: sticky; top: 0; z-index: 10; }

#results-table th {
  background: #1E3A5F;
  color: #fff;
  font-weight: 600;
  font-size: 12px;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.1);
  cursor: pointer;
  user-select: none;
}
#results-table th:hover { background: #254975; }
#results-table th.sortable::after {
  content: ' ↕';
  opacity: .4;
  font-size: 10px;
}
#results-table th.sort-asc::after { content: ' ↑'; opacity: 1; }
#results-table th.sort-desc::after { content: ' ↓'; opacity: 1; }

#results-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#results-table td.wrap {
  white-space: normal;
  min-width: 280px;
  max-width: 440px;
  line-height: 1.5;
  word-break: break-word;
  vertical-align: middle;
}

#results-table td.wrap .cell-link,
#results-table td.wrap span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#results-table tr:hover td { background: var(--primary-light); }
#results-table tr:nth-child(even) td { background: #F8FAFC; }
#results-table tr:nth-child(even):hover td { background: var(--primary-light); }

.cell-link { color: var(--primary); text-decoration: none; }
.cell-link:hover { text-decoration: underline; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-blue   { background: #DBEAFE; color: #1D4ED8; }
.badge-green  { background: #D1FAE5; color: #065F46; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-gray   { background: #F1F5F9; color: #475569; }
.badge-purple { background: #EDE9FE; color: #5B21B6; }

/* Pagination */
.pagination-wrapper {
  flex-shrink: 0;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pagination-info { font-size: 12px; color: var(--text-muted); }

.pagination-controls { display: flex; gap: 4px; align-items: center; }

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.page-btn:hover:not(:disabled) { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-dots { padding: 0 4px; color: var(--text-muted); }

/* States */
.state-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  padding: 40px;
  text-align: center;
}
.state-icon { font-size: 48px; opacity: .5; }
.state-title { font-size: 16px; font-weight: 600; color: var(--text); }
.state-msg { font-size: 13px; max-width: 360px; line-height: 1.6; }

/* Loading spinner */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Per-page select wrapper */
.per-page-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  animation: slideIn .3s ease;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger);  }

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }
