/* =========================================================================
 * Metasurface Studio — Shared Styles (light, clean, engineering UI)
 * ========================================================================= */
:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f0f4f8;
  --ink: #1e293b;
  --ink-soft: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #dbeafe;
  --accent: #0ea5e9;
  --good: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 15px;
}
a { color: var(--brand); text-decoration: none; }

/* ---------- Top bar ---------- */
#topbar, .topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 8px 14px;
  flex-wrap: wrap;                    /* let items drop to a 2nd line instead of overlapping */
  padding: 8px 16px;
  background: linear-gradient(90deg, #0f172a, #1e3a8a);
  color: #fff;
  box-shadow: var(--shadow);
}
#topbar > *, .topbar > * { flex: 0 0 auto; }   /* never squeeze brand / selector / buttons */
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar .brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: radial-gradient(circle at 30% 30%, #60a5fa, #1d4ed8);
  display: inline-block; position: relative;
}
.topbar .brand .logo::after {
  content: ""; position: absolute; inset: 6px;
  border: 2px solid rgba(255,255,255,.7); border-radius: 50%;
}
.topbar .brand small { font-weight: 400; opacity: .85; font-size: 11px; display: block; }
.topnav {
  display: flex; gap: 3px; min-width: 0; max-width: 100%;
  overflow-x: auto;                   /* 12 links scroll horizontally on narrow screens */
  scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 13.5px;
  white-space: nowrap; font-weight: 500;
}
.topnav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topnav a.active { background: rgba(255,255,255,.22); color: #fff; }
.topbar-right {
  display: flex; align-items: center; gap: 8px;
  margin-left: auto;                  /* pins the group to the top-right, level with the nav */
  flex: 0 0 auto;
}
.topbtn {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.08); color: #fff;
  padding: 7px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.topbtn:hover { background: rgba(255,255,255,.2); }
.topbtn.primary { background: #38bdf8; border-color: #38bdf8; color: #06283d; font-weight: 600; }
.langico { font-size: 15px; line-height: 1; }
.langsel {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.45);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer;
  min-width: 96px; font-weight: 500;
}
.langsel option { color: #111; }

/* narrow screens: drop the tagline / mail button to give the nav room */
@media (max-width: 1080px) { .topbar .brand small { display: none; } }
@media (max-width: 860px)  { #btnMail { display: none; } }

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 18px 60px; }
.grid2 { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px){ .grid2 { grid-template-columns: 1fr; } .grid3 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card h2, .card h3 { margin-top: 0; }
.section-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.section-sub { color: var(--muted); margin: 0 0 18px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.btn {
  background: var(--brand); color: #fff; border: none; padding: 10px 16px;
  border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: #e6edf5; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Metric chips ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 12px; margin: 8px 0 16px; }
.metric {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px;
}
.metric .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.metric .v { font-size: 19px; font-weight: 700; margin-top: 3px; }
.metric .u { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---------- Canvas / plots ---------- */
.plot { width: 100%; height: 320px; display: block; background: #fff; }
.plot.small { height: 260px; }
.canvas-box { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background:#fff; }

/* ---------- Home cards ---------- */
.home-hero { text-align: center; padding: 30px 10px 10px; }
.home-hero h1 { font-size: 34px; margin: 0 0 8px; }
.home-hero p { color: var(--ink-soft); max-width: 720px; margin: 0 auto 8px; }
.feature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 22px; }
@media (max-width: 760px){ .feature-grid { grid-template-columns: 1fr; } }
.feature {
  display: block; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.feature:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(15,23,42,.12); }
.feature .ico { font-size: 22px; }
.feature h3 { margin: 8px 0 6px; font-size: 16px; }
.feature p { color: var(--muted); font-size: 13.5px; margin: 0; }
.disclaimer {
  margin-top: 22px; padding: 12px 16px; border-left: 4px solid var(--warn);
  background: #fffbeb; color: #92400e; border-radius: 0 10px 10px 0; font-size: 13.5px;
}

/* ---------- Tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th, table.tbl td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; }
table.tbl th { background: var(--panel-2); }
table.tbl tr:nth-child(even) td { background: #fafcff; }

/* ---------- Misc ---------- */
.note { font-size: 12.5px; color: var(--muted); margin-top: 10px; font-style: italic; }

.jones {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 18px;
  margin: 8px 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
}
.jones .jrow { display: contents; }
.jones .jrow > span { display: block; text-align: center; padding: 4px 0; }
.bigval { font-size: 22px; font-weight: 700; color: #0f172a; }
.tag { display: inline-block; background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 20px; padding: 2px 10px; font-size: 11.5px; font-weight: 600; }
.kvs { font-size: 13.5px; }
.kvs div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px 0 0; }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
canvas { max-width: 100%; }

/* ------------------------- input tooltips --------------------------- */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: 100%; z-index: 60;
  margin-top: 6px; padding: 8px 10px; max-width: 260px;
  background: #0f172a; color: #fff; font-size: 12px; line-height: 1.45;
  border-radius: 6px; box-shadow: 0 6px 18px rgba(15,23,42,.25);
  white-space: normal; pointer-events: none;
}
[data-tip]:hover::before {
  content: ""; position: absolute; left: 12px; top: 100%; z-index: 61;
  margin-top: 1px; border: 5px solid transparent; border-bottom-color: #0f172a;
}
/* --------------------------- print report --------------------------- */
.print-only { display: none; }
@media print {
  body { background: #fff; }
  #topbar, .btnrow, nav, .footer, input, select, label, .note, .muted { }
  #topbar, .btnrow, .footer, .note { display: none !important; }
  .grid2 { display: block; }
  .card { box-shadow: none; border: 1px solid #cbd5e1; break-inside: avoid; }
  .print-only { display: block; margin: 0 0 14px; }
  .print-only table { width: 100%; border-collapse: collapse; font-size: 12px; }
  .print-only td { padding: 4px 8px; border: 1px solid #e2e8f0; }
  .print-only td:first-child { font-weight: 600; background: #f8fafc; width: 42%; }
  canvas { max-width: 100%; box-shadow: none; }
}

/* --------------------- materials legend / refs --------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--ink-soft); }
.lg-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-item i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ref-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.ref-text { color: var(--ink-soft); font-size: 12px; }

/* --------------------- RCWA validation page ------------------------ */
.chkrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 2px; }
.chip { display: inline-block; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 3px 12px; font-size: 12px; color: var(--ink-soft); }
.chip.ok { border-color: #86efac; color: #15803d; background: #f0fdf4; }
.chip.warn { border-color: #fde68a; color: #b45309; background: #fffbeb; }
.chip.bad { border-color: #fca5a5; color: #b91c1c; background: #fef2f2; }
.vsapprox { display: grid; gap: 8px; margin-top: 8px; }
.barrow { display: grid; grid-template-columns: 118px 1fr 92px; gap: 10px; align-items: center; font-size: 12.5px; }
.barrow .bk { color: var(--ink-soft); text-align: right; font-size: 12px; }
.barrow .bv { font-weight: 600; font-variant-numeric: tabular-nums; }
.btrack { height: 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.bfill { height: 100%; border-radius: 6px; transition: width .3s ease; }
.bfill.blue { background: #3b82f6; }
.bfill.green { background: #10b981; }
.delta { margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); }
.delta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.dsep { margin: 0 8px; color: var(--line-strong, #cbd5e1); }
.tablewrap { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 8px; }
.orow { display: grid; grid-template-columns: 44px 1fr 64px 1fr 64px 72px; gap: 8px;
  align-items: center; padding: 5px 12px; font-size: 12px; border-top: 1px solid var(--line); }
.orow:first-child { border-top: none; }
.orow.head { background: var(--panel-2); font-weight: 600; color: var(--ink-soft); font-size: 11.5px; }
.orow .om { font-weight: 600; font-variant-numeric: tabular-nums; }
.orow .ob { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.orow .ofill { display: block; height: 100%; }
.orow .ofill.r { background: #3b82f6; }
.orow .ofill.t { background: #10b981; }
.orow .ov { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.orow .oa { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
