/* RASHMI Frontend -- Custom Styles v2 */
/* Pico CSS base + custom overrides for BNCT Simulation Platform */

/* ================================================================
   Color Scheme & Design Tokens
   ================================================================ */
:root {
  --pico-primary: #2563eb;
  --pico-primary-hover: #1d4ed8;
  --pico-primary-focus: rgba(37, 99, 235, 0.25);
  --pico-primary-inverse: #fff;

  /* Extended palette */
  --rashmi-bg-subtle: #f8fafc;
  --rashmi-surface: #ffffff;
  --rashmi-border: #e2e8f0;
  --rashmi-text-muted: #64748b;
  --rashmi-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --rashmi-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --rashmi-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10);
  --rashmi-radius: 8px;

  /* Status colors */
  --rashmi-success-bg: #dcfce7;
  --rashmi-success-fg: #166534;
  --rashmi-warn-bg: #fef3c7;
  --rashmi-warn-fg: #92400e;
  --rashmi-fail-bg: #fee2e2;
  --rashmi-fail-fg: #991b1b;
  --rashmi-info-bg: #dbeafe;
  --rashmi-info-fg: #1e40af;
}

/* Dark mode tokens */
[data-theme="dark"] {
  --rashmi-bg-subtle: #0f172a;
  --rashmi-surface: #1e293b;
  --rashmi-border: #334155;
  --rashmi-text-muted: #94a3b8;
  --rashmi-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --rashmi-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --rashmi-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --rashmi-success-bg: #052e16;
  --rashmi-success-fg: #86efac;
  --rashmi-warn-bg: #451a03;
  --rashmi-warn-fg: #fcd34d;
  --rashmi-fail-bg: #450a0a;
  --rashmi-fail-fg: #fca5a5;
  --rashmi-info-bg: #172554;
  --rashmi-info-fg: #93c5fd;
}

/* ================================================================
   Body & Layout
   ================================================================ */
body {
  background: var(--rashmi-bg-subtle);
}

main.container {
  padding-top: 1.5rem;
  padding-bottom: 2rem;
}

/* ================================================================
   Brand
   ================================================================ */
.brand {
  text-decoration: none !important;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.2;
}
.brand-logo {
  height: 32px;
  width: auto;
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-text strong {
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  color: var(--pico-primary);
}
.brand-text small {
  font-size: 0.6rem;
  color: var(--rashmi-text-muted);
  font-weight: normal;
  letter-spacing: 0.02em;
}

/* ================================================================
   Navigation
   ================================================================ */
nav {
  background: var(--rashmi-surface);
  border-bottom: 2px solid var(--pico-primary);
  padding-bottom: 0;
  box-shadow: var(--rashmi-shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
nav ul li a,
nav ul li details > summary {
  font-size: 0.84rem;
  padding: 0.5rem 0.6rem;
  white-space: nowrap;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
nav ul li a:hover,
nav ul li details > summary:hover {
  background: var(--pico-primary-focus);
}
nav details.dropdown summary::after {
  margin-left: 0.3rem;
}
nav a.active,
nav summary.active {
  font-weight: 700;
  text-decoration: none;
  color: var(--pico-primary);
  border-bottom: 2px solid var(--pico-primary);
}

/* Dropdown section headers */
.dropdown-section {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rashmi-text-muted);
  padding: 0.4rem 0.75rem 0.15rem;
  pointer-events: none;
}

/* User info inside dropdown */
.dropdown-user-info {
  padding: 0.5rem 0.75rem;
  pointer-events: none;
}
.dropdown-user-info small {
  color: var(--rashmi-text-muted);
}

/* User avatar circle in nav */
summary.user-avatar {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--pico-primary);
  color: var(--pico-primary-inverse) !important;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0 !important;
  cursor: pointer;
}
summary.user-avatar::after {
  display: none !important;
}

/* Logout link styling */
.logout-link {
  color: var(--rashmi-fail-fg) !important;
}

/* ================================================================
   Theme Toggle Button
   ================================================================ */
.theme-toggle {
  background: none;
  border: 1.5px solid var(--rashmi-border);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.2s, border-color 0.2s;
  line-height: 1;
}
.theme-toggle:hover {
  background: var(--pico-primary-focus);
  border-color: var(--pico-primary);
}
/* Show moon in light mode, sun in dark mode */
[data-theme="light"] .theme-icon-dark,
:root:not([data-theme="dark"]) .theme-icon-dark { display: none; }
[data-theme="light"] .theme-icon-light,
:root:not([data-theme="dark"]) .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* ================================================================
   Page Titles
   ================================================================ */
h1 {
  font-size: 1.65rem;
  font-weight: 700;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--rashmi-border);
  padding-bottom: 0.5rem;
}
hgroup {
  margin-bottom: 1.25rem;
}
hgroup p {
  color: var(--rashmi-text-muted);
  font-size: 0.9rem;
}

/* ================================================================
   Cards / Articles
   ================================================================ */
article {
  background: var(--rashmi-surface);
  box-shadow: var(--rashmi-shadow-sm);
  border: 1px solid var(--rashmi-border);
  border-radius: var(--rashmi-radius);
  transition: box-shadow 0.2s;
}
article:hover {
  box-shadow: var(--rashmi-shadow-md);
}
article > header {
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--pico-card-sectioning-background-color);
  border-radius: var(--rashmi-radius) var(--rashmi-radius) 0 0;
}

/* ================================================================
   Tables
   ================================================================ */
table {
  font-size: 0.88rem;
}
th {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--rashmi-text-muted);
  font-weight: 700;
}
tbody tr {
  transition: background 0.1s;
}
tbody tr:hover {
  background: var(--pico-primary-focus);
}

/* Wrap tables in figure for horizontal scroll on mobile */
figure[role="table"] {
  overflow-x: auto;
}

/* ================================================================
   Badges / Status Marks
   ================================================================ */
mark {
  background-color: var(--rashmi-success-bg);
  color: var(--rashmi-success-fg);
  padding: 0.15em 0.55em;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.78em;
  white-space: nowrap;
}
mark.warn {
  background-color: var(--rashmi-warn-bg);
  color: var(--rashmi-warn-fg);
}
mark.fail {
  background-color: var(--rashmi-fail-bg);
  color: var(--rashmi-fail-fg);
}
mark.info {
  background-color: var(--rashmi-info-bg);
  color: var(--rashmi-info-fg);
}

.status-badge {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-badge.operational {
  background: var(--rashmi-success-bg);
  color: var(--rashmi-success-fg);
}
.status-badge.not-found {
  background: var(--rashmi-fail-bg);
  color: var(--rashmi-fail-fg);
}
.status-badge.pending {
  background: var(--rashmi-warn-bg);
  color: var(--rashmi-warn-fg);
}

/* ================================================================
   Buttons
   ================================================================ */
.btn-sm {
  padding: 0.25em 0.65em;
  font-size: 0.8em;
  border-radius: 4px;
}

/* Primary action emphasis */
[role="button"]:not(.outline):not(.secondary):not(.contrast) {
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ================================================================
   Forms
   ================================================================ */
label {
  font-size: 0.88rem;
  font-weight: 500;
}
input, select, textarea {
  border-radius: 6px !important;
}
fieldset {
  border: 1px solid var(--rashmi-border);
  border-radius: var(--rashmi-radius);
  padding: 1rem 1.25rem;
}
legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.35em;
}

/* Radio/checkbox labels inside .grid — prevent Pico overlap */
fieldset .grid > label {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  flex-wrap: wrap;
  line-height: 1.5;
}
fieldset .grid > label input[type="radio"],
fieldset .grid > label input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.15em;
  align-self: flex-start;
}
fieldset .grid > label small {
  display: block;
  width: 100%;
  padding-left: 1.6em;
  margin-top: -0.2em;
  font-size: 0.78rem;
  color: var(--rashmi-text-muted);
}

/* ================================================================
   Code Blocks
   ================================================================ */
code {
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* ================================================================
   Empty States
   ================================================================ */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--rashmi-text-muted);
}
.empty-state h3 {
  margin-bottom: 0.5rem;
}

/* ================================================================
   Footer
   ================================================================ */
footer.site-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--pico-primary);
  font-size: 0.82rem;
}
footer.site-footer a {
  color: var(--rashmi-text-muted);
  transition: color 0.15s;
}
footer.site-footer a:hover {
  color: var(--pico-primary);
}
footer.site-footer .footer-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
footer .footer-links small {
  display: flex;
  gap: 1rem;
}
footer.site-footer .footer-copy {
  text-align: center;
  opacity: 0.6;
  font-size: 0.78rem;
}

/* ================================================================
   HTMX Loading Indicators
   ================================================================ */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }

/* Subtle loading shimmer for HTMX targets */
.htmx-request {
  position: relative;
}
.htmx-request::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--pico-primary), transparent);
  animation: htmx-shimmer 1s infinite;
}
@keyframes htmx-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ================================================================
   Glossary Help Tooltips
   ================================================================ */
/* Reset Pico button styles — .glossary-help must look like a small "?" circle */
.glossary-help {
  --pico-background-color: transparent;
  --pico-border-color: var(--pico-primary);
  --pico-color: var(--pico-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15em;
  height: 1.15em;
  padding: 0;
  margin: 0 0.35em;
  border-radius: 50%;
  border: 1.5px solid var(--pico-primary);
  background-color: transparent !important;
  color: var(--pico-primary) !important;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: none;
  transition: background-color 0.15s, color 0.15s;
}
.glossary-help:hover,
.glossary-help:focus {
  background-color: var(--pico-primary) !important;
  color: var(--pico-primary-inverse) !important;
}

.glossary-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-width: 90vw;
  padding: 0.75rem 1rem;
  background-color: var(--rashmi-surface) !important;
  color: var(--pico-color, #373c44) !important;
  border: 1px solid var(--rashmi-border);
  border-radius: var(--rashmi-radius);
  box-shadow: var(--rashmi-shadow-lg);
  font-size: 0.82rem;
  font-weight: normal;
  text-align: left;
  z-index: 1000;
  cursor: default;
  line-height: 1.45;
}
.glossary-tooltip.visible { display: block; }
/* Show tooltip on hover (desktop); click toggle remains for mobile */
.glossary-help:hover > .glossary-tooltip,
.glossary-help:focus-within > .glossary-tooltip { display: block; }

.glossary-tooltip strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 0.3em;
  color: var(--pico-primary) !important;
}
.glossary-tooltip p {
  margin: 0 0 0.4em;
  color: var(--pico-color, #373c44) !important;
}
.glossary-tooltip .glossary-units {
  font-style: italic;
  font-size: 0.78rem;
  color: var(--rashmi-text-muted) !important;
}
.glossary-tooltip .glossary-links {
  margin-top: 0.4em;
  padding-top: 0.4em;
  border-top: 1px solid var(--rashmi-border);
  font-size: 0.78rem;
}
.glossary-tooltip .glossary-links span {
  font-weight: 600;
  color: var(--rashmi-text-muted) !important;
}
.glossary-tooltip .glossary-links a {
  color: var(--pico-primary) !important;
  text-decoration: none;
  font-weight: 500;
}
.glossary-tooltip .glossary-links a:hover {
  text-decoration: underline;
}

/* Tooltip arrow */
.glossary-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--rashmi-surface);
}
.glossary-tooltip::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--rashmi-border);
}

/* ================================================================
   Alert / Flash Messages
   ================================================================ */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--rashmi-radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-success {
  background: var(--rashmi-success-bg);
  color: var(--rashmi-success-fg);
}
.alert-error, .alert-danger {
  background: var(--rashmi-fail-bg);
  color: var(--rashmi-fail-fg);
}
.alert-warn, .alert-warning {
  background: var(--rashmi-warn-bg);
  color: var(--rashmi-warn-fg);
}
.alert-info {
  background: var(--rashmi-info-bg);
  color: var(--rashmi-info-fg);
}

/* Status text colors (accessible contrast ratios) */
.text-success { color: var(--rashmi-success-fg); }
.text-fail, .text-danger { color: var(--rashmi-fail-fg); }
.text-warn, .text-warning { color: var(--rashmi-warn-fg); }
.text-info { color: var(--rashmi-info-fg); }

/* IAEA result bar chart — theme-aware backgrounds */
.iaea-bar-track {
  background: var(--rashmi-border);
  border-radius: 4px;
  height: 1.2rem;
  position: relative;
}
.iaea-bar-fill {
  height: 100%;
  border-radius: 4px;
}
.iaea-bar-fill.pass { background: var(--rashmi-success-fg); }
.iaea-bar-fill.fail { background: var(--rashmi-fail-fg); }

/* Badge variants for transport codes */
mark.success, mark.geant4 {
  background-color: var(--rashmi-success-bg);
  color: var(--rashmi-success-fg);
}
mark.openmc {
  background-color: var(--rashmi-info-bg);
  color: var(--rashmi-info-fg);
}

/* Chart / data area — theme-aware */
.chart-area {
  background: var(--rashmi-bg-subtle);
  border: 1px solid var(--rashmi-border);
  border-radius: var(--rashmi-radius);
  padding: 1rem;
}

/* Progress bar for compliance / wizard */
.progress-bar {
  height: 1.2rem;
  border-radius: 4px;
  overflow: hidden;
  background: var(--rashmi-border);
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}
.progress-fill.good { background: var(--rashmi-success-fg); color: #fff; }
.progress-fill.moderate { background: var(--rashmi-warn-fg); color: #fff; }
.progress-fill.poor { background: var(--rashmi-fail-fg); color: #fff; }

/* ================================================================
   Layer Composer (Geometry Wizard)
   ================================================================ */

/* Summary bar */
.layer-summary {
  display: flex;
  gap: 1.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--rashmi-info-bg);
  color: var(--rashmi-info-fg);
  border-radius: var(--rashmi-radius);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* Stack container */
.layer-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Individual layer card */
.layer-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--rashmi-surface);
  border: 1.5px solid var(--rashmi-border);
  border-radius: var(--rashmi-radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.layer-card:hover {
  border-color: var(--pico-primary);
  box-shadow: var(--rashmi-shadow-sm);
}
.layer-card-error {
  border-color: var(--rashmi-fail-fg) !important;
  background: var(--rashmi-fail-bg);
}

/* Position + type badge */
.layer-card-grip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  min-width: 5.5rem;
  flex-shrink: 0;
}
.layer-card-pos {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--rashmi-text-muted);
  width: 1.4rem;
  height: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--rashmi-border);
}

/* Fields row */
.layer-card-fields {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}
.layer-field {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  margin-bottom: 0 !important;
}
.layer-field-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--rashmi-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}
.layer-field select,
.layer-field input {
  margin-bottom: 0 !important;
  padding: 0.35rem 0.5rem !important;
  font-size: 0.85rem !important;
  height: auto !important;
}

/* Action buttons */
.layer-card-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.layer-btn {
  --pico-background-color: transparent;
  --pico-border-color: var(--rashmi-border);
  --pico-color: var(--rashmi-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0 !important;
  margin: 0 !important;
  border: 1px solid var(--rashmi-border);
  border-radius: 4px;
  background: transparent !important;
  color: var(--rashmi-text-muted) !important;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.layer-btn:hover:not([disabled]) {
  border-color: var(--pico-primary);
  color: var(--pico-primary) !important;
  background: var(--pico-primary-focus) !important;
}
.layer-btn[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
}
.layer-btn-remove:hover:not([disabled]) {
  border-color: var(--rashmi-fail-fg) !important;
  color: var(--rashmi-fail-fg) !important;
  background: var(--rashmi-fail-bg) !important;
}

/* Quick-add bar */
.layer-add-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0;
  margin-top: 0.25rem;
  border-top: 1px dashed var(--rashmi-border);
}
.layer-add-btn {
  --pico-background-color: transparent;
  --pico-border-color: var(--rashmi-border);
  --pico-color: var(--rashmi-text-muted);
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem !important;
  margin: 0 !important;
  border: 1px dashed var(--rashmi-border);
  border-radius: 999px;
  background: transparent !important;
  color: var(--rashmi-text-muted) !important;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.layer-add-btn:hover {
  border-color: var(--pico-primary);
  color: var(--pico-primary) !important;
  background: var(--pico-primary-focus) !important;
  border-style: solid;
}

/* ================================================================
   Utility Classes
   ================================================================ */
.text-muted { color: var(--rashmi-text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Flex row for action bars */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 768px) {
  .brand-text small { display: none; }
  .brand-logo { height: 26px; }
  nav > ul { flex-wrap: wrap; }
  nav ul li a,
  nav ul li details > summary {
    font-size: 0.78rem;
    padding: 0.4rem 0.45rem;
  }
  .theme-toggle {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.85rem;
  }
  summary.user-avatar {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.65rem;
  }
  footer.site-footer .footer-grid { flex-direction: column; }
  footer .footer-links small { flex-direction: column; gap: 0.25rem; }
  h1 { font-size: 1.35rem; }
}

@media (max-width: 480px) {
  nav ul li a,
  nav ul li details > summary {
    font-size: 0.72rem;
    padding: 0.35rem 0.35rem;
  }
}
