/* Study Pages Specific Styles */

/* Study table styling - consistent with base styles */
.study-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
}

.study-table thead tr {
  background-color: #f8f9fa;
  text-align: center;
}

.study-table th,
.study-table td {
  border: 1px solid #ddd;
  padding: 12px;
  text-align: left;
  color: var(--ink);
  line-height: 1.6;
}

.study-table th {
  font-weight: bold;
  text-align: center;
}

.study-table tbody tr td[colspan] {
  background: #eef2ff;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  border-top: 2px solid #dbeafe;
  border-bottom: 1px solid #dbeafe;
  padding: 10px;
}

.study-table tbody tr td[colspan] strong {
  font-weight: 600;
  color: inherit;
}

.study-table tbody tr:nth-child(even) {
  background-color: #f8f9fa;
}

.study-table tbody tr td:first-child {
  font-weight: bold;
}

/* Dark mode table styling */
[data-theme="dark"] .study-table thead tr {
  background-color: #374151;
}

[data-theme="dark"] .study-table th,
[data-theme="dark"] .study-table td {
  border: 1px solid #4b5563;
  color: var(--ink);
}

[data-theme="dark"] .study-table tbody tr td[colspan] {
  background: #1f2937;
  border-top: 2px solid #334155;
  border-bottom: 1px solid #334155;
  color: #e0e7ff;
}

[data-theme="dark"] .study-table tbody tr:nth-child(even) {
  background-color: #374151;
}

/* Study index tile layout */
.study-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 20px 0;
  max-width: 100%;
}

.study-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.2s ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.study-tile:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  text-decoration: none;
  color: inherit;
}

.study-tile.system-design:hover {
  background-color: #e3f2fd;
  border-color: #0366d6;
  color: #0366d6;
}

.study-tile.coding:hover {
  background-color: #e8f5e8;
  border-color: #28a745;
  color: #28a745;
}

[data-theme="dark"] .study-tile.system-design:hover {
  background-color: #1e3a8a;
  border-color: #3b82f6;
  color: #ffffff;
}

[data-theme="dark"] .study-tile.coding:hover {
  background-color: #166534;
  border-color: #22c55e;
  color: #ffffff;
}

.study-tile-title {
  font-weight: 600;
  font-size: 16px;
  margin: 0 0 8px 0;
  color: var(--ink);
}

.study-tile-icon {
  font-size: 18px;
  margin-right: 8px;
}

/* Floating table of contents */
.floating-toc {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  z-index: 1000;
  font-family: var(--sans);
  font-size: 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.floating-toc .toc-icon {
  width: 32px;
  height: 70px;
  background: #6b7280;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #ffffff;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.floating-toc .toc-icon:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.floating-toc .toc-content {
  position: absolute;
  right: 50px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  min-width: 280px;
  max-width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(-50%) translateX(10px);
}

.floating-toc:hover .toc-content,
.floating-toc.toc-open .toc-content {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

.floating-toc .toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.floating-toc .toc-header span {
  font-weight: 600;
  color: var(--ink);
  font-size: 15px;
}

.floating-toc .toc-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.floating-toc .toc-close:hover {
  background: var(--line);
  color: var(--ink);
}

.floating-toc .toc-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}

.floating-toc .toc-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  margin-left: 16px;
}

.floating-toc .toc-nav li {
  margin: 4px 0;
}

.floating-toc .toc-nav a {
  display: block;
  padding: 6px 8px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 13px;
  line-height: 1.4;
}

.floating-toc .toc-nav a:hover {
  background: var(--line);
  color: var(--accent);
}

.floating-toc .toc-nav a.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 500;
}

@media (max-width: 768px) {
  .floating-toc {
    right: 16px;
  }

  .floating-toc .toc-content {
    right: 46px;
    min-width: 260px;
    max-width: calc(100vw - 80px);
  }
}

@media (max-width: 480px) {
  .floating-toc {
    right: 12px;
  }

  .floating-toc .toc-content {
    right: 42px;
    min-width: 240px;
    max-width: calc(100vw - 70px);
  }
}

/* Image and Diagram Styles with Scroll Margins */
.image-wrapper {
  text-align: center;
  margin: 20px 0;
  scroll-margin-top: calc(var(--header-h) + 12px);
}

.image-wrapper img {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s ease;
}

.image-wrapper img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.image-caption {
  margin-top: 8px;
  font-size: 0.9em;
  color: var(--muted);
  text-align: center;
  scroll-margin-top: calc(var(--header-h) + 20px);
}

.diagram-wrapper {
  text-align: center;
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  scroll-margin-top: calc(var(--header-h) + 12px);
}

.diagram-wrapper img {
  max-width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.diagram-wrapper img:hover {
  transform: scale(1.02);
}

.diagram-caption {
  margin-top: 8px;
  font-size: 0.9em;
  color: var(--ink);
  cursor: pointer;
  display: block;
  position: relative;
  text-align: center;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  scroll-margin-top: calc(var(--header-h) + 20px);
}

.diagram-caption::after {
  content: attr(data-tooltip);
  white-space: pre;
  display: none;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 120%;
  z-index: 10;
  max-width: 90vw;
  max-height: 60vh;
  overflow: auto;
  background: #0b0b0c;
  color: #eee;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 8px 12px;
  text-align: left;
  font-family: monospace;
  font-size: 0.85em;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.diagram-caption:hover::after {
  display: block;
}

/* Modal Styles */
.image-modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(4px);
}

.image-modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  position: relative;
  animation: zoomIn 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  max-width: 95vw;
  max-height: 95vh;
}

@keyframes zoomIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-content img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.modal-content img:active {
  cursor: grabbing;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  color: #ffffff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.7);
  transform: scale(1.1);
}

.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #ffffff;
  font-size: 30px;
  cursor: pointer;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  transition: all 0.2s ease;
  opacity: 0.8;
}

.modal-nav:hover {
  background: rgba(0, 0, 0, 0.7);
  opacity: 1;
  transform: translateY(-50%) scale(1.1);
}

.modal-prev {
  left: 20px;
}

.modal-next {
  right: 20px;
}

.modal-content div:last-child {
  position: absolute;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
  max-width: 600px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Responsive */
@media (max-width: 768px) {
  .study-tiles {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 480px) {
  .study-tiles {
    grid-template-columns: 1fr;
  }
}
