:root {
    --ink: #172522;
    --muted: #687773;
    --line: #d9e2df;
    --line-strong: #bdcbc7;
    --paper: #ffffff;
    --canvas: #f2f5f3;
    --navy: #163934;
    --navy-2: #0e2b27;
    --green: #19845d;
    --green-dark: #106746;
    --green-soft: #e7f5ef;
    --gold: #a86208;
    --gold-soft: #fff4d9;
    --silver: #526671;
    --silver-soft: #eaf0f3;
    --danger: #b33a3a;
    --danger-soft: #fff0f0;
    --warning: #875d0b;
    --warning-soft: #fff8df;
    --blue: #2669a8;
    --shadow: 0 16px 40px rgba(23, 50, 44, .09);
    --radius: 16px;
    --radius-sm: 10px;
    --focus: 0 0 0 3px rgba(43, 145, 107, .25);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
:where(kbd) { background: #edf2f0; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .65rem; padding: .05rem .28rem; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.eyebrow {
    display: block;
    color: var(--green-dark);
    font-size: .73rem;
    font-weight: 800;
    letter-spacing: .13em;
    margin-bottom: .65rem;
}

.muted { color: var(--muted); }
.small { font-size: .83rem; }

.button {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    display: inline-flex;
    font-weight: 720;
    gap: .45rem;
    justify-content: center;
    min-height: 40px;
    padding: .62rem .95rem;
    text-decoration: none;
    transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .52; transform: none; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--paper); border-color: var(--line-strong); color: var(--navy); }
.button.secondary:hover, .button.ghost:hover { background: #edf3f0; }
.button.ghost { background: transparent; border-color: var(--line); color: var(--navy); }
.button.danger { background: var(--danger-soft); border-color: #efbcbc; color: var(--danger); }
.button.small { min-height: 34px; padding: .4rem .72rem; }
.button.wide { width: 100%; }

.alert {
    border: 1px solid;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    line-height: 1.45;
    padding: .75rem .9rem;
}
.alert.error { background: var(--danger-soft); border-color: #efbcbc; color: #8f2929; }
.alert.success { background: var(--green-soft); border-color: #afdcca; color: var(--green-dark); }
.global-alert { margin: 1rem auto 0; max-width: 1180px; }

.login-shell {
    background:
        radial-gradient(circle at 14% 12%, rgba(49, 149, 110, .23), transparent 28rem),
        linear-gradient(135deg, var(--navy-2) 0%, var(--navy) 48%, #235448 100%);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(340px, 470px);
    min-height: 100vh;
    overflow: hidden;
    padding: clamp(2rem, 6vw, 6rem);
    position: relative;
}
.login-shell::after {
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 50%;
    content: "";
    height: 560px;
    position: absolute;
    right: -190px;
    top: -260px;
    width: 560px;
}
.login-brand {
    align-self: center;
    color: white;
    max-width: 670px;
    padding-right: clamp(2rem, 7vw, 7rem);
    position: relative;
    z-index: 1;
}
.login-brand .eyebrow { color: #89dfbd; }
.login-brand h1 { font-size: clamp(2.4rem, 5vw, 4.8rem); letter-spacing: -.045em; line-height: 1.02; margin: 0 0 1.5rem; }
.login-brand > p { color: #c7d8d3; font-size: clamp(1rem, 1.5vw, 1.2rem); line-height: 1.65; max-width: 580px; }
.science-note { align-items: center; border-top: 1px solid rgba(255,255,255,.16); color: #d9e9e4; display: flex; gap: .75rem; margin-top: 2.25rem; padding-top: 1.2rem; }
.status-dot { background: #74e0b5; border-radius: 50%; box-shadow: 0 0 0 5px rgba(116,224,181,.13); height: 9px; width: 9px; }
.login-card {
    align-self: center;
    background: rgba(255,255,255,.98);
    border: 1px solid rgba(255,255,255,.5);
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(2, 18, 15, .28);
    justify-self: end;
    max-width: 470px;
    padding: clamp(1.7rem, 4vw, 2.7rem);
    position: relative;
    width: 100%;
    z-index: 2;
}
.product-mark, .brand-symbol {
    align-items: center;
    background: var(--green);
    border-radius: 11px;
    color: white;
    display: inline-flex;
    font-weight: 850;
    height: 44px;
    justify-content: center;
    letter-spacing: -.04em;
    width: 44px;
}
.login-card h2, .setup-card h1 { font-size: 1.6rem; letter-spacing: -.025em; margin: 1.35rem 0 .35rem; }
.privacy-copy { border-top: 1px solid var(--line); color: var(--muted); font-size: .78rem; margin: 1.5rem 0 0; padding-top: 1rem; text-align: center; }

.stack-form { display: grid; gap: 1rem; margin-top: 1.45rem; }
.stack-form.compact { margin-top: 1rem; }
.stack-form label { color: #34443f; display: grid; font-size: .82rem; font-weight: 720; gap: .42rem; }
input, select, textarea {
    background: white;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    color: var(--ink);
    min-height: 42px;
    padding: .62rem .72rem;
    width: 100%;
}
textarea { line-height: 1.5; min-height: 100px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #94aaa4; }
input:focus, select:focus, textarea:focus { border-color: var(--green); outline: none; box-shadow: var(--focus); }
.two-columns { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; }

.topbar {
    align-items: center;
    background: rgba(255,255,255,.97);
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 1.5rem;
    grid-template-columns: minmax(245px, 1fr) auto minmax(245px, 1fr);
    min-height: 72px;
    padding: .65rem clamp(1rem, 3vw, 2.5rem);
    position: sticky;
    top: 0;
    z-index: 30;
}
.brand { align-items: center; display: inline-flex; gap: .72rem; text-decoration: none; width: max-content; }
.brand-symbol { height: 38px; width: 38px; }
.brand strong, .brand small, .account-name small { display: block; }
.brand strong { color: var(--navy); font-size: .95rem; }
.brand small, .account-name small { color: var(--muted); font-size: .7rem; margin-top: .1rem; }
.main-nav { align-items: center; display: flex; gap: .35rem; }
.main-nav a { border-radius: 8px; color: var(--muted); font-size: .86rem; font-weight: 720; padding: .6rem .85rem; text-decoration: none; }
.main-nav a:hover { background: #eef3f1; color: var(--ink); }
.main-nav a.active { background: var(--green-soft); color: var(--green-dark); }
.account { align-items: center; display: flex; gap: .65rem; justify-content: flex-end; }
.reviewer-badge { background: var(--navy); border-radius: 7px; color: white; font-size: .72rem; font-weight: 820; letter-spacing: .06em; padding: .4rem .55rem; }
.account-name { font-size: .8rem; font-weight: 700; line-height: 1.2; }
.account-name { text-decoration: none; }

.content-shell { margin: 0 auto; max-width: 1240px; padding: clamp(1.5rem, 4vw, 3.3rem) clamp(1rem, 3vw, 2rem) 5rem; }
.page-heading { align-items: end; display: flex; gap: 2rem; justify-content: space-between; margin-bottom: 2rem; }
.page-heading h1 { color: var(--navy); font-size: clamp(1.85rem, 3vw, 2.65rem); letter-spacing: -.04em; margin: 0; }
.page-heading > p { color: var(--muted); line-height: 1.55; margin: 0 0 .2rem; max-width: 510px; }

.project-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.project-card, .panel, .metric-card, .empty-state {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 26px rgba(25,55,48,.045);
}
.project-card { padding: 1.35rem; }
.project-card-top, .progress-row, .project-actions, .panel-heading { align-items: center; display: flex; justify-content: space-between; }
.project-card h2 { font-size: 1.15rem; letter-spacing: -.02em; margin: 1.25rem 0 .18rem; }
.project-code { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .76rem; margin: 0 0 1.5rem; }
.status-text { color: var(--muted); font-size: .75rem; }
.mode-chip { border-radius: 999px; display: inline-flex; font-size: .67rem; font-weight: 850; letter-spacing: .06em; padding: .38rem .58rem; text-transform: uppercase; }
.mode-chip.gold { background: var(--gold-soft); color: var(--gold); }
.mode-chip.silver { background: var(--silver-soft); color: var(--silver); }
.progress-row { font-size: .8rem; margin-bottom: .45rem; }
.progress-row span { color: var(--muted); }
.progress-track { background: #e8eeeb; border-radius: 999px; height: 8px; overflow: hidden; }
.progress-track progress { appearance: none; border: 0; display: block; height: 100%; width: 100%; }
.progress-track progress::-webkit-progress-bar { background: #e8eeeb; }
.progress-track progress::-webkit-progress-value { background: var(--green); border-radius: 999px; }
.progress-track progress::-moz-progress-bar { background: var(--green); border-radius: 999px; }
.project-actions { gap: .55rem; justify-content: flex-start; margin-top: 1.35rem; }
.empty-state { grid-column: 1 / -1; padding: 4rem 2rem; text-align: center; }
.empty-icon { align-items: center; background: var(--green-soft); border-radius: 50%; color: var(--green); display: inline-flex; font-size: 1.4rem; height: 54px; justify-content: center; width: 54px; }
.empty-state h2 { margin-bottom: .35rem; }
.empty-state p { color: var(--muted); margin-top: 0; }

.admin-grid { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.panel { padding: 1.25rem; }
.panel-heading { border-bottom: 1px solid var(--line); margin: -1.25rem -1.25rem 1rem; padding: 1rem 1.25rem; }
.panel-heading > div { align-items: center; display: flex; gap: .65rem; }
.panel-heading h2 { font-size: 1rem; margin: 0; }
.step-number { align-items: center; background: var(--green-soft); border-radius: 7px; color: var(--green-dark); display: inline-flex; font-size: .72rem; font-weight: 850; height: 28px; justify-content: center; width: 28px; }
.science-warning { background: var(--warning-soft); border: 1px solid #ead89e; border-radius: 9px; color: var(--warning); font-size: .8rem; line-height: 1.45; padding: .7rem .8rem; }
.metric-grid { display: grid; gap: .8rem; grid-template-columns: repeat(3, 1fr); margin-bottom: 1rem; }
.metric-card { padding: 1.05rem 1.2rem; }
.metric-card span { color: var(--muted); display: block; font-size: .76rem; }
.metric-card strong { color: var(--navy); display: block; font-size: 1.65rem; margin-top: .15rem; }
.table-panel, .task-list-panel { margin-top: 1rem; }
.import-panel { margin-top: 1rem; }
.import-form { align-items: end; display: grid; gap: .75rem; grid-template-columns: 1fr 1fr 1.15fr 1.45fr auto; }
.import-form label { color: #34443f; display: grid; font-size: .75rem; font-weight: 720; gap: .35rem; }
.import-form input, .import-form select { font-size: .76rem; min-height: 40px; }
.form-note { color: var(--muted); font-size: .75rem; line-height: 1.45; margin: .75rem 0 0; }
.profile-panel { margin: 0 auto; max-width: 560px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; font-size: .82rem; width: 100%; }
.export-form { align-items: center; display: flex; gap: .35rem; min-width: 290px; }
.export-form select { font-size: .72rem; min-height: 34px; padding: .3rem; }
th { color: var(--muted); font-size: .7rem; letter-spacing: .05em; text-align: left; text-transform: uppercase; }
th, td { border-bottom: 1px solid var(--line); padding: .75rem .6rem; }
td small { color: var(--muted); display: block; margin-top: .16rem; }
.empty-cell { color: var(--muted); padding: 2rem; text-align: center; }
.task-list { display: grid; }
.task-row { align-items: center; border-bottom: 1px solid var(--line); display: grid; gap: .8rem; grid-template-columns: 52px 1fr auto; padding: .7rem .4rem; text-decoration: none; }
.task-row:hover { background: #f5f8f7; }
.task-order { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.task-row small { color: var(--muted); display: block; font-size: .72rem; }
.task-status { border-radius: 999px; font-size: .69rem; font-weight: 760; padding: .34rem .55rem; }
.task-status.completed { background: var(--green-soft); color: var(--green-dark); }
.task-status.in_progress, .task-status.reopened { background: #e8f1fb; color: var(--blue); }
.task-status.pending { background: #edf0ef; color: var(--muted); }

.annotator-shell { height: calc(100vh - 72px); min-height: 540px; }
.loading-panel { align-items: center; display: flex; flex-direction: column; height: 100%; justify-content: center; text-align: center; }
.loading-panel h1 { font-size: 1.2rem; margin: 1rem 0 .25rem; }
.loading-panel p { color: var(--muted); margin: 0; }
.spinner { animation: spin .8s linear infinite; border: 3px solid #d8e5e0; border-radius: 50%; border-top-color: var(--green); height: 34px; width: 34px; }
@keyframes spin { to { transform: rotate(360deg); } }

.annotation-layout { display: grid; grid-template-columns: minmax(0, 1fr) 390px; height: 100%; }
.viewer-column { background: #19211f; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; }
.annotation-header { align-items: center; background: #101715; border-bottom: 1px solid #33403d; color: white; display: flex; gap: 1rem; justify-content: space-between; min-height: 59px; padding: .65rem 1rem; }
.annotation-title { align-items: center; display: flex; gap: .7rem; min-width: 0; }
.annotation-title h1 { font-size: .94rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.annotation-title p { color: #9eafaa; font-size: .7rem; margin: .14rem 0 0; }
.annotation-actions { align-items: center; display: flex; gap: .45rem; }
.save-state { color: #aab9b5; font-size: .72rem; white-space: nowrap; }
.save-state.saved { color: #75dcb4; }
.save-state.error { color: #ff9d9d; }
.dark-button { background: #26322f; border: 1px solid #43514d; color: #e7efec; }
.dark-button:hover { background: #34423e; }

.canvas-stage { align-items: center; display: flex; justify-content: center; min-height: 0; overflow: auto; position: relative; touch-action: none; }
.canvas-stage.panning { cursor: grabbing; }
.canvas-stage canvas { background: #111; box-shadow: 0 12px 36px rgba(0,0,0,.28); display: block; flex: none; image-rendering: auto; }
.canvas-stage canvas.draw-mode { cursor: crosshair; }
.canvas-stage canvas.select-mode { cursor: default; }
.viewer-toolbar { align-items: center; background: #101715; border-top: 1px solid #33403d; color: #d2ddda; display: flex; gap: .4rem; min-height: 50px; padding: .45rem .75rem; }
.viewer-toolbar .spacer { flex: 1; }
.toolbar-button { background: #26322f; border: 1px solid #43514d; border-radius: 7px; color: #e8efed; cursor: pointer; min-height: 34px; padding: .35rem .58rem; }
.toolbar-button:hover { background: #36433f; }
.toolbar-button.active { background: #174d3d; border-color: #2f8e6b; }
.toolbar-button:disabled { opacity: .38; }
.zoom-label { color: #9fb0ab; font-size: .7rem; min-width: 44px; text-align: center; }
.shortcut-hint { color: #849690; font-size: .68rem; }

.inspector { background: var(--paper); border-left: 1px solid var(--line); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; }
.inspector-top { border-bottom: 1px solid var(--line); padding: .85rem 1rem; }
.inspector-progress { align-items: center; display: flex; justify-content: space-between; }
.inspector-progress strong { font-size: .78rem; }
.inspector-progress span { color: var(--muted); font-size: .72rem; }
.mini-progress { appearance: none; border: 0; border-radius: 999px; height: 6px; margin-top: .55rem; overflow: hidden; width: 100%; }
.mini-progress::-webkit-progress-bar { background: #e8eeeb; }
.mini-progress::-webkit-progress-value { background: var(--green); }
.mini-progress::-moz-progress-bar { background: var(--green); }
.inspector-scroll { min-height: 0; overflow-y: auto; padding: 1rem; }
.tool-section { border-bottom: 1px solid var(--line); margin-bottom: 1rem; padding-bottom: 1rem; }
.tool-section:last-child { border-bottom: 0; margin-bottom: 0; }
.section-label { color: var(--muted); display: block; font-size: .67rem; font-weight: 850; letter-spacing: .08em; margin-bottom: .65rem; text-transform: uppercase; }
.tool-grid { display: grid; gap: .45rem; grid-template-columns: 1fr 1fr; }
.tool-grid .wide { grid-column: 1 / -1; }
.tool-button { background: white; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink); cursor: pointer; font-size: .78rem; font-weight: 680; min-height: 39px; padding: .48rem .55rem; }
.tool-button:hover { background: #f1f6f4; border-color: #96aaa4; }
.tool-button.active { background: var(--green-soft); border-color: #6bb89a; color: var(--green-dark); }
.tool-button.danger { color: var(--danger); }
.tool-button:disabled { cursor: not-allowed; opacity: .45; }
.auto-block { background: var(--gold-soft); border: 1px solid #ead39a; border-radius: 9px; color: #79500d; font-size: .76rem; line-height: 1.4; padding: .7rem; }
.auto-block strong { display: block; margin-bottom: .18rem; }
.instance-header { align-items: center; display: flex; justify-content: space-between; margin-bottom: .6rem; }
.instance-header .section-label { margin: 0; }
.instance-count { background: var(--navy); border-radius: 999px; color: white; font-size: .67rem; font-weight: 800; padding: .25rem .48rem; }
.instance-list { display: grid; gap: .35rem; max-height: 180px; overflow-y: auto; }
.instance-item { align-items: center; background: #f5f7f6; border: 1px solid transparent; border-radius: 8px; cursor: pointer; display: grid; gap: .55rem; grid-template-columns: 25px 1fr auto; min-height: 42px; padding: .42rem .55rem; text-align: left; width: 100%; }
.instance-item:hover { background: #eef4f1; }
.instance-item.selected { background: var(--green-soft); border-color: #85c8ad; }
.instance-number { align-items: center; background: white; border: 1px solid var(--line); border-radius: 6px; display: flex; font-size: .67rem; font-weight: 800; height: 24px; justify-content: center; }
.instance-item strong { display: block; font-size: .76rem; }
.instance-item small { color: var(--muted); display: block; font-size: .64rem; }
.decision-dot { border-radius: 50%; height: 8px; width: 8px; }
.decision-dot.added { background: var(--green); }
.decision-dot.accepted { background: var(--blue); }
.decision-dot.boundary_edit { background: var(--gold); }
.empty-instances { border: 1px dashed var(--line-strong); border-radius: 8px; color: var(--muted); font-size: .75rem; line-height: 1.45; padding: .85rem; text-align: center; }
.attribute-grid { display: grid; gap: .55rem; grid-template-columns: 1fr 1fr; margin-top: .7rem; }
.attribute-grid label { color: var(--muted); font-size: .68rem; font-weight: 700; }
.attribute-grid select { font-size: .75rem; margin-top: .3rem; min-height: 37px; padding: .4rem; }
.notes-field { font-size: .78rem; min-height: 76px; }
.review-check { align-items: flex-start; background: #f4f7f5; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; display: flex; font-size: .76rem; font-weight: 680; gap: .55rem; line-height: 1.4; padding: .7rem; }
.review-check input { flex: none; height: 18px; margin: .05rem 0 0; min-height: 0; width: 18px; }
.inspector-footer { background: #fafcfb; border-top: 1px solid var(--line); display: grid; gap: .45rem; grid-template-columns: 1fr 1fr; padding: .75rem 1rem; }
.inspector-footer .wide { grid-column: 1 / -1; }
.status-message { align-items: center; background: #eaf3ef; border-radius: 8px; color: #355d4e; display: flex; font-size: .72rem; grid-column: 1 / -1; min-height: 32px; padding: .45rem .65rem; }
.status-message.error { background: var(--danger-soft); color: var(--danger); }
.status-message.warning { background: var(--warning-soft); color: var(--warning); }

.setup-shell { align-items: center; background: var(--navy); display: flex; justify-content: center; min-height: 100vh; padding: 2rem; }
.setup-card { justify-self: auto; }
.setup-card code { background: #edf1ef; border-radius: 4px; padding: .1rem .3rem; }

@media (max-width: 980px) {
    .topbar { grid-template-columns: 1fr auto; }
    .main-nav { display: none; }
    .annotation-layout { grid-template-columns: minmax(0, 1fr) 340px; }
    .admin-grid { grid-template-columns: 1fr; }
    .import-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
    .login-shell { grid-template-columns: 1fr; padding: 1rem; }
    .login-brand { display: none; }
    .login-card { justify-self: center; }
    .topbar { min-height: 64px; padding: .55rem .75rem; }
    .brand small, .account-name { display: none; }
    .annotation-layout { display: block; height: auto; }
    .annotator-shell { height: auto; }
    .viewer-column { height: 62vh; min-height: 430px; }
    .inspector { border-left: 0; min-height: 620px; }
    .inspector-scroll { max-height: none; }
    .page-heading { align-items: start; flex-direction: column; gap: .75rem; }
    .project-grid, .metric-grid { grid-template-columns: 1fr; }
    .two-columns { grid-template-columns: 1fr; }
    .project-actions { align-items: stretch; flex-direction: column; }
    .annotation-header { align-items: flex-start; flex-direction: column; }
    .annotation-actions { width: 100%; }
    .annotation-actions .save-state { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
    .spinner { animation-duration: 1.8s; }
}
