/* ==========================================================================
   Standard Deviation Calculator Stylesheet - Calculator Archive
   Exact replica of reference layout (Image 2) + Statistical Engine,
   Normal Curve & Histogram Visualizations, Step-by-Step Proofs & Fraction Suite
   ========================================================================== */

:root {
  --sd-green: #2e7d32;
  --sd-green-hover: #1b5e20;
  --sd-btn-calc-bg: #5c9038;
  --sd-btn-calc-border: #4a752d;
  --sd-btn-calc-hover: #4a752d;
  --sd-gray-btn: #8e9ca8;
  --sd-gray-btn-hover: #788591;
  --sd-box-bg: #ffffff;
  --sd-bar-bg: #eceff1;
  --sd-box-border: #d4dde6;
  --sd-input-border: #7f9db9;
  --sd-blue-header: #2b5a88;
  --sd-blue-link: #0044aa;
  --sd-blue-hover: #002277;
  --sd-result-bg: #f4fbf5;
  --sd-result-border: #bbf7d0;
  --sd-result-text: #166534;
  --sd-font: Arial, Helvetica, sans-serif;
}

/* Base & Page Layout */
.sd-page-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px 16px 48px;
  font-family: var(--sd-font);
  color: #333333;
}

/* Top Utility & Breadcrumb Bar */
.sd-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
}

.sd-breadcrumbs {
  font-size: 13px;
  color: #666;
}

.sd-breadcrumbs a {
  color: var(--sd-blue-link);
  text-decoration: none;
}

.sd-breadcrumbs a:hover {
  text-decoration: underline;
}

.sd-breadcrumbs .sep {
  margin: 0 4px;
  color: #999;
}

.sd-breadcrumbs .current {
  color: #333;
  font-weight: 500;
}

.sd-top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sd-action-btn {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.sd-action-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #0f172a;
}

.sd-print-link {
  background: none;
  border: none;
  color: var(--sd-blue-link);
  font-size: 12.5px;
  cursor: pointer;
  padding: 4px 6px;
  text-decoration: none;
}

.sd-print-link:hover {
  text-decoration: underline;
}

/* Page Heading & Instruction (Image 2) */
.sd-page-title {
  font-size: 21px;
  font-weight: bold;
  color: #084482;
  margin: 0 0 8px;
  line-height: 1.3;
}

.sd-instruction {
  font-size: 13px;
  line-height: 1.5;
  color: #333333;
  margin: 0 0 16px;
}

/* 2-Column Grid Layout (Image 2) */
.sd-main-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 820px) {
  .sd-main-layout {
    grid-template-columns: 1fr;
  }
}

/* Left Content Column */
.sd-content-col {
  min-width: 0;
}

/* ==========================================================================
   Main Calculator Box (Exact Clone of Image 2)
   ========================================================================== */
.sd-calc-box {
  background: var(--sd-box-bg);
  border: 1px solid var(--sd-box-border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin-bottom: 24px;
}

.sd-input-area {
  padding: 14px 14px 10px;
  background: #ffffff;
}

.sd-textarea {
  width: 100%;
  height: 96px;
  padding: 8px 10px;
  border: 1px solid var(--sd-input-border);
  border-radius: 2px;
  font-family: Consolas, Monaco, "Courier New", monospace, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1a1a1a;
  box-sizing: border-box;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sd-textarea:focus {
  border-color: #0066cc;
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.15);
}

/* Controls Bar (Gray Footer of Box in Image 2) */
.sd-controls-bar {
  background: var(--sd-bar-bg);
  border-top: 1px solid #d4dde6;
  padding: 10px 14px 12px;
}

.sd-radio-row {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: #222222;
  margin-bottom: 12px;
}

.sd-radio-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

.sd-radio-label input[type="radio"] {
  margin: 0;
  cursor: pointer;
}

/* Tooltip Icon & Popover */
.sd-tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.sd-tooltip-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cbd5e1;
  color: #334155;
  font-size: 11px;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid #94a3b8;
  line-height: 1;
}

.sd-tooltip-icon:hover {
  background: #94a3b8;
  color: #ffffff;
}

.sd-tooltip-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 270px;
  background: #1e293b;
  color: #f8fafc;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  z-index: 50;
  pointer-events: none;
}

.sd-tooltip-wrap:hover .sd-tooltip-popup,
.sd-tooltip-wrap:focus-within .sd-tooltip-popup {
  display: block;
}

/* Action Buttons Row */
.sd-btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sd-btn-calc {
  background: var(--sd-btn-calc-bg);
  color: #ffffff;
  border: 1px solid var(--sd-btn-calc-border);
  padding: 5px 16px 6px 14px;
  font-size: 13.5px;
  font-weight: bold;
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  transition: background 0.15s ease;
}

.sd-btn-calc:hover {
  background: var(--sd-btn-calc-hover);
}

.sd-btn-play-icon {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid #ffffff;
  display: inline-block;
}

.sd-btn-clear {
  background: var(--sd-gray-btn);
  color: #ffffff;
  border: 1px solid var(--sd-gray-btn-hover);
  padding: 5px 14px 6px;
  font-size: 13.5px;
  font-weight: bold;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.sd-btn-clear:hover {
  background: var(--sd-gray-btn-hover);
}

/* ==========================================================================
   Results Output Section
   ========================================================================== */
.sd-results-container {
  margin-top: 20px;
  animation: sdFadeIn 0.25s ease;
}

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

.sd-results-banner {
  background: #edf7ed;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 18px;
}

.sd-res-headline {
  font-size: 14px;
  font-weight: bold;
  color: #1b5e20;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sd-res-primary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 10px;
}

.sd-res-primary-card {
  background: #ffffff;
  border: 1px solid #c8e6c9;
  border-radius: 4px;
  padding: 10px 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.sd-res-primary-card.highlight {
  border-color: #4caf50;
  background: #f1f8e9;
}

.sd-res-primary-label {
  font-size: 12px;
  color: #4b5563;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sd-res-primary-val {
  font-size: 20px;
  font-weight: bold;
  color: #1b5e20;
  word-break: break-all;
}

.sd-res-primary-sub {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}

/* Secondary Metrics Grid */
.sd-metrics-section {
  margin-bottom: 22px;
}

.sd-section-title {
  font-size: 16px;
  font-weight: bold;
  color: #1e3a8a;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sd-metrics-table-wrap {
  overflow-x: auto;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #ffffff;
  margin-bottom: 18px;
}

.sd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.sd-table th,
.sd-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #e2e8f0;
}

.sd-table th {
  background: #f8fafc;
  color: #334155;
  font-weight: 600;
  font-size: 12.5px;
}

.sd-table tr:last-child td {
  border-bottom: none;
}

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

.sd-mono {
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-weight: 600;
  color: #0f172a;
}

/* Visualizations Section (Normal Curve, Histogram, Box Plot, Dot Plot) */
.sd-viz-card {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  padding: 14px;
  margin-bottom: 22px;
}

.sd-viz-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.sd-viz-tab {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sd-viz-tab:hover {
  background: #e2e8f0;
}

.sd-viz-tab.active {
  background: #0284c7;
  border-color: #0369a1;
  color: #ffffff;
  font-weight: bold;
}

.sd-canvas-wrap {
  width: 100%;
  min-height: 260px;
  background: #fafafa;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.sd-canvas-wrap svg {
  width: 100%;
  height: 100%;
  max-height: 320px;
}

/* Step-by-Step Proof Box */
.sd-steps-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 22px;
}

.sd-formula-block {
  background: #ffffff;
  border-left: 3px solid #0284c7;
  padding: 10px 14px;
  margin: 10px 0 14px;
  font-size: 13.5px;
  font-family: Consolas, monospace, Arial;
  color: #0f172a;
  line-height: 1.6;
}

/* Results Actions Bar */
.sd-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
  margin-bottom: 24px;
}

/* ==========================================================================
   Fraction Arithmetic & Statistical Proportions Suite (Req 1 & 5)
   ========================================================================== */
.sd-fraction-section {
  background: #fdfefe;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 18px;
  margin-top: 28px;
  margin-bottom: 28px;
}

.sd-section-heading {
  font-size: 17px;
  font-weight: bold;
  color: #084482;
  margin: 0 0 6px;
}

.sd-section-desc {
  font-size: 13px;
  color: #4b5563;
  margin: 0 0 16px;
  line-height: 1.5;
}

.sd-frac-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: #f8fafc;
  padding: 14px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  margin-bottom: 14px;
}

.sd-frac-box {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  width: 54px;
}

.sd-frac-input {
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  padding: 4px;
  border: 1px solid var(--sd-input-border);
  border-radius: 3px;
  outline: none;
}

.sd-frac-bar {
  width: 100%;
  height: 2px;
  background: #334155;
  margin: 4px 0;
}

.sd-op-select {
  padding: 5px 8px;
  font-size: 16px;
  font-weight: bold;
  border: 1px solid var(--sd-input-border);
  border-radius: 4px;
  background: #ffffff;
  cursor: pointer;
}

.sd-frac-results {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 14px;
}

.sd-frac-viz-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}

@media (max-width: 640px) {
  .sd-frac-viz-stage {
    grid-template-columns: 1fr;
  }
}

.sd-frac-viz-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 12px;
  text-align: center;
}

/* ==========================================================================
   Right Sidebar (Exact Replica of Reference Image 2)
   ========================================================================== */
.sd-sidebar-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Search Form */
.sd-search-form {
  position: relative;
  display: flex;
  gap: 4px;
  width: 100%;
}

.sd-search-input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #7f9db9;
  border-radius: 2px;
  font-size: 13px;
  outline: none;
  min-width: 0;
}

.sd-search-input:focus {
  border-color: #0044aa;
}

.sd-search-btn {
  background: #2b5a88;
  color: #ffffff;
  border: 1px solid #1a3d64;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: bold;
  border-radius: 2px;
  cursor: pointer;
}

.sd-search-btn:hover {
  background: #1a3d64;
}

.sd-search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
}

.sd-search-dropdown.active {
  display: block;
}

.sd-search-item {
  padding: 8px 12px;
  font-size: 12.5px;
  color: #334155;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
}

.sd-search-item:hover {
  background: #f8fafc;
  color: #0044aa;
}

/* Math Calculators Card (Image 2) */
.sd-side-card {
  border: 1px solid #7f9db9;
  border-radius: 2px;
  overflow: hidden;
  background: #ffffff;
}

.sd-side-card-title {
  background: #2b5a88;
  color: #ffffff;
  font-size: 13px;
  font-weight: bold;
  padding: 5px 8px;
}

.sd-side-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid #7f9db9;
}

.sd-side-card-grid a {
  padding: 5px 8px;
  font-size: 12px;
  color: #0044aa;
  text-decoration: none;
  border-bottom: 1px solid #eef2f6;
  border-right: 1px solid #eef2f6;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sd-side-card-grid a:nth-child(2n) {
  border-right: none;
}

.sd-side-card-grid a:hover {
  background: #f0f4f8;
  text-decoration: underline;
}

.sd-side-card-grid a.active {
  background: #e8f0fe;
  font-weight: bold;
  color: #002277;
}

.sd-side-card-footer {
  background: #f4f6f9;
  padding: 6px 8px;
  border-top: 1px solid #cbd5e1;
  font-size: 11.5px;
  text-align: center;
  color: #666;
}

.sd-side-card-footer a {
  color: #0044aa;
  text-decoration: none;
}

.sd-side-card-footer a:hover {
  text-decoration: underline;
}

.sd-side-card-footer .sep {
  margin: 0 4px;
  color: #999;
}

/* ==========================================================================
   SEO, AEO, and GEO Content Styling
   ========================================================================== */
.sd-seo-article {
  margin-top: 36px;
  border-top: 1px solid #e2e8f0;
  padding-top: 24px;
  font-size: 13.5px;
  line-height: 1.65;
  color: #2d3748;
}

.sd-seo-article h2 {
  font-size: 18px;
  color: #084482;
  margin: 20px 0 10px;
  font-weight: bold;
}

.sd-seo-article h3 {
  font-size: 15px;
  color: #1a3d64;
  margin: 16px 0 8px;
  font-weight: bold;
}

.sd-seo-article p {
  margin: 0 0 12px;
}

.sd-seo-article ul {
  margin: 0 0 14px 20px;
  padding: 0;
}

.sd-seo-article li {
  margin-bottom: 6px;
}

.sd-aeo-card {
  background: #f8fafc;
  border-left: 3px solid #2b5a88;
  padding: 12px 16px;
  margin: 14px 0;
  border-radius: 0 4px 4px 0;
}

.sd-aeo-q {
  font-weight: bold;
  color: #1e3a8a;
  font-size: 13.5px;
  margin-bottom: 4px;
}

.sd-aeo-a {
  font-size: 13px;
  color: #334155;
  line-height: 1.5;
}

.sd-faq-section {
  margin-top: 24px;
}

.sd-faq-item {
  border-bottom: 1px solid #e2e8f0;
  padding: 12px 0;
}

.sd-faq-q {
  font-weight: bold;
  color: #0f172a;
  font-size: 14px;
  margin-bottom: 4px;
}

.sd-faq-a {
  font-size: 13px;
  color: #475569;
  line-height: 1.55;
}

/* ==========================================================================
   Modals (Print & Saved History)
   ========================================================================== */
.sd-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.sd-modal-content {
  background: #ffffff;
  border-radius: 8px;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.sd-modal-header {
  padding: 12px 18px;
  background: #2b5a88;
  color: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sd-modal-title {
  font-size: 15px;
  font-weight: bold;
}

.sd-modal-close {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.sd-modal-body {
  padding: 18px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.5;
}

.sd-modal-footer {
  padding: 10px 18px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Toast Notifications */
.sd-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
  z-index: 10000;
  animation: sdToastIn 0.2s ease;
}

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

/* ==========================================================================
   Print Stylesheet Isolation (@media print)
   ========================================================================== */
@media print {
  @page {
    size: letter portrait;
    margin: 12mm 15mm;
  }

  body.sd-printing-modal header,
  body.sd-printing-modal .sd-top-bar,
  body.sd-printing-modal .sd-sidebar-col,
  body.sd-printing-modal .sd-seo-article,
  body.sd-printing-modal .sd-fraction-section,
  body.sd-printing-modal footer,
  body.sd-printing-modal .site-footer,
  body.sd-printing-modal .sd-calc-box,
  body.sd-printing-modal .sd-results-actions,
  body.sd-printing-modal .sd-modal-header,
  body.sd-printing-modal .sd-modal-footer {
    display: none !important;
  }

  body.sd-printing-modal .sd-modal-backdrop {
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
    display: block !important;
  }

  body.sd-printing-modal .sd-modal-content {
    box-shadow: none !important;
    border: none !important;
    max-width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.sd-printing-modal .sd-modal-body {
    padding: 0 !important;
    overflow: visible !important;
  }

  .sd-print-sheet {
    font-family: Arial, sans-serif !important;
    color: #000000 !important;
    line-height: 1.4 !important;
  }

  .sd-print-sheet h1 {
    font-size: 18pt !important;
    color: #000000 !important;
    margin-bottom: 4pt !important;
  }

  .sd-print-sheet table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 10pt 0 !important;
  }

  .sd-print-sheet th,
  .sd-print-sheet td {
    border: 1px solid #444 !important;
    padding: 4pt 6pt !important;
    font-size: 9pt !important;
  }

  .sd-print-sheet th {
    background: #f0f0f0 !important;
  }

  .sd-print-svg-wrap {
    max-width: 480pt !important;
    margin: 8pt auto !important;
    text-align: center !important;
  }
}
