:root {
    --bg: #f3f6f1;
    --surface: #ffffff;
    --surface-2: #eef5ee;
    --text: #17231b;
    --muted: #66736a;
    --line: #d6e0d7;
    --primary: #2e7d32;
    --primary-strong: #1b5e20;
    --accent: #c7901e;
    --danger: #b42318;
    --warning: #936300;
    --success: #2e7d32;
    --shadow: 0 10px 28px rgba(30, 54, 36, 0.07);
    --shadow-soft: 0 3px 12px rgba(30, 54, 36, 0.05);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(46, 125, 50, 0.07), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
}

button,
input,
select {
    font: inherit;
}

.shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 100dvh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
}

.brand-mark {
    display: inline-grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.5);
    overflow: hidden;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 6px;
}

.brand strong {
    display: block;
    line-height: 1.15;
    font-size: 0.96rem;
}

.brand small,
.eyebrow,
.muted {
    color: var(--muted);
}

.header-brand small {
    display: block;
}

.header-brand .brand-mark {
    width: 72px;
    height: 42px;
}

.header-brand .brand-mark img {
    padding: 4px;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.nav a {
    min-height: 36px;
    display: flex;
    align-items: center;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 750;
}

.nav a:hover,
.nav a:focus {
    background: var(--surface-2);
    outline: none;
}

.menu-toggle {
    display: none;
    min-height: 40px;
    grid-template-columns: 16px auto;
    grid-template-rows: repeat(3, 2px);
    align-content: center;
    align-items: center;
    column-gap: 8px;
    row-gap: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    padding: 8px 10px;
    cursor: pointer;
    font-weight: 800;
}

.menu-toggle span {
    width: 16px;
    height: 2px;
    display: block;
    grid-column: 1;
    border-radius: 999px;
    background: currentColor;
}

.menu-toggle strong {
    grid-column: 2;
    grid-row: 1 / 4;
    font-size: 0.86rem;
}

.header-user {
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.main {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 20px;
    min-width: 0;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 2px 0 4px;
    box-shadow: none;
}

.topbar h1,
.login-panel h1 {
    margin: 0;
    font-size: clamp(1.25rem, 2.2vw, 1.75rem);
    line-height: 1.15;
}

.eyebrow {
    margin: 0 0 4px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.user-menu,
.inline-form,
.attendance-search {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
}

.user-menu {
    align-items: center;
}

.user-chip {
    display: grid;
    gap: 2px;
    min-width: 150px;
    text-align: right;
}

.user-chip strong {
    line-height: 1.1;
}

.user-chip small {
    color: var(--muted);
    font-weight: 700;
}

.panel,
.metric,
.login-panel,
.winner-banner {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
}

.panel {
    padding: 18px;
    margin-bottom: 16px;
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 1rem;
}

.toolbar {
    margin-bottom: 18px;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-head h2 {
    margin-bottom: 4px;
}

.section-head p {
    margin: 0;
}

.metrics,
.grid-3,
.grid-4,
.split,
.person-result {
    display: grid;
    gap: 14px;
}

.metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 18px;
}

.metric {
    padding: 16px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-weight: 600;
}

.metric strong {
    display: block;
    margin-top: 6px;
    font-size: 1.65rem;
    line-height: 1;
}

.metric .metric-text {
    font-size: 1.35rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

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

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

.split {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
}

.wide {
    min-width: 0;
}

.form-stack {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 5px;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 700;
}

input,
select {
    min-height: 40px;
    width: 100%;
    border: 1px solid #cbd7ce;
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
    max-width: 100%;
}

input:focus,
select:focus,
button:focus,
a:focus {
    outline: 3px solid rgba(15, 107, 79, 0.24);
    outline-offset: 2px;
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.check input {
    width: 20px;
    height: 20px;
    min-height: 20px;
}

.button {
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 8px 13px;
    cursor: pointer;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
    touch-action: manipulation;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

.button.primary {
    background: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-strong);
}

.button.ghost {
    background: var(--surface-2);
    color: var(--text);
}

.button.danger {
    background: #b42318;
    color: #fff;
}

.button.danger:hover {
    background: #8f1c13;
}

.button.small {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.84rem;
}

.button.full {
    width: 100%;
}

.button.large {
    min-height: 46px;
    font-size: 0.98rem;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid;
    border-left-width: 5px;
    font-weight: 700;
    box-shadow: var(--shadow-soft);
}

.alert.success {
    background: #e9f6ef;
    border-color: #b6dcc5;
    color: #0b513c;
}

.alert.error {
    background: #fff0ef;
    border-color: #f0b8b2;
    color: var(--danger);
}

.alert.warning {
    background: #fff7df;
    border-color: #eed08c;
    color: var(--warning);
}

.help-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 12px;
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.readable-table {
    min-width: 680px;
}

th,
td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
}

.identity-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.identity-cell span:last-child {
    display: grid;
    min-width: 0;
}

.identity-cell strong,
.cell-text {
    overflow-wrap: anywhere;
}

.identity-cell small {
    color: var(--muted);
    font-weight: 700;
}

.avatar {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #e5f3e8;
    color: var(--primary-strong);
    font-weight: 900;
}

.table-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr)) auto;
    gap: 8px;
    align-items: center;
}

.table-form input,
.table-form select {
    min-height: 38px;
    padding: 7px 10px;
}

.actions {
    white-space: nowrap;
}

.actions form {
    display: inline-flex;
    margin: 0 6px 0 0;
}

.check.compact {
    min-height: 38px;
    justify-content: center;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 10px;
}

.readonly-cell {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    border-radius: 8px;
    background: var(--surface-2);
    padding: 7px 10px;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.status,
.pill {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    background: var(--surface-2);
    font-weight: 800;
}

.pill.success {
    background: #dff4e8;
    color: var(--success);
}

.pill.warning {
    background: #fff1c5;
    color: var(--warning);
}

.pill.danger {
    background: #ffe1de;
    color: var(--danger);
}

.bars {
    display: grid;
    gap: 14px;
}

.bar-label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.bar-track {
    height: 10px;
    border-radius: 999px;
    background: #edf1ee;
    overflow: hidden;
}

.bar-track span {
    display: block;
    height: 100%;
    background: var(--accent);
}

.focus-panel {
    border-color: #b5d4c3;
    background: linear-gradient(180deg, #ffffff 0%, #f9fcf9 100%);
}

.attendance-search {
    display: grid;
    grid-template-columns: minmax(220px, 1.2fr) minmax(220px, 1fr) auto;
}

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

.result-header h2 {
    margin-bottom: 2px;
    font-size: 1.35rem;
}

.person-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 20px;
}

.person-grid div {
    background: #f8fbf8;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.person-grid dt {
    color: var(--muted);
    font-weight: 800;
    font-size: 0.85rem;
}

.person-grid dd {
    margin: 4px 0 0;
}

.raffle-panel {
    text-align: center;
}

.roulette {
    min-height: 150px;
    display: grid;
    place-items: center;
    border: 2px dashed #b9c7bd;
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 14px;
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--primary-strong);
}

.roulette.spinning {
    animation: pulse 500ms ease-in-out infinite alternate;
}

.winner-banner {
    padding: 22px;
    margin-bottom: 18px;
    display: grid;
    gap: 4px;
    border-color: #e0bd62;
}

.winner-banner span {
    color: var(--muted);
    font-weight: 800;
    text-transform: uppercase;
}

.winner-banner strong {
    font-size: 1.6rem;
}

.login-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(46, 125, 50, 0.12), rgba(199, 144, 30, 0.14)),
        var(--bg);
}

.login-panel {
    width: min(420px, 100%);
    padding: 30px;
}

.login-brand {
    display: grid;
    place-items: center;
    gap: 6px;
    margin-bottom: 18px;
    text-align: center;
}

.login-logo {
    width: min(340px, 92%);
    height: auto;
    object-fit: contain;
    margin-bottom: 2px;
}

.login-brand h1 {
    margin: 0;
    font-size: 1.55rem;
    line-height: 1.1;
    color: var(--text);
}

.login-brand p {
    margin: 0;
    color: var(--muted);
    font-weight: 800;
}

.login-panel h2 {
    margin: 0 0 16px;
    font-size: 1.05rem;
    text-align: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 28, 18, 0.58);
}

.app-modal[hidden] {
    display: none;
}

.app-modal.is-open {
    display: grid;
}

.modal-panel {
    width: min(460px, 100%);
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 22px 60px rgba(10, 24, 15, 0.26);
}

.notice-modal {
    display: grid;
    gap: 10px;
    text-align: left;
}

.notice-modal p {
    margin: 0;
    color: var(--muted);
}

.notice-summary {
    display: grid;
    gap: 2px;
    margin: 4px 0 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbf8;
}

.notice-summary span {
    color: var(--muted);
    font-weight: 750;
}

.form-modal {
    width: min(520px, 100%);
}

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

.modal-header h2 {
    margin: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.icon-button {
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
}

.modal-panel h2 {
    margin: 8px 0 8px;
}

.modal-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: #fff1c5;
    color: var(--warning);
    font-weight: 900;
    font-size: 1.4rem;
}

.modal-icon.warning {
    background: #fff1c5;
    color: var(--warning);
}

.modal-icon.danger {
    background: #ffe1de;
    color: var(--danger);
}

.modal-icon.success {
    background: #dff4e8;
    color: var(--success);
}

@keyframes pulse {
    from {
        transform: scale(1);
        background: #fff;
    }
    to {
        transform: scale(1.015);
        background: #fff8e5;
    }
}

@media (max-width: 1180px) {
    .app-header {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px;
    }

    .header-left {
        grid-column: 1;
        grid-row: 1;
    }

    .header-user {
        grid-column: 2;
        grid-row: 1;
    }

    .menu-toggle {
        display: inline-grid;
    }

    .primary-nav {
        grid-column: 1 / -1;
        grid-row: 2;
        display: none;
        grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
        gap: 8px;
        width: 100%;
        padding-top: 10px;
        border-top: 1px solid var(--line);
    }

    .primary-nav.is-open {
        display: grid;
    }

    .primary-nav a {
        justify-content: center;
        background: var(--surface-2);
        text-align: center;
    }
}

@media (max-width: 980px) {
    .shell {
        grid-template-rows: auto minmax(0, 1fr);
    }

    .app-header {
        padding: 10px 12px;
    }

    .header-brand .brand-mark {
        width: 64px;
        height: 38px;
    }

    .header-brand strong {
        font-size: 0.9rem;
    }

    .header-brand small {
        font-size: 0.75rem;
    }

    .primary-nav {
        grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
    }

    .primary-nav a {
        min-height: 38px;
        font-size: 0.82rem;
    }

    .main {
        padding: 12px;
        width: 100%;
        overflow-x: hidden;
    }

    .split,
    .grid-3,
    .grid-4,
    .metrics,
    .person-grid,
    .attendance-search {
        grid-template-columns: 1fr;
    }

    .inline-form,
    .attendance-search {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .inline-form .button,
    .attendance-search .button {
        width: 100%;
    }

    .section-head {
        display: grid;
        gap: 12px;
    }

    .section-head .button {
        width: 100%;
    }

    .topbar {
        align-items: start;
        flex-direction: column;
        gap: 10px;
        padding: 2px 0 4px;
        margin-bottom: 12px;
    }

    .topbar h1,
    .login-panel h1 {
        font-size: 1.22rem;
    }

    .user-menu {
        width: 100%;
        justify-content: space-between;
        gap: 10px;
    }

    .user-chip {
        text-align: left;
        min-width: 0;
    }

    .table-form {
        grid-template-columns: 1fr;
    }

    .actions form {
        margin-bottom: 6px;
    }

    .panel {
        padding: 12px;
        margin-bottom: 12px;
    }

    .table-wrap {
        overflow-x: visible;
    }

    .table-wrap table.mobile-cards {
        min-width: 0;
    }

    .table-wrap table.mobile-cards,
    .table-wrap table.mobile-cards thead,
    .table-wrap table.mobile-cards tbody,
    .table-wrap table.mobile-cards th,
    .table-wrap table.mobile-cards td,
    .table-wrap table.mobile-cards tr {
        display: block;
    }

    .table-wrap table.mobile-cards thead {
        display: none;
    }

    .table-wrap table.mobile-cards tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 10px;
        background: #fff;
        overflow: hidden;
    }

    .table-wrap table.mobile-cards td {
        border-bottom: 1px solid var(--line);
        padding: 9px 10px;
        overflow-wrap: anywhere;
    }

    .table-wrap table.mobile-cards input,
    .table-wrap table.mobile-cards select,
    .table-wrap table.mobile-cards .readonly-cell,
    .table-wrap table.mobile-cards .button {
        width: 100%;
    }

    .table-wrap table.mobile-cards td:last-child {
        border-bottom: 0;
    }

    .table-wrap table.mobile-cards td[data-label]::before {
        content: attr(data-label);
        display: block;
        color: var(--muted);
        font-size: 0.68rem;
        font-weight: 800;
        text-transform: uppercase;
        margin-bottom: 4px;
    }

    .actions {
        white-space: normal;
        display: grid;
        gap: 8px;
    }

    .actions form,
    .actions .button {
        width: 100%;
        margin: 0;
    }

    .login-page {
        align-items: start;
        padding: 18px;
    }

    .login-panel {
        margin-top: 12px;
        padding: 20px;
    }

    .login-logo {
        width: min(320px, 92%);
        height: auto;
    }

    .login-brand h1 {
        font-size: 1.48rem;
    }

    .modal-backdrop {
        align-items: end;
        padding: 10px;
    }

    .modal-panel {
        width: 100%;
        max-height: calc(100dvh - 20px);
        padding: 16px;
    }

    .modal-actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    body {
        font-size: 13.5px;
    }

    .metrics {
        grid-template-columns: 1fr;
    }

    .brand small {
        font-size: 0.78rem;
    }

    .attendance-search {
        gap: 10px;
    }

    .button,
    input,
    select {
        min-height: 40px;
    }

    .result-header {
        flex-direction: column;
    }

    .person-grid {
        gap: 10px;
    }

    .user-menu .button {
        flex: 0 0 auto;
    }

    .app-header {
        grid-template-columns: 1fr auto;
        align-items: start;
    }

    .header-left {
        align-items: flex-start;
    }

    .header-brand {
        gap: 8px;
    }

    .header-brand small {
        display: none;
    }

    .menu-toggle strong {
        display: none;
    }

    .header-user {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        display: flex;
        justify-content: space-between;
        padding-top: 8px;
        border-top: 1px solid var(--line);
    }

    .header-user .button {
        width: auto;
        min-width: 86px;
    }

    .primary-nav {
        grid-row: 3;
    }

    .topbar,
    .panel,
    .metric,
    .winner-banner {
        border-radius: 8px;
    }

    .user-menu {
        display: flex;
    }

    .user-menu .button {
        width: auto;
    }

    .login-page {
        padding: 14px;
    }

    .login-panel {
        margin-top: 8px;
        padding: 18px;
    }

    .login-brand {
        margin-bottom: 18px;
    }

    .login-logo {
        width: min(300px, 92%);
        height: auto;
    }

    .login-brand h1 {
        font-size: 1.45rem;
    }

    .table-wrap table.mobile-cards tr {
        margin-bottom: 10px;
    }

    .table-wrap table.mobile-cards td {
        padding: 8px 9px;
    }
}

@media (max-width: 420px) {
    .main {
        padding: 8px;
    }

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

    .primary-nav a {
        min-height: 36px;
        padding: 7px 6px;
        font-size: 0.78rem;
    }

    .topbar,
    .panel,
    .metric,
    .winner-banner {
        padding: 10px;
    }

    .topbar h1,
    .login-panel h1 {
        font-size: 1.12rem;
    }

    .login-logo {
        width: min(280px, 92%);
        height: auto;
    }

    .login-brand h1 {
        font-size: 1.32rem;
    }
}

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