:root {
  --sidebar-width: 265px;
  --sidebar-mobile-width: min(86vw, 300px);
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
}

* {
  box-sizing: border-box;
}

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: #0f172a;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-toggle,
.sidebar-backdrop {
  display: none;
}

.sidebar-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 42px;
  height: 42px;
  border: 1px solid #cbd5e1;
  border-radius: 11px;
  background: #fff;
  color: #0f172a;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  z-index: 140;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  opacity: 0;
  pointer-events: none;
  z-index: 120;
  transition: opacity 0.2s ease;
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-brand h4 {
  margin: 0;
  color: #f1f5f9;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
}

.sidebar-brand small {
  color: #64748b;
  font-size: 0.7rem;
  line-height: 1;
}

.sidebar .nav {
  padding: 0.75rem 0;
  flex: 1;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.5rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.sidebar .nav-link i {
  width: 18px;
  text-align: center;
  font-size: 0.95rem;
}

.sidebar .nav-link:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.05);
  border-left-color: rgba(255, 255, 255, 0.15);
}

.sidebar .nav-link.active {
  color: #fff;
  background: rgba(37, 99, 235, 0.15);
  border-left-color: var(--primary);
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info {
  overflow: hidden;
}

.user-info .fw-500 {
  color: #e2e8f0;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info .text-muted-sm {
  color: #64748b;
  font-size: 0.73rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-sidebar-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-sidebar-sm:hover,
.btn-sidebar-sm.active {
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
}

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 2rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.top-bar h5 {
  color: var(--text);
}

.page-content {
  flex: 1;
  padding: 1.75rem 2rem;
}

.card,
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}

.card-header {
  padding: 1rem 1.5rem !important;
  background: #fff !important;
  border-bottom: 1px solid #f1f5f9 !important;
  border-radius: 12px 12px 0 0 !important;
}

.card-body {
  padding: 1.5rem;
}

.stat-card {
  padding: 1.5rem;
}

.stat-card .number {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.stat-card .label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.stat-card .icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.table {
  margin: 0;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table thead th {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tbody td {
  padding: 0.85rem 1.25rem;
  border-color: #f1f5f9;
  vertical-align: middle;
  font-size: 0.875rem;
  color: #374151;
}

.table-hover tbody tr:hover {
  background: #f8fafc;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover,
.clickable-row:focus {
  background: #f8fbff !important;
  outline: none;
}

.term-highlight {
  padding: 0 0.18rem;
  border-radius: 4px;
  background: #fef08a;
  color: #713f12;
  font-weight: 700;
}

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

.highlighted-reading {
  white-space: normal;
  line-height: 1.8;
  color: #1f2937;
  font-size: 0.96rem;
}

.pdf-inline-preview-wrap {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.pdf-inline-preview {
  width: 100%;
  height: min(72vh, 860px);
  min-height: 420px;
  border: 0;
  display: block;
}

.badge {
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
}

.bg-primary-soft { background: #eff6ff !important; }
.bg-info-soft { background: #f0f9ff !important; }
.bg-success-soft { background: #f0fdf4 !important; }
.bg-warning-soft { background: #fffbeb !important; }
.bg-danger-soft { background: #fef2f2 !important; }
.bg-secondary-soft { background: #f8fafc !important; }

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
}

.status-active {
  background: #f0fdf4;
  color: #16a34a;
}

.status-inactive {
  background: #fef2f2;
  color: #dc2626;
}

.btn-primary {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--primary-dark) !important;
  border-color: var(--primary-dark) !important;
}

.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }

.empty-state {
  padding: 3.5rem 2rem;
  text-align: center;
  color: #94a3b8;
}

.empty-state i {
  display: block;
  margin-bottom: 1rem;
  font-size: 3rem;
  color: #cbd5e1;
}

.empty-state p {
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.section-picker {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  padding: 1rem;
}

.section-checkbox-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.65rem;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.section-checkbox-list.is-disabled {
  opacity: 0.55;
}

.section-check {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  min-height: 48px;
  padding: 0.75rem;
  border: 1px solid #dbe5f1;
  border-radius: 10px;
  background: #fff;
  font-size: 0.86rem;
  color: #334155;
  cursor: pointer;
}

.section-check:hover {
  border-color: #c7d2fe;
  background: #fdfdff;
}

.section-check .form-check-input {
  margin-top: 2px;
  flex-shrink: 0;
}

.pdf-viewer-card .card-body {
  padding: 0;
}

.pdf-viewer-body {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 290px;
  min-height: calc(100vh - 180px);
}

.pdf-tools-panel,
.pdf-marks-panel {
  background: #ffffff;
  padding: 1rem;
  border-right: 1px solid #edf2f7;
  overflow-y: auto;
}

.pdf-marks-panel {
  border-right: 0;
  border-left: 1px solid #edf2f7;
  background: #fbfdff;
}

.pdf-canvas-panel {
  background: #eef2f7;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
  padding: 1.2rem;
}

.pdf-stage-wrap {
  min-width: 100%;
  display: flex;
  justify-content: center;
}

#pdf-stage {
  position: relative;
  background: #fff;
  box-shadow: 0 6px 26px rgba(15, 23, 42, 0.16);
  border-radius: 8px;
  overflow: hidden;
}

#pdf-canvas,
#pdf-text-layer,
#pdf-highlight-layer {
  position: absolute;
  inset: 0;
}

#pdf-canvas {
  position: relative;
  display: block;
}

#pdf-text-layer {
  z-index: 4;
  user-select: text;
  cursor: text;
}

#pdf-text-layer .textLayer {
  position: static;
}

#pdf-text-layer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  transform-origin: 0 0;
}

#pdf-highlight-layer {
  z-index: 5;
  pointer-events: none;
}

.pdf-highlight-box {
  position: absolute;
  background: rgba(255, 235, 59, 0.45);
  border: 1px solid rgba(239, 190, 15, 0.8);
  border-radius: 3px;
}

.pdf-highlights-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.pdf-mark-item {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  padding: 0.7rem 0.75rem;
}

.pdf-mark-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.pdf-mark-header .btn-link {
  margin-left: auto;
  text-decoration: none;
}

body.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 2.5rem;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}

.auth-logo {
  width: 52px;
  height: 52px;
  margin-bottom: 1.25rem;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.auth-card h2 {
  margin-bottom: 4px;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
}

.auth-card .subtitle {
  margin-bottom: 1.75rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.input-group-text {
  background: #f8fafc;
  border-color: var(--line);
  color: var(--muted);
}

.form-control {
  border-color: var(--line);
  font-size: 0.9rem;
}

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

.form-label {
  margin-bottom: 0.4rem;
  color: #374151;
  font-size: 0.85rem;
  font-weight: 500;
}

.swal-wide {
  width: min(720px, calc(100vw - 32px)) !important;
}

.swal2-popup {
  border-radius: 14px !important;
}

.swal2-title {
  font-size: 1.1rem !important;
  font-weight: 700 !important;
}

.swal2-confirm,
.swal2-cancel {
  border-radius: 8px !important;
  font-weight: 500 !important;
}

.app-pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-pagination-info {
  font-size: 0.83rem;
}

.app-pagination-nav {
  margin-left: auto;
}

.app-pagination-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.app-page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 0.7rem;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #475569;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s ease;
}

.app-page-btn:hover {
  border-color: #94a3b8;
  color: #1e293b;
  background: #f8fafc;
}

.app-page-btn.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}

.app-page-btn.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.app-page-ellipsis {
  min-width: 24px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-weight: 700;
  letter-spacing: 1px;
}

@media (max-width: 992px) {
  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar {
    width: var(--sidebar-mobile-width);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 130;
    box-shadow: 10px 0 30px rgba(2, 6, 23, 0.4);
  }

  .sidebar-backdrop {
    display: block;
  }

  body.sidebar-open {
    overflow: hidden;
  }

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

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

  .sidebar {
    min-height: 100vh;
  }

  .main-content {
    margin-left: 0;
  }

  .top-bar {
    padding: 1rem;
  }

  .page-content {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .pdf-viewer-body {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .pdf-tools-panel,
  .pdf-marks-panel {
    border-right: 0;
    border-left: 0;
    border-bottom: 1px solid #edf2f7;
  }

  .pdf-canvas-panel {
    min-height: 55vh;
  }
}

@media (max-width: 768px) {
  .table-responsive {
    overflow-x: visible;
  }

  .table-responsive .table {
    min-width: 0;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .table-responsive .table thead {
    display: none;
  }

  .table-responsive .table tbody {
    display: block;
  }

  .table-responsive .table tbody tr {
    display: block;
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
  }

  .table-responsive .table tbody td {
    display: grid;
    grid-template-columns: minmax(105px, 40%) minmax(0, 1fr);
    gap: 0.55rem;
    align-items: start;
    padding: 0.35rem 0;
    font-size: 0.82rem;
    white-space: normal;
    border: 0;
    text-align: left;
  }

  .table-responsive .table tbody td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.35px;
    text-transform: uppercase;
    line-height: 1.35;
  }

  .table-responsive .table tbody td:last-child {
    padding-bottom: 0;
  }

  .table-responsive .table tbody td[data-label='']::before {
    content: '';
  }

  .table-responsive .table tbody td .badge {
    white-space: normal;
  }

  .table-responsive .table tbody td.text-truncate,
  .table-responsive .table tbody td[style*='text-overflow:ellipsis'] {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
  }

  .table-wrapper {
    overflow-x: auto;
  }

  .table-wrapper table {
    min-width: 680px;
  }

  .top-bar {
    flex-wrap: wrap;
    padding: 1rem;
  }

  .page-content {
    padding: 1rem;
  }

  .section-checkbox-list {
    grid-template-columns: 1fr;
  }

  .pdf-inline-preview {
    min-height: 340px;
    height: 62vh;
  }

  .app-pagination-wrap {
    flex-direction: column;
    align-items: stretch;
  }

  .app-pagination-nav {
    margin-left: 0;
  }

  .app-pagination-list {
    justify-content: center;
    flex-wrap: wrap;
  }
}

@media (max-width: 576px) {
  .table-wrapper table {
    min-width: 620px;
  }
}
