/* ==========================================================================
   PrismCalc — Responsive Application Layout, Visualizers, Drawer & Modals
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--page-bg);
  color: var(--page-text);
  -webkit-font-smoothing: antialiased;
  transition: background 300ms ease, color 300ms ease;
}

.app-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Navigation Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--chrome-card);
  border-bottom: 1px solid var(--chrome-border);
  backdrop-filter: blur(22px) saturate(170%);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--track-border);
}

.brand-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.76rem;
  color: var(--page-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-switcher-wrap {
  min-width: 330px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--chrome-border);
  background: var(--chrome-card);
  color: var(--page-text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms ease, background 200ms ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.96);
}

/* Main Stage */
.main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 18px;
  gap: 10px;
}

/* Preset Strip */
.preset-bar {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 680px;
}

.preset-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--calc-muted);
}

.preset-chip {
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

/* Calculator Shell Sizing */
.calc-container {
  width: 100%;
  max-width: 448px;
  padding: 14px 16px;
}

.calc-container--wide {
  max-width: 580px;
}

.calc-topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.calc-topbar-left,
.calc-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.ages-label {
  font-size: 0.76rem;
  color: var(--calc-muted);
  font-weight: 500;
}

/* Display Internals */
.display-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.display-history-line {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--calc-muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 58%;
}

.visual-panel {
  position: relative;
  z-index: 2;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 16px;
  background: var(--viz-bg);
  border: 1px solid var(--disp-border);
  transition: opacity 220ms ease;
}

.visual-panel.is-hidden {
  display: none;
}

/* Editable Expression Input */
.expr-input {
  position: relative;
  z-index: 2;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--calc-muted);
  font-family: var(--font-mono);
  font-size: 0.96rem;
  font-weight: 500;
  text-align: right;
  padding: 2px 0;
}

.result-readout {
  position: relative;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: clamp(1.7rem, 4.2vw, 2.25rem);
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -0.025em;
  text-align: right;
  word-break: break-all;
  margin-top: 2px;
}

.result-readout.is-error {
  font-size: 1.05rem;
  color: #dc2626;
}

[data-theme="dark"] .result-readout.is-error {
  color: #fca5a5;
}

.hint-line {
  position: relative;
  z-index: 2;
  font-size: 0.78rem;
  color: var(--calc-muted);
  text-align: right;
  margin-top: 6px;
  min-height: 1.1em;
}

/* Memory Strip */
.memory-row {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 7px;
  margin-bottom: 6px;
}

.memory-btn {
  height: 26px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--disp-border);
  background: var(--disp-bg);
  color: var(--calc-text);
  opacity: 0.82;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease, opacity 180ms ease, transform 120ms ease;
}

.memory-btn:hover {
  opacity: 1;
}

.memory-btn.has-memory {
  opacity: 1;
  color: var(--accent-text);
  background: var(--accent-soft);
}

/* Context Strip & College Ribbon */
.context-strip {
  position: relative;
  z-index: 2;
  margin-top: 6px;
  margin-bottom: 7px;
}

.context-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.context-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.ribbon-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.ribbon-tab {
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--key-fn-border);
  background: var(--key-fn-bg);
  color: var(--key-fn-text);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  transition: background 180ms ease, color 180ms ease, transform 140ms ease;
}

.ribbon-tab.is-active {
  background: var(--key-op-bg);
  border-color: var(--key-op-border);
  color: var(--key-op-text);
}

/* Keypad Grid */
.keypad {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: var(--key-gap);
}

.keypad-row {
  display: grid;
  gap: var(--key-gap);
}

.keypad-row--4 {
  grid-template-columns: repeat(4, 1fr);
}

.keypad-row--5 {
  grid-template-columns: repeat(5, 1fr);
}

.shell-handle {
  position: relative;
  z-index: 2;
  width: 84px;
  height: 4px;
  border-radius: 9999px;
  background: currentColor;
  opacity: 0.22;
  margin: 10px auto 0;
}

/* Visualizers Specific Styling */
.dots-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.dots-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.count-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
}

.count-dot--outline {
  background: var(--accent-soft);
  border: 2px solid var(--accent);
}

.ratio-track {
  width: 100%;
  height: 10px;
  border-radius: 9999px;
  background: var(--accent-soft);
  overflow: hidden;
  margin-top: 6px;
}

.ratio-fill {
  height: 100%;
  border-radius: 9999px;
  background: var(--accent);
  transition: width 320ms var(--spring-smooth);
}

.graph-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.74rem;
  font-family: var(--font-mono);
}

.graph-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.graph-mini-btn {
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid var(--disp-border);
  background: var(--disp-bg);
  color: var(--calc-text);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.graph-canvas {
  width: 100%;
  height: 92px;
  display: block;
  border-radius: 10px;
  cursor: crosshair;
}

.matrix-preview {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.matrix-grid {
  display: grid;
  gap: 4px 12px;
  text-align: center;
  font-weight: 700;
}

/* Slide-Over History Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 22, 0.35);
  backdrop-filter: blur(6px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

.drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.history-drawer {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(360px, calc(100vw - 32px));
  z-index: 50;
  border-radius: 28px;
  background: var(--shell-bg);
  border: 1px solid var(--shell-border);
  box-shadow: var(--shell-shadow);
  color: var(--calc-text);
  backdrop-filter: blur(32px) saturate(185%);
  -webkit-backdrop-filter: blur(32px) saturate(185%);
  display: flex;
  flex-direction: column;
  padding: 18px;
  transform: translateX(calc(100% + 28px));
  transition: transform 320ms var(--spring-smooth);
}

.history-drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--disp-border);
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  width: 100%;
  text-align: right;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--disp-border);
  background: var(--disp-bg);
  color: var(--calc-text);
  cursor: pointer;
  transition: transform 140ms ease;
}

.history-item:hover {
  transform: translateY(-1px);
}

.history-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--calc-muted);
  margin-bottom: 2px;
}

.history-item-expr {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--calc-muted);
}

.history-item-res {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
}

/* College Modal (Matrix & Calculus Guided Builder) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 12, 22, 0.42);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.is-hidden {
  display: none;
}

.modal-card {
  width: min(440px, 100%);
  border-radius: 28px;
  background: var(--shell-bg);
  border: 1px solid var(--shell-border);
  box-shadow: var(--shell-shadow);
  color: var(--calc-text);
  backdrop-filter: blur(32px) saturate(185%);
  -webkit-backdrop-filter: blur(32px) saturate(185%);
  padding: 20px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.modal-input {
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px solid var(--disp-border);
  background: var(--disp-bg);
  color: var(--calc-text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  outline: none;
}

.matrix-inputs {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.matrix-cell-input {
  width: 100%;
  text-align: center;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid var(--disp-border);
  background: var(--disp-bg);
  color: var(--calc-text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Mode Capability Footer Pill */
.mode-footer {
  position: relative;
  z-index: 2;
  max-width: 580px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--calc-muted);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: var(--disp-bg);
  border: 1px solid var(--disp-border);
  backdrop-filter: blur(16px);
}

@media (max-width: 640px) {
  .app-header {
    padding: 12px 14px;
  }
  .mode-switcher-wrap {
    width: 100%;
    min-width: 0;
  }
  .calc-container {
    padding: 14px;
  }
}

/* ==========================================================================
   Unified OpenAppsAI Suite Chrome (Header & Footer)
   Consistent across openappsai.com, DeepThink, OpenSign, Mortgage & PrismCalc
   ========================================================================== */
.oa-header {
  position: sticky;
  top: 0;
  z-index: 35;
  padding: 10px 16px 0;
  background: transparent;
}

.oa-nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
  border: 1px solid rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.96), 0 6px 22px rgba(32, 42, 88, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

[data-theme="dark"] .oa-nav {
  background: rgba(20, 25, 44, 0.84);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 8px 26px rgba(0, 0, 0, 0.42);
}

.oa-brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.oa-prism-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 11px;
  transition: transform 0.18s ease;
}

.oa-prism-btn:hover {
  transform: scale(1.05);
}

.oa-logo {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, #4f46e5 0%, #06b6d4 52%, #f43f5e 100%);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 7px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.34);
  flex-shrink: 0;
}

.oa-dot {
  background: #ffffff;
  display: block;
}

.oa-dot.d1,
.oa-dot.d4 {
  border-radius: 2.5px;
}

.oa-dot.d2,
.oa-dot.d3 {
  border-radius: 50%;
  opacity: 0.84;
}

.oa-divider {
  width: 1px;
  height: 22px;
  background: var(--chrome-border);
}

.oa-app-link {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
}

.oa-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.08;
}

.oa-brand-title {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.oa-brand-sub {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--page-muted);
}

.oa-suite-pills {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.14);
}

[data-theme="dark"] .oa-suite-pills {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

.oa-pill {
  padding: 6px 12px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--page-muted);
  white-space: nowrap;
  transition: background-color 0.18s, color 0.18s;
}

.oa-pill:hover {
  background: rgba(79, 70, 229, 0.12);
  color: var(--page-text);
}

.oa-pill.is-active {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(2, 132, 199, 0.28);
}

.oa-footer {
  margin-top: auto;
  border-top: 1px solid rgba(98, 108, 152, 0.2);
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

[data-theme="dark"] .oa-footer {
  background: rgba(16, 20, 36, 0.78);
  border-top-color: rgba(255, 255, 255, 0.12);
}

.oa-footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
}

.oa-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--page-muted);
}

.oa-footer-brand strong {
  color: var(--page-text);
  font-weight: 800;
}

.oa-footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.oa-footer-links a {
  text-decoration: none;
  color: var(--page-muted);
  font-weight: 700;
  transition: color 0.18s;
}

.oa-footer-links a:hover {
  color: var(--accent);
}

@media (max-width: 900px) {
  .oa-suite-pills {
    display: none;
  }
}

@media (max-width: 600px) {
  .oa-header {
    padding: 8px 10px 0;
  }
  .oa-nav {
    padding: 6px 10px;
  }
  .oa-brand-sub {
    display: none;
  }
  .oa-footer-inner {
    flex-direction: column;
    text-align: center;
  }
  .oa-footer-links {
    justify-content: center;
    gap: 12px;
  }
}
