/* API Function Styling for PyDevelop-Docs
 * Fixes white/unstyled functions and improves API documentation appearance
 * Compatible with Furo theme
 */

/* CSS Variables for API styling */
:root {
  --api-function-bg: #f8f9fa;
  --api-function-border: #e9ecef;
  --api-function-hover: #e9ecef;
  --api-class-bg: #f1f5f9;
  --api-class-border: #e2e8f0;
  --api-param-color: #495057;
  --api-return-color: #0066cc;
  --api-decorator-color: #6f42c1;
  --api-async-color: #dc3545;
  --api-code-bg: #f6f8fa;
}

body[data-theme="dark"] {
  --api-function-bg: #1e293b;
  --api-function-border: #334155;
  --api-function-hover: #2d3748;
  --api-class-bg: #1a202c;
  --api-class-border: #2d3748;
  --api-param-color: #cbd5e1;
  --api-return-color: #60a5fa;
  --api-decorator-color: #a78bfa;
  --api-async-color: #f87171;
  --api-code-bg: #0f172a;
}

/* Function/Method/Class Signatures - Fix white appearance */
dl.py.function > dt,
dl.py.method > dt,
dl.py.class > dt,
dl.py.attribute > dt,
dl.py.data > dt,
dl.py.exception > dt {
  background-color: var(--api-function-bg);
  border: 1px solid var(--api-function-border);
  border-radius: 0.375rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  font-family:
    "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  position: relative;
  transition: background-color 0.2s ease;
}

/* Hover effect */
dl.py.function > dt:hover,
dl.py.method > dt:hover,
dl.py.class > dt:hover {
  background-color: var(--api-function-hover);
}

/* Class signatures get slightly different styling */
dl.py.class > dt {
  background-color: var(--api-class-bg);
  border-color: var(--api-class-border);
  font-weight: 600;
}

/* Fix sig-object styling */
.sig.sig-object {
  background-color: var(--api-function-bg) !important;
  border: 1px solid var(--api-function-border) !important;
  border-radius: 0.375rem !important;
  padding: 0.5rem 1rem !important;
  margin: 0.5rem 0 !important;
  display: block;
  width: 100%;
}

/* Parameter styling */
.sig-param {
  color: var(--api-param-color);
  font-style: italic;
}

/* Return type styling */
.sig-return {
  color: var(--api-return-color);
  font-weight: 500;
}

/* Decorator styling */
.decorator {
  color: var(--api-decorator-color);
  font-style: italic;
  font-size: 0.9em;
}

/* Async indicator */
dt .pre:contains("async") {
  color: var(--api-async-color);
  font-weight: 600;
}

/* Permalink/headerlink styling */
.headerlink {
  opacity: 0;
  transition: opacity 0.2s ease;
  margin-left: 0.5rem;
  color: var(--color-brand-primary);
  text-decoration: none;
}

dt:hover .headerlink {
  opacity: 1;
}

/* Source link styling - Add [source] links */
.viewcode-link,
.viewsource-link {
  float: right;
  font-size: 0.875rem;
  color: var(--color-brand-primary);
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.viewcode-link:hover,
.viewsource-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Add [source] link via CSS if missing */
dl.py > dt::after {
  content: "[source]";
  float: right;
  font-size: 0.875rem;
  color: var(--color-brand-primary);
  opacity: 0.6;
  cursor: pointer;
  margin-left: 1rem;
}

dl.py > dt:hover::after {
  opacity: 1;
  text-decoration: underline;
}

/* Function body/description styling */
dl.py > dd {
  margin-left: 0;
  padding: 1rem;
  background-color: var(--color-background-secondary);
  border: 1px solid var(--api-function-border);
  border-top: none;
  border-radius: 0 0 0.375rem 0.375rem;
  margin-bottom: 1.5rem;
}

/* Empty dd elements should be hidden */
dl.py > dd:empty {
  display: none;
}

/* Field list (parameters, returns, etc.) */
.field-list {
  background-color: var(--color-background-primary);
  border: 1px solid var(--api-function-border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0.5rem 0;
}

.field-list dt {
  font-weight: 600;
  color: var(--api-param-color);
  margin-bottom: 0.25rem;
}

.field-list dd {
  margin-left: 1.5rem;
  margin-bottom: 0.5rem;
}

/* Admonition improvements */
.admonition {
  border-radius: 0.375rem;
  margin: 1rem 0;
}

.admonition.tip {
  background-color: rgba(37, 99, 235, 0.1);
  border-left: 4px solid #2563eb;
}

.admonition.warning {
  background-color: rgba(245, 158, 11, 0.1);
  border-left: 4px solid #f59e0b;
}

.admonition.danger {
  background-color: rgba(239, 68, 68, 0.1);
  border-left: 4px solid #ef4444;
}

.admonition.seealso {
  background-color: rgba(139, 92, 246, 0.1);
  border-left: 4px solid #8b5cf6;
}

.admonition.note {
  background-color: rgba(59, 130, 246, 0.1);
  border-left: 4px solid #3b82f6;
}

/* Dark mode admonition adjustments */
[data-theme="dark"] .admonition.tip {
  background-color: rgba(37, 99, 235, 0.2);
}

[data-theme="dark"] .admonition.warning {
  background-color: rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .admonition.danger {
  background-color: rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .admonition.seealso {
  background-color: rgba(139, 92, 246, 0.2);
}

[data-theme="dark"] .admonition.note {
  background-color: rgba(59, 130, 246, 0.2);
}

/* Container styling for function-info, class-info */
.function-info,
.class-info {
  margin-top: 1rem;
  padding: 0.5rem;
  background-color: var(--color-background-secondary);
  border-radius: 0.25rem;
}

/* Rubric styling */
.rubric {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-brand-content);
  margin-top: 2rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--api-function-border);
  padding-bottom: 0.5rem;
}

/* AutoAPI summary tables */
.autoapisummary table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.autoapisummary td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--api-function-border);
}

.autoapisummary td:first-child {
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-weight: 500;
}

/* SD Card improvements for API docs */
.sd-card {
  border: 1px solid var(--api-function-border) !important;
  background-color: var(--color-background-secondary) !important;
}

.sd-card-body:empty {
  display: none;
}

/* Inheritance container */
.inheritance {
  margin: 0.5rem 0;
  padding: 0.5rem;
  background-color: var(--color-background-secondary);
  border-radius: 0.25rem;
  font-size: 0.9rem;
}

/* Module stat badges */
.module-stat {
  display: inline-block;
  background-color: var(--color-brand-primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  margin-left: 0.5rem;
}

/* Fix for empty divs in API docs */
div.sd-col.sd-d-flex-row.docutils:has(> .sd-card > .sd-card-body:empty) {
  display: none;
}

/* Source link container */
.source-link {
  text-align: right;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--api-function-border);
}

/* Code highlighting in API docs */
.sig .pre {
  background-color: transparent !important;
  padding: 0 !important;
}

/* Fix contrast for dark mode */
[data-theme="dark"] .sig-name {
  color: #60a5fa;
}

[data-theme="dark"] .sig-param {
  color: #94a3b8;
}

[data-theme="dark"] .sig-return {
  color: #34d399;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  dl.py > dt {
    padding: 0.5rem;
    font-size: 0.875rem;
  }

  dl.py > dt::after {
    display: none; /* Hide [source] on mobile */
  }

  .field-list dd {
    margin-left: 1rem;
  }
}
