:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --success: #138a5b;
  --warning: #b7791f;
  --danger: #c24135;
  --shadow: 0 16px 38px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px;
  background: #111827;
  color: #f8fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f8fafc;
  color: #111827;
  font-weight: 900;
}

.brand strong,
.brand span,
.connection-card span,
.connection-card small {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand span {
  margin-top: 2px;
  color: #aeb7c6;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d7deea;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: #1f2937;
  border-color: #344055;
  color: #ffffff;
}

.connection-card {
  margin-top: auto;
  min-height: 66px;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid #344055;
  border-radius: 8px;
  background: #182230;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--danger);
}

.connection-dot.online {
  background: var(--success);
}

.connection-card span {
  font-size: 13px;
  font-weight: 700;
}

.connection-card small {
  max-width: 170px;
  overflow: hidden;
  color: #aeb7c6;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

.topbar-actions,
.drawer-actions,
.pagination,
.records-toolbar,
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.primary-button,
.ghost-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  text-decoration: none;
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
}

.icon-button.small {
  width: 34px;
  min-height: 34px;
}

.primary-button {
  padding: 0 14px;
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.ghost-button {
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 750;
}

.ghost-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

i[data-lucide] {
  width: 17px;
  height: 17px;
  stroke-width: 2.2;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  min-height: 96px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.stat-card strong {
  display: block;
  margin-top: 12px;
  font-size: 27px;
  line-height: 1;
}

.vault-layout {
  display: grid;
  grid-template-columns: 260px minmax(320px, 0.9fr) minmax(420px, 1.35fr);
  gap: 14px;
  min-height: calc(100vh - 210px);
}

.category-panel,
.records-panel,
.reader-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.category-panel,
.records-panel {
  display: flex;
  flex-direction: column;
}

.panel-header {
  justify-content: space-between;
  min-height: 58px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.category-list {
  overflow: auto;
  padding: 10px;
}

.category-item {
  width: 100%;
  min-height: 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.category-item:hover,
.category-item.active {
  border-color: #bed2f7;
  background: #eff6ff;
}

.category-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-count {
  color: var(--muted);
  font-size: 12px;
}

.records-toolbar {
  min-height: 58px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  min-width: 0;
  flex: 1;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

select {
  height: 38px;
  max-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.active-filter {
  min-height: 38px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.record-list {
  flex: 1;
  overflow: auto;
  padding: 10px;
}

.record-item {
  width: 100%;
  min-height: 112px;
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.record-item:hover,
.record-item.active {
  border-color: #9abaf2;
  background: #f7fbff;
}

.record-title {
  display: -webkit-box;
  overflow: hidden;
  font-weight: 850;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.record-meta,
.record-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.record-badge {
  max-width: 100%;
  overflow: hidden;
  padding: 3px 7px;
  border-radius: 6px;
  background: #edf2f7;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pagination {
  justify-content: space-between;
  min-height: 58px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.pagination span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.reader-panel {
  position: relative;
  overflow: hidden;
  background: var(--surface);
}

.reader-empty,
.empty-state {
  height: 100%;
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}

.reader-empty i,
.empty-state i {
  width: 34px;
  height: 34px;
}

.reader-empty strong,
.empty-state strong {
  color: var(--text);
}

.reader-detail {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.reader-head {
  min-height: 116px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.reader-category {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  margin-bottom: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #e8f2ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-head h2 {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.reader-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

iframe {
  width: 100%;
  height: 100%;
  min-height: 520px;
  border: 0;
  background: #ffffff;
}

.settings-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
}

.drawer-backdrop {
  background: rgba(15, 23, 42, 0.36);
}

.drawer-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.form-field {
  display: grid;
  gap: 8px;
}

.form-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.form-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.drawer-actions {
  justify-content: flex-end;
  margin-top: 4px;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.loading {
  opacity: 0.62;
  pointer-events: none;
}

@media (max-width: 1380px) {
  .vault-layout {
    grid-template-columns: 220px minmax(320px, 1fr);
  }

  .reader-panel {
    grid-column: 1 / -1;
    min-height: 620px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .connection-card {
    margin-top: 0;
  }

  .workspace {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid,
  .vault-layout {
    grid-template-columns: 1fr;
  }

  .records-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  select {
    max-width: none;
    width: 100%;
  }

  .settings-drawer {
    grid-template-columns: 1fr;
  }

  .drawer-backdrop {
    display: none;
  }
}
