:root {
    color-scheme: light;
    --bg: #f6f3ed;
    --panel: #ffffff;
    --ink: #1f2a24;
    --muted: #657169;
    --line: #d9ded6;
    --accent: #2f6f4e;
    --accent-dark: #24553d;
    --warning: #8a5a16;
    --danger: #9f3131;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

.shell {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent-dark);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 0;
    font-size: 2rem;
}

.button {
    min-height: 44px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    font-weight: 700;
    text-decoration: none;
}

.button:hover {
    background: var(--accent-dark);
}

.button-secondary {
    background: #e5ebe3;
    color: var(--ink);
}

.button-secondary:hover {
    background: #d9e2d6;
}

.header-actions {
    display: flex;
    gap: 10px;
}

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

.summary-card,
.notice,
.empty-state,
.stock-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.stock-card + .edit-form,
.stock-card + .stock-card {
    margin-top: 16px;
}

.summary-card {
    padding: 16px;
}

.summary-card span {
    display: block;
    color: var(--muted);
    font-size: 0.88rem;
    margin-bottom: 6px;
}

.summary-card strong {
    font-size: 1.45rem;
}

.filters {
    display: grid;
    grid-template-columns: 1fr 1fr minmax(220px, 1.4fr) auto;
    gap: 12px;
    align-items: end;
    background: #eef2eb;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 18px;
}

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

label span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 6px;
}

select,
input {
    width: 100%;
    min-height: 44px;
    border: 1px solid #c8d0c6;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    padding: 0 12px;
}

.nfc-field {
    display: grid;
    gap: 8px;
}

.nfc-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.nfc-status {
    color: var(--muted);
    font-size: 0.82rem;
    min-height: 1rem;
}

.nfc-status-error {
    color: var(--danger);
}

textarea {
    width: 100%;
    border: 1px solid #c8d0c6;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    padding: 12px;
    resize: vertical;
}

.notice,
.empty-state {
    padding: 20px;
}

.notice-error {
    border-color: #e4b9b9;
    background: #fff7f7;
}

.notice-success {
    border-color: #bcd9c3;
    background: #f1faf2;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
}

.auth-form {
    display: grid;
    gap: 16px;
}

.stock-list {
    display: grid;
    gap: 12px;
}

.bulk-update-form {
    display: grid;
    gap: 14px;
}

.list-toolbar {
    display: flex;
    justify-content: flex-end;
}

.bulk-update-panel {
    background: #eef2eb;
}

.bulk-update-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.compact-records {
    padding: 0;
}

.growing-table th,
.growing-table td {
    padding: 8px 10px;
    vertical-align: middle;
}

.growing-table td:first-child,
.growing-table th:first-child {
    width: 64px;
}

.growing-table td strong,
.growing-table td span {
    display: block;
}

.growing-table td span:not(.status) {
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 2px;
}

.compact-check {
    min-height: 18px;
    width: 18px;
}

.table-action {
    color: var(--accent-dark);
    font-weight: 700;
}

.modal {
    width: min(760px, calc(100% - 32px));
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(31, 42, 36, 0.28);
    padding: 18px;
}

.modal::backdrop {
    background: rgba(31, 42, 36, 0.45);
}

.modal-header {
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
    padding-bottom: 10px;
}

.modal-header h2 {
    margin-bottom: 0;
}

.modal-close {
    width: 38px;
    min-height: 38px;
    border: 0;
    border-radius: 6px;
    background: #e5ebe3;
    color: var(--ink);
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
}

.stock-card {
    padding: 16px;
}

.stock-list .stock-card.stock-card-expiring {
    background: #fff7d6;
    border-color: #e2c96d;
}

.stock-list .stock-card.stock-card-expired {
    background: #fff0f0;
    border-color: #de8d8d;
}

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

.crop {
    color: var(--accent-dark);
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.stock-card h2 {
    font-size: 1.24rem;
    margin-bottom: 0;
}

.stock-card h2 a {
    color: var(--ink);
    text-decoration: none;
}

.stock-card h2 a:hover {
    color: var(--accent-dark);
    text-decoration: underline;
}

.status {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-stack {
    align-items: flex-end;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    gap: 8px;
}

.select-record {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    display: inline-flex;
    gap: 7px;
    min-height: 34px;
    padding: 6px 10px;
}

.select-record input {
    flex: 0 0 auto;
    min-height: 16px;
    width: 16px;
}

.select-record span {
    color: var(--ink);
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 0;
}

.seed-warning {
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 5px 9px;
}

.status-in_stock {
    background: #dcebd7;
    color: #24553d;
}

.status-part_used {
    background: #fff2d4;
    color: var(--warning);
}

.status-used_up,
.status-discarded {
    background: #f5dddd;
    color: var(--danger);
}

.status-sown {
    background: #e8ece3;
    color: #405040;
}

.status-germinated,
.status-potted_on {
    background: #dcebd7;
    color: #24553d;
}

.status-planted_out,
.status-cropping {
    background: #d9eaf0;
    color: #245163;
}

.status-failed {
    background: #f5dddd;
    color: var(--danger);
}

.status-finished {
    background: #eee5d5;
    color: #6b5228;
}

.notice .button + .button {
    margin-left: 8px;
}

.details {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
}

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

.details div {
    min-width: 0;
}

dt {
    color: var(--muted);
    font-size: 0.78rem;
    margin-bottom: 3px;
}

dd {
    margin: 0;
    overflow-wrap: anywhere;
}

dd a {
    color: var(--accent-dark);
    font-weight: 700;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.meta-row span {
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.8rem;
    padding: 5px 9px;
}

.notes-card {
    display: grid;
    gap: 12px;
}

.note-block {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
}

.note-block strong {
    display: block;
    margin-bottom: 4px;
}

.note-block p {
    margin-bottom: 0;
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--line);
    padding: 10px 8px;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    color: var(--muted);
    font-size: 0.78rem;
}

.unit-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 14px 0 18px;
}

.unit-list span {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    padding: 7px 10px;
}

.unit-tag-list {
    display: grid;
    gap: 12px;
}

.unit-tag-row {
    align-items: end;
    background: #f8faf6;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(120px, 1fr) minmax(110px, 0.8fr) minmax(220px, 1.5fr) minmax(130px, 0.9fr) minmax(130px, 1fr) auto;
    padding: 12px;
}

.tag-assignment-form {
    display: grid;
    gap: 14px;
}

.tag-assignment-row {
    background: #f8faf6;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(120px, 0.8fr) minmax(110px, 0.7fr) minmax(260px, 1.6fr) minmax(180px, 1fr);
    padding: 14px;
}

.tag-assignment-row .nfc-field,
.tag-assignment-row .nfc-input-row {
    min-width: 0;
}

.unit-tag-main,
.unit-tag-current {
    display: grid;
    gap: 4px;
}

.unit-tag-main span,
.unit-tag-current span,
.unit-tag-closed {
    color: var(--muted);
    font-size: 0.82rem;
}

.unit-tag-current strong {
    overflow-wrap: anywhere;
}

.unit-tag-closed {
    grid-column: span 4;
    margin: 0;
}

.tag-date-field {
    display: block;
    max-width: 240px;
    margin-bottom: 1rem;
}

.tag-save-button {
    margin-top: 1rem;
}

.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline li {
    border-left: 3px solid var(--line);
    padding: 0 0 18px 14px;
    position: relative;
}

.timeline li::before {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 999px;
    background: var(--accent);
    position: absolute;
    left: -7px;
    top: 4px;
}

.timeline li:last-child {
    padding-bottom: 0;
}

.timeline time {
    color: var(--muted);
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.timeline strong {
    display: block;
    margin-bottom: 4px;
}

.timeline p {
    margin-bottom: 6px;
}

.packet-layout {
    display: grid;
    gap: 16px;
}

.edit-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    background: #eef2eb;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.form-full,
.edit-form .button,
.check-row,
.form-section {
    grid-column: 1 / -1;
}

.form-section {
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}

.form-section h2 {
    margin-bottom: 0;
}

.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.check-row label {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.check-row span {
    margin-bottom: 0;
}

.record-picker {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 0;
    padding: 14px;
}

.record-picker legend {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 0 6px;
}

.record-picker p {
    color: var(--muted);
    font-size: 0.88rem;
    margin-bottom: 10px;
}

.record-picker-grid {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.record-picker-grid label {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: flex;
    gap: 8px;
    min-height: 44px;
    padding: 8px 10px;
}

.record-picker-grid input {
    flex: 0 0 auto;
    min-height: 18px;
    width: 18px;
}

.record-picker-grid span {
    margin-bottom: 0;
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.menu-card {
    min-height: 190px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 20px;
}

.menu-card h2 {
    font-size: 1.35rem;
    margin-bottom: 8px;
}

.menu-card p:last-child {
    color: var(--muted);
    margin-bottom: 0;
}

@media (max-width: 820px) {
    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .summary-grid,
    .menu-grid,
    .filters,
    .filters-wide,
    .bulk-update-grid,
    .details,
    .details-wide,
    .edit-form,
    .unit-tag-row,
    .tag-assignment-row {
        grid-template-columns: 1fr;
    }

    .unit-tag-closed {
        grid-column: auto;
    }

    .button {
        width: 100%;
    }

    .nfc-input-row {
        grid-template-columns: 1fr;
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
    }
}
