:root {
    --ink: #17211d;
    --muted: #67746d;
    --line: #dce5df;
    --panel: #ffffff;
    --wash: #f7f4ec;
    --brand: #1f7a59;
    --brand-dark: #123729;
    --accent: #d88b35;
    --danger: #a33a2c;
    --ok: #1f7a59;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    color: var(--ink);
    background: var(--wash);
}

img {
    image-orientation: from-image;
}

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

.sidebar {
    height: 100vh;
    padding: 22px;
    background: var(--brand-dark);
    color: #f4fbf6;
    position: sticky;
    top: 0;
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 30px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: #e5b15d;
    object-fit: cover;
    object-position: center;
    display: block;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #c7d8cf;
    margin-top: 4px;
}

nav {
    display: grid;
    gap: 8px;
}

.app-version {
    color: #a8beb2;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
    padding: 0 14px 4px;
}

nav a {
    min-height: 42px;
    display: flex;
    align-items: center;
    border-radius: 8px;
    padding: 0 14px;
    color: #dbe9e2;
}

nav a.active,
nav a:hover {
    background: #f2f7ef;
    color: var(--brand-dark);
}

.tabs {
    display: flex;
    gap: 0;
    margin: 0 0 16px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
}

.tabs a {
    min-width: 132px;
    min-height: 42px;
    justify-content: center;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    color: var(--brand-dark);
    background: #edf5ef;
    font-weight: 900;
    white-space: nowrap;
}

.tabs a.active,
.tabs a:hover {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

main {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 18px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(247, 244, 236, 0.94);
    border-bottom: 1px solid rgba(220, 229, 223, 0.85);
    padding: 0 0 14px;
    backdrop-filter: blur(8px);
}

.eyebrow {
    color: var(--brand);
    font-size: 13px;
    text-transform: uppercase;
    font-weight: 900;
}

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

h1 {
    font-size: 34px;
    margin-bottom: 0;
}

p {
    color: var(--muted);
    line-height: 1.55;
}

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

.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    border-radius: 8px;
    padding: 0 16px;
    font-weight: 800;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 120ms ease, opacity 160ms ease;
}

.button:hover,
button:hover,
input[type="button"]:hover,
input[type="submit"]:hover,
input[type="reset"]:hover {
    box-shadow: 0 8px 20px rgba(18, 55, 41, 0.14);
    transform: translateY(-1px);
}

.button:active,
button:active,
input[type="button"]:active,
input[type="submit"]:active,
input[type="reset"]:active {
    box-shadow: none;
    transform: translateY(0) scale(0.98);
}

.button:focus-visible,
button:focus-visible,
input[type="button"]:focus-visible,
input[type="submit"]:focus-visible,
input[type="reset"]:focus-visible {
    outline: 3px solid rgba(31, 122, 89, 0.28);
    outline-offset: 2px;
}

.button.primary {
    background: var(--brand);
    color: white;
}

.button.secondary {
    background: #e7eee9;
}

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

.notice {
    background: #fff7e6;
    border: 1px solid #f0d59c;
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 18px;
}

.notice.toast {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 50;
    width: min(460px, calc(100vw - 36px));
    box-shadow: 0 18px 45px rgba(28, 47, 38, 0.18);
    animation: toast-fade 7s ease forwards;
}

@keyframes toast-fade {
    0%, 78% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-8px);
        pointer-events: none;
    }
}

.notice p {
    margin-bottom: 0;
}

.notice.error {
    background: #fff0ed;
    border-color: #e4a396;
    color: var(--danger);
}

.notice.success {
    background: #edf8f1;
    border-color: #acd9bd;
    color: var(--ok);
}

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

.metrics article,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(28, 47, 38, 0.1);
}

.metrics article {
    padding: 16px;
}

.metrics span {
    color: var(--muted);
    font-size: 13px;
}

.metrics strong {
    display: block;
    font-size: 30px;
    margin-top: 6px;
}

.grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 16px;
}

.grid > .panel:only-child {
    grid-column: 1 / -1;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.5fr);
    gap: 16px;
    margin-bottom: 16px;
}

.panel {
    padding: 20px;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-title h2 {
    margin-bottom: 12px;
}

.panel-title span {
    border-radius: 999px;
    background: #edf5ef;
    color: var(--brand);
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 900;
}

.table {
    display: grid;
}

.animal-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 250px));
    justify-content: start;
    gap: 12px;
}

.animal-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fbfdfb;
}

.animal-card-photo {
    aspect-ratio: 16 / 9;
}

.animal-card:hover {
    border-color: var(--brand);
}

.animal-card-photo,
.hero-photo {
    background: #dfe8df;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 900;
    overflow: hidden;
}

.animal-card-photo img {
    width: 100%;
    height: 100%;
    object-fit: var(--fit, cover);
    object-position: var(--pos-x, 50%) var(--pos-y, 50%);
    transform: translate(var(--shift-x, 0), var(--shift-y, 0)) rotate(var(--rotate, 0deg)) scale(calc(var(--zoom, 1) * var(--rotate-scale, 1)));
    transform-origin: center;
    display: block;
}

.hero-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: 50% 50%;
    transform: rotate(var(--rotate, 0deg)) scale(var(--rotate-scale, 1));
    transform-origin: center;
    display: block;
}

.photo-grid img,
.photo-dialog-preview img,
.preview-card-photo img,
.preview-hero-photo img {
    width: 100%;
    height: 100%;
    object-fit: var(--fit, cover);
    object-position: var(--pos-x, 50%) var(--pos-y, 50%);
    transform: translate(var(--shift-x, 0), var(--shift-y, 0)) rotate(var(--rotate, 0deg)) scale(calc(var(--zoom, 1) * var(--rotate-scale, 1)));
    transform-origin: center;
    display: block;
}

.animal-card-body {
    display: grid;
    gap: 8px;
    padding: 10px;
}

.animal-card-body strong,
.animal-card-body span {
    display: block;
}

.animal-card-body span {
    color: var(--muted);
    font-size: 14px;
    margin-top: 3px;
}

.animal-card-body dl {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 0;
}

.animal-card-body dl div {
    display: grid;
    gap: 3px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 5px;
}

.animal-card-body dd {
    text-align: left;
}

.filters {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.45fr) minmax(150px, 0.45fr) auto auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 16px;
}

.filters label {
    display: grid;
    gap: 6px;
}

.filters label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.filters input,
.filters select {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #fbfdfb;
    font: inherit;
}

.filters button {
    border: 0;
    justify-content: center;
}

.pagination {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

.pagination a,
.pagination span {
    border-radius: 8px;
    background: #edf5ef;
    color: var(--brand);
    font-weight: 900;
    padding: 9px 12px;
}

.card-actions {
    align-self: end;
}

.card-actions span {
    color: var(--brand);
    font-size: 14px;
    font-weight: 900;
}

.row {
    display: grid;
    grid-template-columns: 1.4fr 0.8fr 0.8fr 0.8fr 1fr 1fr;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.row:hover {
    color: var(--brand);
}

.row span,
.empty {
    color: var(--muted);
}

.mini-tree {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.mini-tree span {
    min-height: 44px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #edf5ef;
    font-weight: 800;
}

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

.animal-form label {
    display: grid;
    gap: 7px;
}

.animal-form label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.animal-form input,
.animal-form select,
.animal-form textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    color: var(--ink);
    background: #fbfdfb;
    font: inherit;
}

.animal-form textarea {
    min-height: 96px;
    padding-top: 12px;
    resize: vertical;
}

.animal-form .wide,
.animal-form .check {
    grid-column: 1 / -1;
}

.animal-form .check {
    align-items: center;
    display: flex;
    gap: 10px;
}

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

.animal-form button {
    border: 0;
    justify-content: center;
}

.compact-form {
    grid-template-columns: minmax(180px, 0.6fr) minmax(150px, 0.4fr);
    margin-bottom: 20px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.inline-action {
    border: 0;
    justify-content: center;
    margin-bottom: 16px;
}

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

.status-list div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}

.status-list span {
    color: var(--muted);
}

.animal-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.65fr);
    gap: 18px;
    align-items: stretch;
    margin-bottom: 16px;
    padding: 24px;
    border-radius: 8px;
    background: var(--brand-dark);
    color: #f7fbf8;
}

.animal-hero.has-photo {
    grid-template-columns: minmax(340px, 0.9fr) minmax(0, 0.8fr) minmax(280px, 0.55fr);
}

.hero-photo {
    align-self: start;
    aspect-ratio: 16 / 9;
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: none;
    border-radius: 8px;
}

.animal-hero span,
.animal-hero p,
.animal-hero dt {
    color: #cfe0d7;
}

.animal-hero strong {
    display: block;
    font-size: 36px;
    margin: 6px 0 10px;
}

.animal-hero p {
    margin-bottom: 0;
}

.animal-hero dl,
.data-list {
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.animal-hero dl div,
.data-list div {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    padding: 12px;
}

.data-list div {
    border-color: var(--line);
}

dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

dd {
    margin: 4px 0 0;
    font-weight: 800;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
    gap: 16px;
    margin-bottom: 16px;
}

.pedigree-cards,
.ancestry-list {
    display: grid;
    gap: 10px;
}

.pedigree-cards {
    grid-template-columns: 1fr 1fr;
    margin-bottom: 14px;
}

.ancestor-card,
.ancestry-list a {
    display: grid;
    gap: 4px;
    min-height: 76px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fbfdfb;
}

.ancestor-card span,
.ancestor-card small,
.ancestry-list span {
    color: var(--muted);
}

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

.timeline div {
    border-left: 3px solid var(--brand);
    padding-left: 12px;
}

.timeline time {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 800;
}

.stack {
    display: grid;
    gap: 16px;
}

.photo-form {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.photo-form label {
    display: grid;
    gap: 7px;
}

.photo-form label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.photo-form label small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.photo-form input[type="file"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #fbfdfb;
}

.photo-form .check {
    align-items: center;
    display: flex;
    gap: 10px;
}

.photo-form button {
    border: 0;
    justify-content: center;
}

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

.photo-grid figure {
    aspect-ratio: 1 / 1;
    margin: 0;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    background: #dfe8df;
}

.photo-thumb {
    width: 100%;
    height: 100%;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.photo-grid figcaption {
    position: absolute;
    left: 8px;
    bottom: 8px;
    border-radius: 8px;
    background: rgba(18, 55, 41, 0.88);
    color: #fff;
    font-size: 12px;
    font-weight: 900;
    padding: 5px 8px;
}

.photo-dialog {
    width: min(860px, calc(100vw - 32px));
    max-height: calc(100vh - 28px);
    border: 0;
    border-radius: 8px;
    padding: 0;
    background: #f7fbf8;
    box-shadow: 0 24px 80px rgba(18, 55, 41, 0.28);
    overflow: auto;
}

.photo-dialog::backdrop {
    background: rgba(18, 33, 29, 0.55);
}

.photo-dialog-body {
    display: grid;
    grid-template-columns: minmax(0, 0.95fr) 340px;
    align-items: start;
    gap: 0;
}

.photo-dialog-preview {
    aspect-ratio: 16 / 9;
    height: auto;
    min-height: 0;
    margin: 14px;
    border: 1px solid #cbd8cf;
    border-radius: 8px;
    background:
        linear-gradient(45deg, rgba(255, 255, 255, 0.42) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255, 255, 255, 0.42) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.42) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.42) 75%),
        #dfe8df;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    background-size: 20px 20px;
    overflow: hidden;
}

.photo-dialog-preview img,
.preview-hero-photo img {
    object-fit: var(--fit, contain);
}

.photo-adjust-form {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    display: grid;
    gap: 9px;
    margin-top: 0;
    padding: 12px;
}

.photo-adjust-form strong {
    color: var(--brand-dark);
    font-size: 15px;
}

.photo-adjust-form label {
    display: grid;
    gap: 5px;
}

.photo-adjust-form label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.photo-adjust-form select,
.photo-adjust-form input {
    min-height: 34px;
}

.photo-adjust-form select {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfb;
    color: var(--ink);
    font: inherit;
    padding: 0 10px;
}

.photo-adjust-form input[type="range"] {
    accent-color: var(--brand);
    min-height: 26px;
}

.range-control {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
}

.range-control input[type="number"] {
    width: 64px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfb;
    color: var(--ink);
    font: inherit;
    font-weight: 800;
    padding: 0 8px;
    text-align: center;
}

.compact-button {
    min-height: 36px;
    border: 0;
    justify-content: center;
}

.photo-dialog-side {
    display: grid;
    align-content: start;
    gap: 10px;
    padding: 16px;
    background: #ffffff;
    border-left: 1px solid var(--line);
}

.photo-dialog-heading {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}

.photo-dialog-heading span {
    color: var(--brand);
    display: block;
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.photo-dialog-side h2 {
    font-size: 22px;
    margin-bottom: 0;
}

.icon-button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #edf5ef;
    color: var(--brand-dark);
    cursor: pointer;
    font: inherit;
    font-weight: 900;
    line-height: 1;
}

.photo-dialog-side form,
.photo-management-actions {
    width: 100%;
}

.photo-dialog-side .button,
.photo-management-actions .button {
    border: 0;
    justify-content: center;
    width: 100%;
}

.photo-management-actions {
    display: grid;
    grid-template-columns: 1fr 0.72fr;
    gap: 8px;
}

.ghost-danger {
    border: 1px solid #d8aca5;
    background: #fff3f1;
    color: var(--danger);
}

.photo-preview-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 2px 0;
}

.photo-preview-pair span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 6px;
}

.preview-card-photo {
    aspect-ratio: 16 / 9;
    border: 1px solid var(--line);
    background: #edf5ef;
    border-radius: 8px;
    overflow: hidden;
}

.preview-hero-photo {
    aspect-ratio: 16 / 9;
    height: auto;
    border: 1px solid var(--line);
    background: var(--brand-dark);
    border-radius: 8px;
    overflow: hidden;
}

.activity-dialog {
    width: min(720px, calc(100vw - 32px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    background: var(--panel);
    box-shadow: 0 24px 80px rgba(18, 55, 41, 0.28);
}

.activity-dialog::backdrop {
    background: rgba(18, 33, 29, 0.55);
}

.dialog-form {
    border: 0;
    margin: 0;
    padding: 22px;
}

.dialog-title,
.dialog-actions {
    grid-column: 1 / -1;
}

.dialog-title h2 {
    margin-bottom: 6px;
}

.dialog-title p {
    margin-bottom: 0;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

@media (max-width: 1050px) {
    body {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
        height: auto;
        position: static;
    }

    nav,
    .metrics,
    .grid,
    .workspace,
    .animal-cards,
    .filters,
    .detail-grid,
    .animal-hero,
    .animal-hero.has-photo,
    .photo-dialog-body,
    .animal-form {
        grid-template-columns: 1fr 1fr;
    }

    .tabs {
        display: flex;
    }

    .animal-cards {
        grid-template-columns: repeat(auto-fill, minmax(200px, 240px));
    }
}

@media (max-width: 720px) {
    main {
        padding: 18px;
    }

    .topbar,
    .actions {
        align-items: stretch;
        flex-direction: column;
    }

    nav,
    .metrics,
    .grid,
    .workspace,
    .animal-cards,
    .animal-card,
    .filters,
    .detail-grid,
    .animal-hero,
    .animal-hero.has-photo,
    .photo-dialog-body,
    .animal-hero dl,
    .data-list,
    .pedigree-cards,
    .animal-form,
    .row,
    .mini-tree {
        grid-template-columns: 1fr;
    }

    .tabs {
        display: flex;
    }

    .animal-cards {
        grid-template-columns: 1fr;
    }
}
