/* ============================================================
   MPCALC — Materials Stress-Strain Compute Engine
   Premium industrial dark UI · hard edges · terminal-grade
   ============================================================ */

:root {
  --bg:        #050506;
  --bg-2:      #0a0b0d;
  --panel:     #0d0f12;
  --panel-2:   #101317;
  --line:      #1c2128;
  --line-2:    #2a313b;
  --text:      #e7ecf2;
  --text-dim:  #7d8794;
  --text-faint:#4a525c;
  --accent:    #00e5d0;   /* electric teal */
  --accent-2:  #14b8a6;
  --amber:     #ffb400;   /* result gold */
  --danger:    #ff4d5e;
  --glow:      0 0 0 1px rgba(0,229,208,.25), 0 0 24px -6px rgba(0,229,208,.35);
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(900px 500px at 85% -5%, rgba(0,229,208,.06), transparent 60%),
    radial-gradient(700px 400px at 0% 100%, rgba(255,180,0,.04), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  background-attachment: fixed;
  overflow-x: hidden;
}

/* faint moving scanline for the "instrument" feel */
.scanline {
  position: fixed; inset: 0; pointer-events: none; z-index: 999;
  background: repeating-linear-gradient(
    to bottom, rgba(255,255,255,.012) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

/* ───────────────────────── HEADER ───────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-2), transparent);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  font-family: var(--mono); font-weight: 800; font-size: 15px;
  color: var(--bg); background: var(--accent);
  box-shadow: var(--glow);
  clip-path: polygon(0 0, 100% 0, 100% 70%, 85% 100%, 0 100%);
}
.brand-text h1 {
  font-family: var(--mono); font-size: 18px; font-weight: 800;
  letter-spacing: 3px;
}
.brand-sub {
  font-family: var(--mono); font-size: 10px; letter-spacing: 2px;
  color: var(--text-dim);
}
.status { display: flex; gap: 22px; }
.status-item {
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px;
  color: var(--text-dim); display: flex; align-items: center; gap: 7px;
}
.dot { width: 7px; height: 7px; background: var(--text-faint); display: inline-block; }
.dot.live { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ───────────────────────── LAYOUT ───────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  gap: 18px;
  padding: 18px 22px;
  max-width: 1500px;
  margin: 0 auto;
}
.col { display: flex; flex-direction: column; gap: 18px; }

/* ───────────────────────── PANELS ───────────────────────── */
.panel {
  background:
    linear-gradient(180deg, rgba(255,255,255,.015), transparent 40%),
    var(--panel);
  border: 1px solid var(--line);
  position: relative;
}
.panel::before {
  content: ""; position: absolute; top: 0; left: 0;
  width: 10px; height: 10px;
  border-top: 1px solid var(--accent); border-left: 1px solid var(--accent);
  opacity: .6;
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.panel-id {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  color: var(--accent); border: 1px solid var(--line-2);
  padding: 2px 6px; min-width: 26px; text-align: center;
}
.panel-head h2 {
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  letter-spacing: 2px; flex: 1;
}
.panel-tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1px;
  color: var(--accent); background: rgba(0,229,208,.07);
  border: 1px solid rgba(0,229,208,.2); padding: 3px 8px;
}
.panel-body { padding: 16px 14px; }

/* ───────────────────────── SEGMENTED TOGGLE ───────────────────────── */
.seg { display: flex; border: 1px solid var(--line-2); margin-bottom: 16px; }
.seg-btn {
  flex: 1; padding: 9px 0; cursor: pointer;
  background: transparent; color: var(--text-dim);
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px; font-weight: 600;
  border: none; border-right: 1px solid var(--line-2);
  transition: all .12s ease;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--text); background: rgba(255,255,255,.03); }
.seg-btn.active { background: var(--accent); color: var(--bg); font-weight: 700; }

/* ───────────────────────── FIELDS ───────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.5px;
  color: var(--text-dim); display: flex; gap: 6px; align-items: baseline;
}
.field-label em { color: var(--accent); font-style: normal; font-weight: 700; }
.input-wrap {
  display: flex; align-items: center;
  border: 1px solid var(--line-2); background: var(--bg);
  transition: all .12s ease;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: var(--glow); }
.input-wrap input {
  flex: 1; width: 100%; padding: 10px 11px;
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--mono); font-size: 15px; font-weight: 500;
}
.input-wrap input::placeholder { color: var(--text-faint); }
/* kill number spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
.unit {
  padding: 0 11px; font-family: var(--mono); font-size: 11px;
  color: var(--text-faint); border-left: 1px solid var(--line);
}

.hint { font-size: 11px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.5; }
.hidden { display: none !important; }

/* ───────────────────────── DATA TABLE ───────────────────────── */
.table-wrap { border: 1px solid var(--line-2); max-height: 230px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font-family: var(--mono); font-size: 9px; letter-spacing: 1px;
  color: var(--text-dim); text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line-2); background: var(--panel-2);
  position: sticky; top: 0;
}
.data-table td { border-bottom: 1px solid var(--line); padding: 0; }
.data-table tr:last-child td { border-bottom: none; }
.data-table td.idx {
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  text-align: center; width: 34px;
}
.data-table input {
  width: 100%; padding: 9px 10px; background: transparent; border: none;
  outline: none; color: var(--text); font-family: var(--mono); font-size: 13px;
}
.data-table input:focus { background: rgba(0,229,208,.06); }
.row-del {
  width: 34px; text-align: center; cursor: pointer; color: var(--text-faint);
  font-family: var(--mono); font-size: 15px; user-select: none;
}
.row-del:hover { color: var(--danger); }

.table-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  cursor: pointer; padding: 8px 13px; font-family: var(--mono);
  font-size: 10px; letter-spacing: 1.2px; font-weight: 600;
  border: 1px solid var(--line-2); background: transparent; color: var(--text);
  transition: all .12s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.ghost { background: var(--bg); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ───────────────────────── HERO OUTPUT ───────────────────────── */
.hero { border-color: var(--line-2); }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; }
.hero-metric {
  padding: 26px 22px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line);
}
.hero-metric:last-child { border-right: none; }
.metric-key {
  font-family: var(--mono); font-size: 10px; letter-spacing: 2px; color: var(--text-dim);
}
.metric-val {
  font-family: var(--mono); font-size: 42px; font-weight: 800; line-height: 1;
  color: var(--accent); text-shadow: 0 0 22px rgba(0,229,208,.35);
  letter-spacing: -1px; word-break: break-all;
}
.metric-unit { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }

/* ───────────────────────── METRIC CARDS ───────────────────────── */
.metric-cards {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
}
.card {
  background: var(--panel); border: 1px solid var(--line);
  padding: 16px 15px; display: flex; flex-direction: column; gap: 6px;
  position: relative; transition: border-color .15s;
}
.card:hover { border-color: var(--line-2); }
.card-key { font-family: var(--mono); font-size: 9px; letter-spacing: 1.3px; color: var(--text-dim); }
.card-val {
  font-family: var(--mono); font-size: 26px; font-weight: 700;
  color: var(--text); line-height: 1; word-break: break-all;
}
.card-unit { font-family: var(--mono); font-size: 10px; color: var(--text-faint); }
.card.accent { border-color: rgba(255,180,0,.35); }
.card.accent::after {
  content: ""; position: absolute; top: 0; right: 0; width: 24px; height: 2px; background: var(--amber);
}
.card.accent .card-val { color: var(--amber); text-shadow: 0 0 18px rgba(255,180,0,.3); }
.card.accent .card-key { color: var(--amber); opacity: .85; }

/* ───────────────────────── CHART ───────────────────────── */
.chart-panel { flex: 1; display: flex; flex-direction: column; }
.chart-body { flex: 1; padding: 8px; min-height: 340px; }
#chart { width: 100%; height: 100%; display: block; }

/* ───────────────────────── FOOTER ───────────────────────── */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 22px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 10px; letter-spacing: 1px; color: var(--text-faint);
}
#warn { color: var(--amber); }
.footer .credit { margin-left: auto; color: var(--accent); }

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line-2); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-2); }

/* ───────────────────────── RESPONSIVE ───────────────────────── */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .metric-cards { grid-template-columns: repeat(2, 1fr); }
  .status .status-item:nth-child(2) { display: none; }
}
@media (max-width: 560px) {
  .metric-cards { grid-template-columns: 1fr; }
  .hero-grid { grid-template-columns: 1fr; }
  .hero-metric { border-right: none; border-bottom: 1px solid var(--line); }
  .metric-val { font-size: 34px; }
}
