:root {
    --bg: #f3f6f4;
    --panel: rgba(255, 255, 255, 0.92);
    --panel-strong: #ffffff;
    --ink: #17232a;
    --muted: #66747d;
    --border: #d5dfdf;
    --shadow: 0 10px 26px rgba(24, 32, 40, 0.06);
    --accent: #286a62;
    --accent-soft: #e0f0eb;
    --blueprint: #2b6f91;
    --danger: #a27712;
    --danger-soft: #f8efc9;
    --standard: #eef2f5;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        linear-gradient(rgba(43, 111, 145, 0.022) 1px, transparent 1px),
        linear-gradient(90deg, rgba(43, 111, 145, 0.022) 1px, transparent 1px),
        linear-gradient(180deg, #fbfcfa 0%, var(--bg) 100%);
    background-size: 24px 24px, 24px 24px, auto;
}

button,
input,
select,
textarea {
    font: inherit;
}

.page-shell {
    width: min(1600px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 18px 0 24px;
}

.hero,
.legend,
.district-column,
.modal-card {
    backdrop-filter: blur(16px);
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.hero {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 10px;
}

.hero-copy-block {
    display: grid;
    gap: 4px;
}

.eyebrow,
.lane-kicker {
    margin: 0 0 6px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    font-weight: 600;
}

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

h1 {
    margin-bottom: 0;
    font-size: clamp(1.35rem, 2.4vw, 1.95rem);
    line-height: 1;
    letter-spacing: -0.03em;
}

.hero-copy {
    max-width: 56ch;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.hero-actions,
.modal-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.hero-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.button,
.icon-button {
    border: 0;
    cursor: pointer;
    transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.button {
    padding: 9px 12px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    box-shadow: none;
    font-weight: 600;
    font-size: 0.88rem;
}

.button:hover,
.icon-button:hover {
    transform: translateY(-1px);
}

.button:focus-visible,
.icon-button:focus-visible,
.drag-handle:focus-visible,
.text-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(43, 111, 145, 0.28);
    outline-offset: 2px;
}

.button:disabled,
.icon-button:disabled {
    cursor: wait;
    opacity: 0.58;
    transform: none;
}

.button-secondary {
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    border: 1px solid var(--border);
}

.button-small {
    width: 100%;
    padding: 10px 14px;
    margin-top: 8px;
    font-size: 0.95rem;
}

.legend {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    border-radius: 14px;
    padding: 8px 10px;
    margin-bottom: 12px;
}

.legend-hint {
    align-self: center;
    margin-left: auto;
    color: var(--muted);
    font-size: 0.78rem;
}

.export-title {
    display: none;
}

.legend-pill,
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 0.78rem;
    font-weight: 600;
}

.legend-needs,
.badge-needs-attention .status-badge {
    background: var(--danger-soft);
    color: #7b5a10;
}

.legend-strong,
.badge-strong-family .status-badge {
    background: var(--accent-soft);
    color: #184f56;
}

.district-grid {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    overflow-x: auto;
    padding: 2px 0 8px;
    scroll-behavior: smooth;
    scrollbar-color: #b8c6c8 transparent;
}

.diagram-grid {
    flex-wrap: nowrap;
}

.district-column {
    border-radius: 16px;
    padding: 10px;
    min-width: fit-content;
    width: fit-content;
    flex: 0 0 auto;
    max-width: 100%;
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.district-column-unassigned {
    background: #fcfbf7;
}

.lane-header,
.district-header,
.pod-header,
.card-topline,
.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: start;
}

.count {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: #f2f5f7;
    border: 1px solid transparent;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
}

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

.pod-card {
    border-radius: 12px;
    background: #fbfcfd;
    border: 1px solid #e6ebef;
    padding: 8px 8px 4px;
    position: relative;
    width: max-content;
    min-width: 100%;
    max-width: none;
    overflow: visible;
}

.pod-card-unassigned {
    background: #fffdfa;
}

.family-list {
    display: grid;
    gap: 0;
    min-height: 40px;
    padding: 4px 2px 2px;
    width: 100%;
    overflow: visible;
    position: relative;
    isolation: isolate;
}

.dropzone.is-target {
    outline: 2px dashed rgba(40, 106, 98, 0.44);
    outline-offset: 4px;
    background: rgba(224, 240, 235, 0.52);
    border-radius: 8px;
}

.household-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 6px 7px 4px;
    border-top: 1px solid #edf1f4;
    background: transparent;
    transition: background 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
    min-width: 100%;
    width: 100%;
    position: relative;
    overflow: visible;
    z-index: 0;
}

.household-row:first-child {
    border-top: 0;
}

.household-row:hover {
    background: #f7f9fb;
    opacity: 0.96;
    z-index: 20;
}

.household-row:focus-within {
    z-index: 20;
}

.household-row:has(.household-name-wrap:hover) {
    z-index: 30;
}

.household-row.is-dragging {
    position: fixed;
    z-index: 1000;
    margin: 0;
    border: 1px solid rgba(43, 111, 145, 0.3);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 16px 38px rgba(23, 35, 42, 0.22);
    opacity: 0.96;
    pointer-events: none;
    transform: rotate(0.7deg);
}

.household-row.is-saving {
    opacity: 0.62;
}

.drag-placeholder {
    margin: 2px 0;
    border: 1px dashed rgba(43, 111, 145, 0.52);
    border-radius: 8px;
    background: rgba(43, 111, 145, 0.08);
}

.drag-in-progress,
.drag-in-progress * {
    cursor: grabbing !important;
    user-select: none !important;
}

.household-row-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
}

.drag-handle {
    display: grid;
    grid-template-columns: repeat(2, 2px);
    grid-template-rows: repeat(3, 2px);
    gap: 3px;
    width: 24px;
    min-width: 24px;
    height: 28px;
    place-content: center;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    cursor: grab;
    touch-action: none;
}

.drag-handle:hover {
    background: #edf3f4;
}

.drag-handle span {
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: #8b9ba2;
}

.household-name-wrap {
    position: relative;
    min-width: 0;
    overflow: visible;
    z-index: 30;
}

.household-name {
    font-size: 0.93rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-tooltip {
    position: absolute;
    left: 0;
    bottom: calc(100% + 6px);
    z-index: 200;
    min-width: 220px;
    max-width: 320px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #182028;
    color: #fff;
    box-shadow: 0 10px 24px rgba(24, 32, 40, 0.16);
    font-size: 0.82rem;
    line-height: 1.35;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 120ms ease, transform 120ms ease;
}

.household-name-wrap:hover .note-tooltip,
.household-name-wrap:focus-within .note-tooltip {
    opacity: 1;
    transform: translateY(0);
}

.household-name-wrap .note-tooltip:empty {
    display: none;
}

.badge-needs-attention {
    background: #fffdf4;
}

.badge-strong-family {
    background: #f7fbf9;
}

.badge-standard {
    background: transparent;
}

.status-badge {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    min-width: 18px;
    border-radius: 999px;
    padding: 0;
    background: #e9eef2;
}

.badge-standard .status-badge {
    display: none;
}

.badge-needs-attention .status-badge {
    background: #ead78d;
    color: #6a4d0e;
}

.badge-strong-family .status-badge {
    background: #cfe5da;
    color: #245847;
}

.badge-icon {
    font-size: 0.72rem;
    line-height: 1;
}

.badge-label {
    display: none;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.note-indicator {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: #eef2f5;
    color: #596574;
    font-size: 0.8rem;
    line-height: 1;
}

.note-indicator.is-hidden {
    visibility: hidden;
}

input,
select,
textarea {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    padding: 10px 11px;
    color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(43, 111, 145, 0.64);
}

textarea {
    resize: vertical;
}

.icon-button {
    width: 22px;
    height: 22px;
    border-radius: 8px;
    background: #f5f7f8;
    color: var(--muted);
}


.danger-button:hover {
    background: var(--danger-soft);
    color: #7d3524;
}

.row-edit-button {
    opacity: 0;
    pointer-events: none;
    width: 18px;
    height: 18px;
    font-size: 0.66rem;
}

.logout-form {
    display: flex;
    margin: 0;
}

.text-button {
    padding: 8px 4px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
}

.text-button:hover {
    color: var(--ink);
}

.household-row:hover .row-edit-button,
.household-row:focus-within .row-edit-button {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    border: 0;
    padding: 0;
    background: transparent;
}

.modal::backdrop {
    background: rgba(19, 24, 31, 0.24);
    backdrop-filter: blur(6px);
}

.modal-card {
    width: min(560px, calc(100vw - 24px));
    border-radius: 18px;
    padding: 20px;
}

.modal-actions-split {
    justify-content: space-between;
}

.button-danger {
    background: var(--danger);
}

.toast-region {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 2000;
    display: grid;
    gap: 8px;
    pointer-events: none;
}

.toast {
    max-width: min(380px, calc(100vw - 36px));
    padding: 11px 14px;
    border: 1px solid rgba(23, 35, 42, 0.12);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(23, 35, 42, 0.16);
    font-size: 0.86rem;
    font-weight: 600;
    animation: toast-in 180ms ease-out;
}

.toast-error {
    border-color: #ddc89b;
    background: #fffaf0;
    color: #74510b;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

.export-render {
    position: fixed;
    top: 0;
    left: -100000px;
    z-index: -1;
    width: max-content;
    min-width: max-content;
    padding: 28px;
    background: var(--bg);
}

.export-render .export-title {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 40px;
    padding: 0 2px 16px;
}

.export-render .export-title h1,
.export-render .export-title p {
    margin-bottom: 0;
}

.export-render .export-title > p {
    color: var(--muted);
    font-size: 0.8rem;
}

.export-render .legend {
    width: 100%;
}

.export-render .district-grid {
    width: max-content;
    overflow: visible;
    padding-bottom: 0;
}

.export-render .district-column {
    box-shadow: none;
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.login-shell {
    width: min(440px, calc(100vw - 32px));
    padding: 32px 0;
}

.login-card {
    position: relative;
    overflow: hidden;
    padding: 34px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 24px 70px rgba(23, 35, 42, 0.11);
}

.login-card::before {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--blueprint), var(--accent));
    content: "";
}

.login-mark {
    display: flex;
    align-items: end;
    gap: 4px;
    height: 28px;
    margin-bottom: 22px;
}

.login-mark span {
    width: 7px;
    border-radius: 2px 2px 0 0;
    background: var(--blueprint);
}

.login-mark span:nth-child(1) { height: 14px; opacity: 0.48; }
.login-mark span:nth-child(2) { height: 22px; opacity: 0.72; }
.login-mark span:nth-child(3) { height: 28px; }

.login-copy {
    margin: 12px 0 24px;
    color: var(--muted);
    line-height: 1.5;
}

.login-form {
    display: grid;
    gap: 10px;
}

.login-form label {
    font-size: 0.82rem;
    font-weight: 700;
}

.login-form .button {
    margin-top: 4px;
    padding: 11px 14px;
}

.form-error {
    margin: -6px 0 18px;
    padding: 10px 12px;
    border: 1px solid #ead7a9;
    border-radius: 9px;
    background: #fff9e9;
    color: #75530f;
    font-size: 0.84rem;
}

@media (max-width: 1080px) {
    .district-column {
        min-width: fit-content;
        width: fit-content;
        flex-basis: auto;
    }
}

@media (max-width: 760px) {
    .page-shell {
        width: min(100vw - 20px, 100%);
        padding-top: 14px;
    }

    .hero {
        flex-direction: column;
        align-items: start;
    }

    .hero-actions,
    .modal-actions {
        width: 100%;
        flex-direction: column;
    }

    .logout-form {
        width: 100%;
        justify-content: center;
    }

    .legend-hint {
        width: 100%;
        margin-left: 0;
    }

    .button,
    .button-secondary {
        width: 100%;
        text-align: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
