:root {
    --ink: #2b2d42;
    --paper: #edf2f4;
    --accent: #ef233c;
    --muted: #8d99ae;
    --line: rgba(43, 45, 66, 0.16);
    --white: #ffffff;
    --good: #1f9d68;
    --warn: #d08c28;
    --shadow: 0 18px 60px rgba(17, 20, 34, 0.18);
    --mono: "SFMono-Regular", "Roboto Mono", Consolas, monospace;
    --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(43, 45, 66, 0.06) 1px, transparent 1px),
        linear-gradient(0deg, rgba(43, 45, 66, 0.05) 1px, transparent 1px),
        var(--paper);
    background-size: 36px 36px;
    font-family: var(--sans);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
}

.side-rail {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 18px 12px;
    color: var(--paper);
    background: var(--ink);
    border-right: 5px solid var(--accent);
}

.brand {
    display: grid;
    gap: 8px;
    place-items: center;
    color: var(--paper);
    text-decoration: none;
    font-weight: 800;
    font-size: 13px;
    line-height: 1.1;
    text-align: center;
}

.brand img {
    width: 48px;
    height: 48px;
}

.rail-nav {
    display: grid;
    gap: 8px;
}

.rail-button {
    display: grid;
    gap: 6px;
    min-height: 68px;
    place-items: center;
    color: rgba(237, 242, 244, 0.72);
    background: transparent;
    border: 1px solid rgba(237, 242, 244, 0.13);
    border-radius: 8px;
    transition: transform 160ms ease, color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.rail-button:hover,
.rail-button.is-active {
    color: var(--white);
    background: rgba(237, 242, 244, 0.1);
    border-color: rgba(237, 242, 244, 0.35);
    transform: translateY(-1px);
}

.rail-icon,
.mono,
.eyebrow {
    font-family: var(--mono);
    letter-spacing: 0;
    text-transform: uppercase;
}

.rail-icon {
    font-size: 12px;
    color: var(--accent);
}

.rail-foot {
    margin-top: auto;
    display: grid;
    gap: 5px;
    font-size: 11px;
    overflow-wrap: anywhere;
}

.workspace {
    min-width: 0;
    padding: 22px;
}

.topline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 5vw, 56px);
    line-height: 0.94;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 10px;
    font-size: clamp(28px, 4vw, 44px);
    line-height: 1;
    letter-spacing: 0;
}

.sync-box {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-width: 190px;
    padding: 10px 12px;
    color: var(--paper);
    background: var(--ink);
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 12px;
}

.sync-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 4px rgba(31, 157, 104, 0.18);
}

.sync-dot.is-danger {
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(239, 35, 60, 0.2);
}

.alert-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    margin-bottom: 16px;
    padding: 9px 13px;
    color: var(--paper);
    background: var(--ink);
    border-left: 8px solid var(--accent);
    box-shadow: var(--shadow);
}

.alert-strip .mono {
    color: var(--accent);
    font-size: 12px;
}

.alert-strip.is-error {
    border-left-color: var(--warn);
}

.screen {
    display: none;
}

.screen.is-active {
    display: block;
    animation: screenIn 190ms ease-out;
}

@keyframes screenIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.filters-bar {
    display: grid;
    grid-template-columns: minmax(220px, 1.2fr) 170px minmax(300px, 2fr);
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
}

label {
    display: grid;
    gap: 5px;
    color: rgba(43, 45, 66, 0.7);
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
}

input,
select {
    width: 100%;
    min-height: 42px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(239, 35, 60, 0.13);
}

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

.segment,
.task-actions button,
.primary-action {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--ink);
    font-weight: 800;
    transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.segment:hover,
.task-actions button:hover,
.primary-action:hover {
    transform: translateY(-1px);
    border-color: rgba(239, 35, 60, 0.4);
}

.segment.is-active,
.primary-action {
    color: var(--paper);
    background: var(--accent);
    border-color: var(--accent);
}

.ops-grid {
    display: grid;
    grid-template-columns: minmax(420px, 1.28fr) minmax(360px, 0.82fr);
    gap: 14px;
    min-height: calc(100vh - 188px);
}

.map-canvas,
.task-panel,
.stage-board,
.event-log,
.import-view,
.public-layout {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.map-canvas {
    min-height: 560px;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}

.map-header,
.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    min-height: 48px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.map-header .mono,
.panel-head .mono {
    color: var(--accent);
    font-size: 11px;
}

.floor-map {
    position: relative;
    min-height: 500px;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(43, 45, 66, 0.14) 1px, transparent 1px),
        linear-gradient(0deg, rgba(43, 45, 66, 0.14) 1px, transparent 1px),
        linear-gradient(135deg, rgba(141, 153, 174, 0.28), rgba(237, 242, 244, 0.9));
    background-size: 48px 48px, 48px 48px, auto;
}

.floor-map::before {
    content: "";
    position: absolute;
    inset: 10% 8% 15% 10%;
    border: 3px solid rgba(43, 45, 66, 0.52);
    border-left-width: 14px;
    border-bottom-width: 8px;
    border-radius: 8px;
}

.floor-map::after {
    content: "";
    position: absolute;
    inset: 27% 28% 30% 34%;
    border: 2px dashed rgba(43, 45, 66, 0.36);
    border-radius: 8px;
}

.map-gridline {
    position: absolute;
    background: rgba(239, 35, 60, 0.28);
    pointer-events: none;
}

.map-gridline.horizontal {
    left: 8%;
    right: 8%;
    top: 50%;
    height: 2px;
}

.map-gridline.vertical {
    top: 10%;
    bottom: 14%;
    left: 50%;
    width: 2px;
}

.zone-pin {
    position: absolute;
    z-index: 2;
    width: min(170px, 32vw);
    min-height: 78px;
    transform: translate(-50%, -50%);
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    grid-template-areas:
        "code title"
        "code status";
    gap: 3px 8px;
    align-items: center;
    padding: 9px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(43, 45, 66, 0.2);
    border-left: 6px solid var(--muted);
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(43, 45, 66, 0.14);
    text-align: left;
}

.zone-pin:hover {
    transform: translate(-50%, -52%);
}

.zone-pin.status-blocked {
    border-left-color: var(--accent);
}

.zone-pin.status-done {
    border-left-color: var(--good);
}

.zone-pin.status-in_review {
    border-left-color: var(--warn);
}

.pin-code {
    grid-area: code;
    display: grid;
    place-items: center;
    width: 34px;
    height: 48px;
    color: var(--paper);
    background: var(--ink);
    border-radius: 8px 8px 16px 16px;
    font-family: var(--mono);
    font-size: 11px;
}

.zone-pin strong {
    grid-area: title;
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 13px;
}

.zone-pin small {
    grid-area: status;
    color: rgba(43, 45, 66, 0.7);
}

.task-panel {
    min-height: 560px;
    overflow: hidden;
}

.task-list {
    height: calc(100% - 49px);
    max-height: calc(100vh - 238px);
    overflow: auto;
}

.task-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px;
    gap: 10px 12px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.58);
}

.task-item.status-blocked {
    background: linear-gradient(90deg, rgba(239, 35, 60, 0.12), rgba(255, 255, 255, 0.7));
}

.task-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 7px;
}

.task-meta span {
    padding: 3px 6px;
    color: var(--ink);
    background: rgba(141, 153, 174, 0.18);
    border-radius: 999px;
    font-family: var(--mono);
    font-size: 10px;
}

.task-main h3 {
    margin-bottom: 6px;
    font-size: 16px;
    line-height: 1.15;
}

.task-main p {
    margin-bottom: 0;
    color: rgba(43, 45, 66, 0.72);
    font-size: 13px;
    line-height: 1.45;
}

.task-side {
    display: grid;
    justify-items: end;
    align-content: start;
    gap: 6px;
    color: rgba(43, 45, 66, 0.66);
    font-size: 12px;
    text-align: right;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    color: var(--paper);
    background: var(--muted);
    border-radius: 999px;
    font-family: var(--mono);
    font-size: 11px;
    white-space: nowrap;
}

.badge-blocked {
    background: var(--accent);
}

.badge-done {
    background: var(--good);
}

.badge-in_review {
    background: var(--warn);
}

.badge-open {
    background: var(--ink);
}

.task-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
}

.task-actions button {
    min-height: 36px;
    font-size: 12px;
}

.task-actions button:disabled {
    opacity: 0.55;
    cursor: wait;
}

.analytics-layout {
    display: grid;
    grid-template-columns: 230px minmax(320px, 1fr) minmax(300px, 0.8fr);
    gap: 14px;
}

.metric-stack {
    display: grid;
    gap: 10px;
}

.metric {
    min-height: 124px;
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 16px;
    color: var(--paper);
    background: var(--ink);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric:nth-child(1) {
    background: var(--accent);
}

.metric strong {
    font-size: 42px;
    line-height: 1;
}

.metric small {
    color: rgba(237, 242, 244, 0.75);
}

.stage-board,
.event-log {
    overflow: hidden;
}

.stage-row {
    display: grid;
    gap: 8px;
    padding: 15px;
    border-bottom: 1px solid var(--line);
}

.stage-row > div:first-child {
    display: flex;
    justify-content: space-between;
    gap: 14px;
}

.progress {
    height: 10px;
    overflow: hidden;
    background: rgba(141, 153, 174, 0.22);
    border-radius: 999px;
}

.progress span {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: inherit;
    transition: width 220ms ease;
}

.event-row {
    padding: 15px;
    border-bottom: 1px solid var(--line);
}

.event-row h3 {
    margin-bottom: 5px;
    font-size: 15px;
}

.event-row p {
    margin-bottom: 0;
    color: rgba(43, 45, 66, 0.72);
    font-size: 13px;
    line-height: 1.45;
}

.import-view,
.public-layout {
    min-height: 520px;
    display: grid;
    align-content: start;
    gap: 18px;
    padding: 24px;
}

.import-view p,
.public-layout p {
    max-width: 660px;
    color: rgba(43, 45, 66, 0.72);
    line-height: 1.55;
}

.primary-action {
    width: min(260px, 100%);
}

pre {
    margin: 0;
    min-height: 160px;
    overflow: auto;
    padding: 16px;
    color: var(--paper);
    background: var(--ink);
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 13px;
    white-space: pre-wrap;
}

.public-status {
    display: grid;
    gap: 10px;
}

.public-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 280px);
    gap: 18px;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.public-row h3 {
    margin-bottom: 5px;
}

.public-meter {
    display: grid;
    justify-items: end;
    gap: 10px;
}

.public-meter .progress {
    width: 100%;
}

.empty-state {
    padding: 24px;
    color: rgba(43, 45, 66, 0.66);
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: 92px minmax(0, 1fr);
    }

    .filters-bar,
    .ops-grid,
    .analytics-layout {
        grid-template-columns: 1fr;
    }

    .task-list {
        max-height: none;
    }
}

@media (max-width: 720px) {
    .app-shell {
        display: block;
    }

    .side-rail {
        position: static;
        height: auto;
        display: grid;
        grid-template-columns: 92px 1fr;
        padding: 10px;
        border-right: 0;
        border-bottom: 5px solid var(--accent);
    }

    .rail-nav {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .rail-button {
        min-height: 58px;
        font-size: 11px;
    }

    .rail-foot {
        grid-column: 1 / -1;
    }

    .workspace {
        padding: 14px;
    }

    .topline {
        display: grid;
    }

    .sync-box {
        min-width: 0;
        width: 100%;
    }

    .alert-strip {
        align-items: flex-start;
    }

    .segments {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .map-canvas,
    .task-panel {
        min-height: auto;
    }

    .floor-map {
        min-height: 440px;
    }

    .zone-pin {
        width: 145px;
        min-height: 70px;
    }

    .task-item,
    .public-row {
        grid-template-columns: 1fr;
    }

    .task-side,
    .public-meter {
        justify-items: start;
        text-align: left;
    }

    .task-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
