/* ==========================================================================
   Telegram Topic Study Hub — Design System & Responsive Stylesheet
   Tailored for MacBook Air (13/15") & Mobile Viewports
   ========================================================================== */

:root {
  /* Ultra-Premium Pure Black / AMOLED / Vantablack Theme */
  --bg-main: #000000;
  --bg-surface: #0a0a0a;
  --bg-surface-elevated: #121212;
  --bg-surface-hover: #1c1c1c;
  --bg-glass: rgba(10, 10, 10, 0.90);
  
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-focus: #ffffff;
  --border-hover: rgba(255, 255, 255, 0.22);

  --text-primary: #f5f5f5;
  --text-secondary: #a3a3a3;
  --text-muted: #666666;
  
  --accent-primary: #ffffff;
  --accent-primary-hover: #e5e5e5;
  --accent-primary-subtle: rgba(255, 255, 255, 0.10);
  --accent-text: #000000;

  /* Subject Accent Colors (Crisp, High-Contrast Jewel Tones) */
  --subject-physics: #38bdf8;
  --subject-physics-bg: rgba(56, 189, 248, 0.12);
  --subject-chemistry: #34d399;
  --subject-chemistry-bg: rgba(52, 211, 153, 0.12);
  --subject-botany: #a3e635;
  --subject-botany-bg: rgba(163, 230, 53, 0.12);
  --subject-biology: #f43f5e;
  --subject-biology-bg: rgba(244, 63, 94, 0.12);
  --subject-general: #e5e5e5;
  --subject-general-bg: rgba(255, 255, 255, 0.10);

  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-error: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.85);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.95);

  --sidebar-width: 280px;
  --header-height: 68px;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="light"] {
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  --bg-glass: rgba(255, 255, 255, 0.85);
  
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-focus: #4f46e5;
  --border-hover: rgba(0, 0, 0, 0.15);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-primary-subtle: rgba(79, 70, 229, 0.1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  max-width: 100vw;
  font-family: var(--font-body);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overflow-y: hidden;
}

/* App Container Layout */
.app-container {
  display: flex;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  overflow-y: hidden;
  position: relative;
}

/* ==========================================================================
   Sidebar Navigation (Desktop & Mobile Drawer)
   ========================================================================== */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  scrollbar-gutter: stable;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

.brand-text h2 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stats-overview {
  padding: 0.9rem 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  background: var(--bg-surface-elevated);
  margin: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.stat-pill {
  display: flex;
  flex-direction: column;
}

.stat-val {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.stat-lbl {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-section-title {
  padding: 0.8rem 1.25rem 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.refresh-topics-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

.refresh-topics-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.topics-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.topic-item-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease-in-out;
}

.topic-item-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.topic-item-btn.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  color: var(--text-primary);
  font-weight: 600;
}

.topic-item-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  overflow: hidden;
}

.topic-emoji-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.topic-title-span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-badge-count {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-weight: 600;
}

.topic-item-btn.active .topic-badge-count {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

/* Sidebar Footer & Status */
.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.2s;
}

.connection-status:hover {
  background: var(--bg-surface-hover);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--color-success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.status-dot.disconnected {
  background: var(--color-warning);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}

.status-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.status-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
}

.status-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */

.main-content {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  background: var(--bg-main);
}

/* Top Header Bar */
.top-header {
  height: var(--header-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 50;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex-shrink: 0;
}

.topic-tag-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.88rem;
  font-weight: 600;
  min-width: 0;
}

.topic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  flex-shrink: 0;
}

/* Search Input */
.header-search {
  flex: 1 1 auto;
  max-width: 580px;
  min-width: 0;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrapper input {
  width: 100%;
  min-width: 0;
  padding: 0.65rem 2.5rem 0.65rem 2.65rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.2s ease;
  outline: none;
}

.search-input-wrapper input:focus {
  border-color: var(--border-focus);
  background: var(--bg-surface-elevated);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.search-kbd {
  position: absolute;
  right: 12px;
  padding: 2px 6px;
  font-size: 0.72rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: monospace;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
  text-decoration: none;
}

.sync-btn {
  background: #ffffff;
  color: #000000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  font-weight: 600;
}

.sync-btn:hover {
  background: #e5e5e5;
  color: #000000;
  transform: translateY(-1px);
}

.sync-btn.spinning .sync-icon,
.refresh-topics-btn.spinning svg {
  animation: spin 1s linear infinite;
}

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.icon-btn-small {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.icon-btn-small:hover {
  color: var(--text-primary);
}

.mobile-menu-btn {
  display: none;
}

/* Controls Bar (Filter Tabs & Sorting) */
.controls-bar {
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.filter-tabs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
  flex: 1 1 auto;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.tab-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-surface-elevated);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  font-weight: 600;
}

.tab-count {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--bg-surface-hover);
  color: var(--text-muted);
}

.tab-btn.active .tab-count {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.toggle-control-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.toggle-control-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.toggle-control-btn.active {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
  font-weight: 600;
}

.sort-select-wrapper select {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

/* Sync Banner */
.sync-banner {
  padding: 0.65rem 1.25rem;
  background: #111111;
  border-bottom: 1px solid #222222;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.sync-banner-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sync-banner-detail {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

/* ==========================================================================
   Materials Feed & Card Grid
   ========================================================================== */

.feed-section {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scrollbar-gutter: stable;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 1.25rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Material Card */
.material-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s, box-shadow 0.2s;
  position: relative;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.material-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

.card-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  max-width: 100%;
}

.card-topic-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* PDF & File Content */
.file-card-preview {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.file-icon-box {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-icon-box.doc {
  background: rgba(255, 255, 255, 0.08);
  color: #f5f5f5;
}

.file-info-col {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.file-name-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
  max-width: 100%;
}

.file-name-text {
  flex: 1 1 0%;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  line-height: 1.35;
  transition: color 0.15s ease;
  min-width: 0;
}

.file-name-text:hover {
  color: #ffffff;
}

.file-name-text.expanded,
.expand-all-filenames .file-name-text {
  white-space: normal;
  word-break: break-word;
  overflow: visible;
  text-overflow: unset;
}

.filename-toggle-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: 4px;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
  padding: 0;
  margin-top: 1px;
}

.filename-toggle-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.filename-toggle-btn.active,
.expand-all-filenames .filename-toggle-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
}

.file-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Question & Note Content */
.question-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
  width: fit-content;
}

.note-text-snippet {
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 140px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Service Action / Topic Activity Cards */
.service-action-banner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  min-width: 0;
  max-width: 100%;
}

.service-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.service-action-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}

.service-action-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.service-action-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Link Cards */
.link-items-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
  max-width: 100%;
}

.link-item-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  text-decoration: none;
  transition: all 0.15s ease;
  min-width: 0;
  max-width: 100%;
}

.link-item-row:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
}

.link-item-icon {
  color: #ffffff;
  flex-shrink: 0;
}

.link-item-title {
  flex: 1 1 0%;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.link-item-domain {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Card Actions */
.card-actions-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.85rem;
  min-width: 0;
  max-width: 100%;
}

.btn-preview {
  background: #141414;
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.btn-preview:hover {
  background: #222222;
  border-color: rgba(255, 255, 255, 0.28);
}

.btn-download {
  background: #ffffff;
  color: #000000;
  font-weight: 600;
  border: 1px solid #ffffff;
}

.btn-download:hover {
  background: #e5e5e5;
  border-color: #e5e5e5;
  color: #000000;
}

.btn-copy {
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-secondary);
}

.btn-copy:hover {
  background: #222222;
  color: #ffffff;
}

/* Pagination */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  padding: 1rem 0 2rem;
}

.load-more-btn {
  padding: 0.75rem 2rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.load-more-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  padding: 4rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-state h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 420px;
}

/* ==========================================================================
   Modals & Overlays
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  display: none;
  opacity: 0;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  width: 100%;
  overflow: hidden;
  animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  overflow: hidden;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

/* PDF Modal Specifics (Tailored for MacBook Air) */
.pdf-dialog {
  max-width: 1100px;
  height: 88vh;
}

.pdf-tag-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pdf-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pdf-modal-filename {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-modal-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.pdf-viewer-body {
  flex: 1;
  padding: 0;
  position: relative;
  background: #1e1e1e;
  display: flex;
  flex-direction: column;
}

.pdf-viewer-frame {
  width: 100%;
  height: 100%;
  border: none;
}

.pdf-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.9rem;
  z-index: 10;
}

/* Settings / Sync Modal */
.settings-dialog {
  max-width: 540px;
}

.settings-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.settings-label {
  color: var(--text-muted);
}

.settings-val {
  font-weight: 600;
  color: var(--text-primary);
}

.code-val {
  font-family: monospace;
  background: var(--bg-main);
  padding: 2px 6px;
  border-radius: 4px;
}

.badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.authorized {
  background: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
}

.badge.unauthorized {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
}

.sync-controls-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.sync-option-card {
  padding: 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
}

.sync-option-card h4 {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.sync-option-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.primary-btn {
  background: #ffffff !important;
  color: #000000 !important;
  font-weight: 600 !important;
  border: 1px solid #ffffff !important;
}

.primary-btn:hover {
  background: #e5e5e5 !important;
  color: #000000 !important;
  border-color: #e5e5e5 !important;
}

.primary-btn:active {
  background: #cccccc !important;
  color: #000000 !important;
}

.primary-btn svg {
  stroke: #000000 !important;
}

.secondary-btn {
  background: #141414 !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  color: #f5f5f5 !important;
  font-weight: 500 !important;
}

.secondary-btn:hover {
  background: #222222 !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
  color: #ffffff !important;
}

.secondary-btn:active {
  background: #181818 !important;
}

.download-btn,
.btn-download {
  background: #ffffff !important;
  color: #000000 !important;
  font-weight: 600 !important;
  border: 1px solid #ffffff !important;
}

.download-btn:hover,
.btn-download:hover {
  background: #e5e5e5 !important;
  color: #000000 !important;
  border-color: #e5e5e5 !important;
}

.download-btn svg,
.btn-download svg {
  stroke: #000000 !important;
}

.full-width {
  width: 100%;
  justify-content: center;
}

.terminal-tip-box {
  background: #111111;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.terminal-tip-box code {
  display: block;
  margin-top: 0.35rem;
  background: #000000;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: monospace;
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Passcode Modal */
.passcode-dialog {
  max-width: 380px;
}

.passcode-form {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.passcode-form input {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
}

.passcode-form input:focus {
  border-color: var(--border-focus);
}

.error-msg {
  font-size: 0.8rem;
  color: var(--color-error);
}

/* ==========================================================================
   Toast Notifications & Spinners
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

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

.sync-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.sync-spinner.large {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-shimmer {
  background: linear-gradient(90deg, var(--bg-surface-elevated) 25%, var(--bg-surface-hover) 50%, var(--bg-surface-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.nav-shimmer {
  height: 38px;
  margin-bottom: 0.4rem;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Responsive Breakpoints: MacBook Air & Mobile
   ========================================================================== */

/* Tablet & Mobile Drawer */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .top-header {
    padding: 0 0.75rem;
    gap: 0.5rem;
  }

  .header-left {
    min-width: 0;
  }

  .active-topic-meta {
    display: none;
  }

  .header-search {
    flex: 1 1 auto;
    max-width: 100%;
    min-width: 0;
  }

  .search-input-wrapper {
    min-width: 0;
  }

  .search-input-wrapper input {
    min-width: 0;
    padding-left: 2.2rem;
    padding-right: 0.75rem;
    font-size: 0.85rem;
  }

  .search-kbd {
    display: none;
  }

  .header-actions {
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .header-actions .icon-btn {
    width: 34px;
    height: 34px;
  }

  .sync-btn {
    padding: 0.45rem 0.65rem;
  }

  .sync-btn-text {
    display: none;
  }

  .controls-bar {
    padding: 0.65rem 0.75rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .filter-tabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .controls-right {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .feed-section {
    padding: 0.85rem;
    gap: 1rem;
    overflow-x: hidden !important;
  }

  .cards-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .pdf-dialog {
    height: 96vh;
    max-height: 96vh;
    border-radius: var(--radius-sm);
  }

  .toast-container {
    bottom: 16px;
    right: 16px;
    left: 16px;
  }

  .toast {
    width: 100%;
    justify-content: center;
  }

  .security-dialog {
    padding: 2rem 1.4rem;
    max-width: 100%;
    border-radius: 16px;
  }

  .change-key-dialog {
    max-width: 100%;
    margin: 0 0.5rem;
    border-radius: 16px;
  }
}

/* MacBook Air & High DPI Screens (1280px - 1680px) */
@media (min-width: 861px) and (max-width: 1600px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  }
}

/* ==========================================================================
   Security Key Gate & Change Key Modals
   ========================================================================== */

.gate-backdrop {
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  background: rgba(0, 0, 0, 0.96);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.security-dialog {
  max-width: 440px;
  width: 100%;
  text-align: center;
  background: #0d0d0d;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.95), 0 0 0 1px rgba(255, 255, 255, 0.05);
  padding: 2.4rem 2rem;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: modalFadeIn 0.25s ease-out;
}

.security-badge-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 1.25rem auto;
  border-radius: 16px;
  background: #171717;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.security-dialog-header {
  text-align: center;
  margin-bottom: 1.5rem;
  width: 100%;
}

.security-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  color: #ffffff;
}

.security-subtitle {
  font-size: 0.88rem;
  color: #a3a3a3;
  line-height: 1.45;
  margin: 0;
}

.security-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.security-form .input-password-wrapper input {
  height: 48px;
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  color: #ffffff;
  font-size: 0.95rem;
  padding: 0 2.8rem 0 1.1rem;
  transition: all 0.2s ease;
}

.security-form .input-password-wrapper input:focus {
  outline: none;
  border-color: #ffffff;
  background: #1a1a1a;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.security-form #security-key-submit-btn {
  height: 48px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  background: #ffffff !important;
  color: #000000 !important;
  border: 1px solid #ffffff !important;
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.security-form #security-key-submit-btn:hover {
  background: #e5e5e5 !important;
  color: #000000 !important;
  transform: translateY(-1px);
}

.input-password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-password-wrapper input {
  width: 100%;
  padding: 0.75rem 2.8rem 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.input-password-wrapper input:focus {
  outline: none;
  border-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

.password-toggle-btn {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: #737373;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s ease;
}

.password-toggle-btn:hover {
  color: #ffffff;
}

.security-hint-box {
  margin-top: 0.25rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  background: #111111;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  font-size: 0.8rem;
  color: #888888;
  line-height: 1.45;
  text-align: left;
}

.security-hint-box code {
  color: #ffffff;
  background: #1c1c1c;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Change Security Key Modal Styles
   ========================================================================== */

.change-key-dialog {
  max-width: 480px;
  width: 100%;
  background: #0d0d0d;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.95);
  border-radius: 18px;
  margin: 0 auto;
}

.modal-header-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #171717;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-title-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-align: left;
}

.modal-title-text h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.01em;
  margin: 0;
}

.modal-title-text .modal-sub {
  font-size: 0.82rem;
  color: #888888;
  margin: 0;
}

.change-key-form {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  text-align: left;
}

.form-field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #cccccc;
  letter-spacing: 0.01em;
}

.change-key-form .input-password-wrapper input {
  height: 44px;
  background: #141414;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  color: #ffffff;
  font-size: 0.92rem;
  padding: 0 2.8rem 0 1rem;
  transition: all 0.2s ease;
}

.change-key-form .input-password-wrapper input:focus {
  outline: none;
  border-color: #ffffff;
  background: #1a1a1a;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.modal-actions-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 1.15rem;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.modal-actions-row .action-btn {
  height: 42px;
  padding: 0 1.35rem;
  font-size: 0.88rem;
  border-radius: 10px;
}

#change-key-submit-btn {
  background: #ffffff !important;
  color: #000000 !important;
  font-weight: 600 !important;
  border: 1px solid #ffffff !important;
}

#change-key-submit-btn:hover {
  background: #e5e5e5 !important;
  color: #000000 !important;
  border-color: #e5e5e5 !important;
}

.key-btn:hover {
  border-color: rgba(255, 255, 255, 0.4);
  color: #ffffff;
}

.lock-btn:hover {
  border-color: rgba(239, 68, 68, 0.5);
  color: #ef4444;
}

.shake {
  animation: shakeAnimation 0.4s ease-in-out;
}

@keyframes shakeAnimation {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

