/* Auto Piping Design — light Fluent (Windows 11) style theme. */
:root {
    --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
    --bg: #f3f3f3;
    --surface: #ffffff;
    --surface-alt: #fafafa;
    --surface-hover: #f5f5f5;
    --stroke: #e0e0e0;
    --stroke-strong: #d1d1d1;
    --text: #242424;
    --text-2: #616161;
    --text-3: #8a8a8a;
    --brand: #0f6cbd;
    --brand-hover: #115ea3;
    --brand-pressed: #0c3b5e;
    --brand-tint: #ebf3fc;
    --success: #107c10;
    --success-tint: #f1faf1;
    --warning: #bc4b09;
    --warning-tint: #fff9f5;
    --danger: #c50f1f;
    --danger-tint: #fdf3f4;
    --radius: 6px;
    --radius-lg: 8px;
    --shadow-2: 0 1px 2px rgba(0,0,0,.12), 0 0 2px rgba(0,0,0,.10);
    --shadow-8: 0 4px 8px rgba(0,0,0,.12), 0 0 2px rgba(0,0,0,.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 20px; }
h1 { font-size: 24px; line-height: 32px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 18px; line-height: 24px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 15px; line-height: 20px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; line-height: 16px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { height: 16px; }

/* ---- shell ---- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; height: 48px; padding: 0 20px;
          background: var(--surface); border-bottom: 1px solid var(--stroke); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--brand); white-space: nowrap; }
.brand span { color: var(--text); }
.tabs { display: flex; gap: 4px; height: 100%; }
.tab { display: flex; align-items: center; padding: 0 12px; color: var(--text-2); border-bottom: 3px solid transparent; font-weight: 500; }
.tab:hover { color: var(--text); text-decoration: none; background: var(--surface-hover); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user form { margin: 0; }
.content { flex: 1; padding: 20px 24px 40px; max-width: 1680px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .grow { min-width: 200px; }

/* ---- cards ---- */
.card { background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); padding: 16px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius-lg); padding: 14px 16px; box-shadow: var(--shadow-2); }
.stat .label { color: var(--text-2); font-size: 12px; }
.stat .value { font-size: 26px; line-height: 34px; font-weight: 600; }
.stat .sub { color: var(--text-3); font-size: 12px; }

/* ---- buttons & inputs ---- */
.btn { font: inherit; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius);
       border: 1px solid var(--stroke-strong); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--surface-hover); border-color: #c7c7c7; text-decoration: none; }
.btn:active { background: #e0e0e0; }
.btn:disabled { color: #bdbdbd; background: #f0f0f0; border-color: #e0e0e0; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.primary:active { background: var(--brand-pressed); }
.btn.primary:disabled { background: #e0e0e0; color: #bdbdbd; }
.btn.subtle { border-color: transparent; background: transparent; font-weight: 500; }
.btn.subtle:hover { background: var(--surface-hover); }
.btn.danger { color: var(--danger); }
.btn.small { height: 24px; padding: 0 8px; font-size: 12px; font-weight: 500; }
.btn.icon { width: 28px; padding: 0; justify-content: center; height: 28px; }
input[type=text], input[type=password], input[type=number], input:not([type]), select, textarea {
    font: inherit; height: 32px; padding: 0 10px; border: 1px solid var(--stroke-strong); border-bottom-color: #8a8a8a; border-radius: var(--radius);
    background: var(--surface); color: var(--text); min-width: 0; }
textarea { height: auto; padding: 6px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-bottom: 2px solid var(--brand); }
input.compact, select.compact { height: 26px; padding: 0 6px; font-size: 13px; }
input.num { width: 92px; text-align: right; }
input.num-s { width: 64px; text-align: right; }
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
label.field > span { color: var(--text); }
label.check { display: inline-flex; align-items: center; gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* ---- badges & messages ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 12px; font-weight: 600;
         background: #f0f0f0; color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--success-tint); color: var(--success); border: 1px solid #9fd89f; }
.badge.warn { background: var(--warning-tint); color: var(--warning); border: 1px solid #fdcfb4; }
.badge.bad { background: var(--danger-tint); color: var(--danger); border: 1px solid #eeacb2; }
.badge.info { background: var(--brand-tint); color: var(--brand); border: 1px solid #b4d6fa; }
.msg { border-radius: var(--radius); padding: 10px 12px; border: 1px solid; margin-bottom: 12px; }
.msg.ok { background: var(--success-tint); border-color: #9fd89f; }
.msg.warn { background: var(--warning-tint); border-color: #fdcfb4; }
.msg.bad { background: var(--danger-tint); border-color: #eeacb2; }
.msg.info { background: var(--brand-tint); border-color: #b4d6fa; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.checks li { display: flex; gap: 8px; align-items: baseline; }
.checks .Pass::before { content: "✓"; color: var(--success); font-weight: 700; }
.checks .Warning::before { content: "!"; color: var(--warning); font-weight: 700; width: 10px; text-align: center; }
.checks .Error::before { content: "✕"; color: var(--danger); font-weight: 700; }

/* ---- tables ---- */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--stroke); white-space: nowrap; }
table.grid td { padding: 6px 8px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
table.grid tr:hover td { background: var(--surface-alt); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: #e8e8e8; overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--brand); }
.bar.ok > div { background: var(--success); }

/* ---- drop zone ---- */
.drop { position: relative; border: 2px dashed #b4d6fa; border-radius: var(--radius-lg); background: var(--brand-tint); padding: 36px 20px; text-align: center; transition: background .15s; }
.drop:hover, .drop.over { background: #dcebfb; border-color: var(--brand); }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.drop .big { font-size: 16px; font-weight: 600; color: var(--brand); }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #eef4fb, #f3f3f3); }
.login { width: 360px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-8); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { font-size: 16px; margin-bottom: 4px; }

/* ---- review ---- */
.review { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(520px, 1.15fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .review { grid-template-columns: 1fr; } }
.viewer { position: sticky; top: 64px; }
.viewer-frame { height: calc(100vh - 170px); min-height: 420px; overflow: auto; background: #e9e9e9; border-radius: var(--radius); border: 1px solid var(--stroke); }
.viewer-frame img { display: block; transform-origin: 0 0; user-select: none; }
.editor section { border-top: 1px solid var(--stroke); padding-top: 12px; margin-top: 12px; }
.editor section:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.leg { border: 1px solid var(--stroke); border-radius: var(--radius); padding: 8px; background: var(--surface-alt); }
.leg + .leg { margin-top: 6px; }
.leg-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.leg-no { font-weight: 700; color: var(--text-2); width: 22px; }
.item { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 6px 8px; margin: 6px 0 0 28px; background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius); }
.item .kind { font-weight: 600; font-size: 12px; color: var(--brand); width: 84px; }
.bend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0 0 28px; font-size: 13px; }
.tag { font-size: 11px; color: var(--text-3); }
.pill-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.pill-tabs button { font: inherit; border: 1px solid var(--stroke-strong); background: var(--surface); border-radius: 14px; padding: 2px 12px; cursor: pointer; }
.pill-tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.iso { width: 100%; height: 340px; background: #fcfcfc; border: 1px solid var(--stroke); border-radius: var(--radius); }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 4px; border-top: 1px solid var(--stroke); margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Blazor ---- */
#blazor-error-ui { color-scheme: light only; background: #fff4ce; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); box-sizing: border-box; display: none; left: 0; padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: var(--danger-tint); padding: 1rem; color: var(--danger); border-radius: var(--radius); }
.blazor-error-boundary::after { content: "An error has occurred." }
.valid.modified:not([type=checkbox]) { outline: none; }

/* ---- Review / Learning additions ---- */
.editor h4 { margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.stats { margin-bottom: 16px; }
.version-tag { font-size: 11px; font-weight: 400; color: var(--text-3); margin-left: 4px; }

/* ---- API credit and drawing cost (changelog 16) ---- */
.credit { font-size: 12px; padding: 3px 10px; border-radius: 12px; text-decoration: none; white-space: nowrap; border: 1px solid transparent; }
.credit.ok { background: #dff6dd; color: #0e700e; border-color: #9fd89f; }
.credit.warn { background: #fff4ce; color: #8a5300; border-color: #f2d27a; }
.credit.bad { background: #fde7e9; color: #b10e1c; border-color: #eeacb2; }
.credit.none { background: var(--surface-alt); color: var(--text-2); border-color: var(--stroke); }
.credit:hover { filter: brightness(0.97); text-decoration: none; }
.cost-line { display: block; font-size: 12px; color: var(--text-2); margin-top: 4px; }
.cost-line strong { color: var(--text-1, #242424); }
.credit-line { display: block; font-size: 12px; margin-top: 2px; }
.credit-line.warn { color: #8a5300; }
.credit-line.bad { color: #b10e1c; }
