:root {
    color-scheme: light;
    --brand-orange: #f99610;
    --brand-burgundy: #a50344;
    --brand-green: #66a55e;
    --brand-tan: #d19c64;
    --brand-cream: #f5d5a9;
    --brand-ink: #292823;
    --brand-muted: #737373;
    --bg: #f7f7f7;
    --surface: #ffffff;
    --surface-soft: #eeeeee;
    --ink: var(--brand-ink);
    --muted: var(--brand-muted);
    --line: #dedede;
    --teal: var(--brand-orange);
    --teal-dark: var(--brand-burgundy);
    --amber: var(--brand-tan);
    --red: #b42318;
    --blue: var(--brand-burgundy);
    --green: var(--brand-green);
    --shadow: 0 18px 45px rgba(41, 40, 35, 0.11);
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    margin: 0;
    min-width: 320px;
    width: 100%;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

button,
input,
textarea,
select {
    font: inherit;
    min-width: 0;
}

button {
    border: 0;
    cursor: pointer;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 18px clamp(16px, 4vw, 36px);
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand-logo {
    display: flex;
    align-items: center;
    width: clamp(118px, 15vw, 185px);
    min-width: 0;
}

.brand-logo img {
    display: block;
    width: 100%;
    height: auto;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 1.25rem;
}

h2 {
    font-size: 1rem;
}

.topbar p,
.inline-state,
.meta-badge {
    color: var(--muted);
    font-size: 0.86rem;
}

.main-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.logout-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.84rem;
}

.tab-button,
.secondary-button,
.primary-button,
.accent-button,
.primary-link,
.danger-button,
.icon-button {
    min-height: 38px;
    border-radius: 8px;
    padding: 9px 14px;
    color: var(--ink);
    background: var(--surface-soft);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    max-width: 100%;
}

.tab-button.active,
.primary-button {
    background: var(--teal);
    color: #ffffff;
}

.accent-button {
    background: var(--teal-dark);
    color: #ffffff;
}

.danger-button {
    background: var(--red);
    color: #ffffff;
}

.secondary-button {
    border: 1px solid var(--line);
}

.tab-button.active,
.primary-button,
.accent-button {
    box-shadow: 0 8px 18px rgba(165, 3, 68, 0.12);
}

.tab-button:not(.active):hover,
.secondary-button:hover,
.primary-link:hover {
    border-color: var(--brand-orange);
    color: var(--brand-burgundy);
    background: #ffffff;
}

.primary-button:hover {
    background: #d9810e;
}

.accent-button:hover {
    background: #860238;
}

.icon-button {
    width: 38px;
    padding: 0;
    font-weight: 700;
}

main {
    padding: clamp(16px, 3vw, 32px);
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.hidden {
    display: none !important;
}

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

.login-shell {
    width: min(100%, 430px);
    display: grid;
    gap: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-shell img {
    width: 170px;
    max-width: 60%;
}

.login-form,
.user-form {
    display: grid;
    gap: 12px;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(230px, 320px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.list-panel,
.editor-panel,
.settings-panel,
.weight-chart-panel,
.plan-output,
.history-panel,
.install-shell {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.list-panel,
.editor-panel,
.settings-panel,
.weight-chart-panel,
.plan-output,
.history-panel {
    padding: 18px;
    min-width: 0;
}

.editor-panel {
    display: flex;
    flex-direction: column;
}

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

.animal-list-title {
    align-items: stretch;
}

.animal-list-toggle {
    flex: 1 1 auto;
}

.animal-list-toggle .segment-button {
    flex: 1 1 0;
}

.segmented-control {
    display: inline-flex;
    max-width: 100%;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    gap: 3px;
}

.segment-button {
    min-height: 34px;
    border-radius: 6px;
    padding: 7px 12px;
    background: transparent;
    color: var(--muted);
    white-space: nowrap;
}

.segment-button.active {
    background: var(--teal);
    color: #ffffff;
}

.dog-list,
.history-list {
    display: grid;
    gap: 10px;
}

.current-animal-card {
    order: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(238, 238, 238, 0.86);
}

.animal-current-avatar {
    width: 58px;
    height: 58px;
    flex-basis: 58px;
    font-size: 0.95rem;
}

.current-animal-copy {
    min-width: 0;
}

.current-animal-copy span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
}

.current-animal-copy strong {
    display: block;
    margin-top: 2px;
    font-size: 1.18rem;
    overflow-wrap: anywhere;
}

.current-animal-copy p {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.current-animal-actions {
    display: flex;
    justify-content: flex-end;
    min-width: 0;
}

.dog-settings-details {
    order: 5;
    margin-top: 18px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.dog-settings-details summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 50px;
    padding: 13px 14px;
    background: var(--surface-soft);
    color: var(--ink);
    font-weight: 700;
    cursor: pointer;
    list-style: none;
}

.dog-settings-details summary::-webkit-details-marker {
    display: none;
}

.dog-settings-details summary::after {
    content: "+";
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 999px;
    background: #ffffff;
    color: var(--brand-burgundy);
    font-size: 1.2rem;
    line-height: 1;
}

.dog-settings-details[open] summary::after {
    content: "-";
}

.dog-settings-details:not([open]) > form,
.history-details:not([open]) > .history-list {
    display: none;
}

.dog-settings-details summary small {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 400;
}

.dog-settings-details .form-grid {
    padding: 14px;
}

.dog-item,
.history-card {
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
}

.dog-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dog-item.active {
    border-color: var(--teal);
    background: rgba(249, 150, 16, 0.13);
}

.dog-item-body {
    min-width: 0;
}

.dog-item-body strong,
.history-card strong {
    display: block;
    margin-bottom: 3px;
}

.dog-item-body span,
.history-card span {
    color: var(--muted);
    font-size: 0.86rem;
    overflow-wrap: anywhere;
}

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

.history-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.history-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.history-actions button {
    min-height: 34px;
    padding: 7px 10px;
}

.history-preview .structured-plan {
    gap: 10px;
}

.history-panel.history-details {
    padding: 0;
    overflow: hidden;
}

.history-details > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    padding: 15px 18px;
    cursor: pointer;
    list-style: none;
}

.history-details > summary::-webkit-details-marker {
    display: none;
}

.history-details > summary::after {
    content: "+";
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--brand-burgundy);
    font-size: 1.2rem;
    line-height: 1;
}

.history-details[open] > summary::after {
    content: "-";
}

.history-details > summary span {
    font-weight: 700;
}

.history-details > summary small {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 400;
}

.history-details > .history-list {
    padding: 0 18px 18px;
}

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

.animal-photo-field {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.animal-photo-editor {
    display: grid;
    justify-items: center;
    flex: 0 0 auto;
}

.animal-photo-adjuster {
    display: grid;
    grid-template-columns: 24px 64px 24px;
    grid-template-rows: 24px 64px 24px;
    gap: 2px;
    align-items: center;
    justify-items: center;
}

.photo-zoom-controls {
    display: grid;
    grid-template-columns: 26px minmax(46px, auto) 26px;
    gap: 4px;
    align-items: center;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
}

.photo-zoom-button {
    width: 26px;
    height: 26px;
    min-height: 26px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #ffffff;
    color: var(--teal);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
}

.photo-zoom-button:hover,
.photo-zoom-button:focus-visible {
    background: var(--surface-soft);
}

.animal-photo-field label {
    flex: 1;
    min-width: 0;
}

.animal-avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 999px;
    background: var(--teal);
    color: #ffffff;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
}

.animal-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: var(--photo-x, 50%) var(--photo-y, 50%);
    transform: translate(var(--photo-offset-x, 0%), var(--photo-offset-y, 0%)) scale(var(--photo-scale, 1.35));
    transform-origin: center;
    transition: transform 120ms ease, object-position 120ms ease;
    will-change: transform;
    pointer-events: none;
    user-select: none;
}

.animal-photo-preview {
    width: 64px;
    height: 64px;
    flex-basis: 64px;
    grid-column: 2;
    grid-row: 2;
    cursor: default;
    touch-action: none;
}

.animal-photo-field.has-photo .animal-photo-preview {
    cursor: grab;
}

.animal-photo-preview.dragging {
    cursor: grabbing;
}

.photo-move-button {
    width: 24px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #ffffff;
    color: var(--teal);
    font-size: 0.9rem;
    font-weight: 800;
    line-height: 1;
}

.photo-move-button:hover,
.photo-move-button:focus-visible {
    background: var(--surface-soft);
}

.photo-move-button:active {
    transform: translateY(1px);
}

.photo-move-up {
    grid-column: 2;
    grid-row: 1;
}

.photo-move-left {
    grid-column: 1;
    grid-row: 2;
}

.photo-move-right {
    grid-column: 3;
    grid-row: 2;
}

.photo-move-down {
    grid-column: 2;
    grid-row: 3;
}

.animal-photo-field:not(.has-photo) .photo-move-button {
    visibility: hidden;
    pointer-events: none;
}

.animal-photo-field:not(.has-photo) .photo-zoom-controls {
    visibility: hidden;
    pointer-events: none;
}

label,
fieldset {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.88rem;
}

input,
textarea,
select {
    width: 100%;
    min-height: 40px;
    font-size: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    background: #ffffff;
    color: var(--ink);
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: 3px solid rgba(22, 117, 111, 0.18);
    border-color: var(--teal);
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

legend {
    color: var(--ink);
    font-weight: 700;
}

.wide {
    grid-column: 1 / -1;
}

.mixed-only.hidden {
    display: none;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    color: var(--ink);
}

.check-line input {
    width: 17px;
    height: 17px;
    min-height: auto;
    accent-color: var(--teal);
}

.chip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    align-items: stretch;
}

.chip,
.choice-card {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--ink);
    background: #ffffff;
    max-width: 100%;
    min-height: 44px;
    text-align: left;
    overflow-wrap: anywhere;
}

.chip input,
.choice-card input {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    min-height: auto;
    accent-color: var(--teal);
}

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

.weight-chart-summary {
    margin: -6px 0 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.status-strip {
    order: 3;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 18px 0;
}

.status-strip > div {
    border-left: 4px solid var(--blue);
    background: rgba(238, 238, 238, 0.86);
    border-radius: 8px;
    padding: 12px;
}

.status-strip span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
}

.status-strip strong {
    display: block;
    margin-top: 4px;
}

.status-strip.overweight > div {
    border-left-color: var(--red);
    background: rgba(180, 35, 24, 0.08);
}

.status-strip.underweight > div {
    border-left-color: var(--amber);
    background: rgba(209, 156, 100, 0.17);
}

.status-strip.ideal > div {
    border-left-color: var(--green);
    background: rgba(102, 165, 94, 0.14);
}

.plan-layout {
    order: 4;
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}

.weight-chart-panel {
    order: 2;
    margin: 18px 0;
}

.weight-chart {
    min-width: 0;
}

.weight-chart-scroll {
    overflow-x: visible;
    padding-bottom: 2px;
}

.weight-chart-frame {
    display: grid;
    grid-template-columns: 48px minmax(320px, 1fr);
    gap: 10px;
    min-width: 0;
}

.weight-chart-scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 230px;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: right;
    padding: 6px 0 32px;
}

.weight-chart-plot {
    position: relative;
    min-height: 230px;
    border-left: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background:
        linear-gradient(to top, rgba(238, 238, 238, 0.88) 1px, transparent 1px) 0 0 / 100% 25%;
    padding: 12px 12px 32px;
}

.weight-ideal-band {
    position: absolute;
    left: 12px;
    right: 12px;
    z-index: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 20px;
    border-top: 1px dashed rgba(34, 122, 72, 0.72);
    border-bottom: 1px dashed rgba(34, 122, 72, 0.72);
    background: rgba(34, 122, 72, 0.09);
    color: var(--green);
    font-size: 0.76rem;
    font-weight: 700;
    pointer-events: none;
}

.weight-ideal-band span {
    margin-right: 8px;
    background: rgba(255, 255, 255, 0.86);
    border-radius: 6px;
    padding: 2px 6px;
}

.weight-bars {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 10px;
    height: 186px;
}

.weight-bar {
    flex: 1 1 42px;
    max-width: 74px;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-end;
    gap: 7px;
}

.weight-bar-fill {
    min-height: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    border-radius: 7px 7px 0 0;
    background: var(--blue);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(165, 3, 68, 0.16);
    overflow: hidden;
    padding: 5px 3px 4px;
    transition: height 160ms ease;
}

.weight-bar-fill .weight-value {
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1.05;
}

.weight-bar-fill .weight-status {
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    opacity: 0.94;
    text-align: center;
    white-space: nowrap;
}

.weight-bar-fill.compact .weight-status {
    display: none;
}

.weight-bar small {
    min-height: 20px;
    color: var(--muted);
    font-size: 0.74rem;
    text-align: center;
    white-space: nowrap;
}

.weight-bar.under .weight-bar-fill {
    background: var(--amber);
    box-shadow: 0 8px 18px rgba(209, 156, 100, 0.22);
}

.weight-bar.ok .weight-bar-fill {
    background: var(--green);
    box-shadow: 0 8px 18px rgba(102, 165, 94, 0.18);
}

.weight-bar.over .weight-bar-fill {
    background: var(--red);
    box-shadow: 0 8px 18px rgba(180, 35, 24, 0.16);
}

.weight-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.8rem;
}

.weight-chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.weight-chart-legend i {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--blue);
}

.weight-chart-legend i.ideal {
    border: 1px dashed var(--green);
    background: rgba(34, 122, 72, 0.12);
}

.weight-chart-legend i.under {
    background: var(--amber);
}

.weight-chart-legend i.ok {
    background: var(--green);
}

.weight-chart-legend i.over {
    background: var(--red);
}

.plan-view {
    margin: 0;
    min-height: 280px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.plan-view.empty-state {
    display: grid;
    place-items: center;
    color: var(--muted);
}

.structured-plan {
    display: grid;
    gap: 16px;
}

.plan-intro {
    display: grid;
    gap: 6px;
    padding: 12px;
    border-left: 4px solid var(--teal);
    border-radius: 8px;
    background: rgba(249, 150, 16, 0.13);
}

.plan-intro p {
    margin: 4px 0 0;
    color: var(--text);
}

.plan-table-section {
    display: grid;
    gap: 8px;
}

.plan-table-section h3,
.plan-notes h3 {
    margin: 0;
    font-size: 1rem;
}

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

.plan-row-card {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    min-width: 0;
}

.plan-row-card.meal-morning {
    border-color: #f1d19c;
    background: #fff8eb;
}

.plan-row-card.meal-midday {
    border-color: #b9d9c4;
    background: #f4fbf7;
}

.plan-row-card.meal-evening {
    border-color: #d9c2dc;
    background: #f8f3fa;
}

.plan-row-card.meal-neutral {
    background: #ffffff;
}

.plan-row-card > strong {
    display: block;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.plan-row-card dl {
    display: grid;
    gap: 8px;
    margin: 0;
}

.plan-row-field {
    display: grid;
    grid-template-columns: minmax(118px, 0.35fr) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-width: 0;
}

.plan-row-field dt,
.plan-row-field dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.plan-row-field dt {
    color: var(--muted);
    font-weight: 700;
}

.plan-row-field dd {
    color: var(--ink);
}

.plan-notes ul {
    margin: 0;
    padding-left: 18px;
}

.structured-plan.compact .plan-intro {
    padding: 10px;
}

.settings-check {
    max-width: max-content;
}

.settings-stack {
    display: grid;
    gap: 20px;
    max-width: 1180px;
    margin: 0 auto;
}

.settings-accordion {
    padding: 0;
    overflow: hidden;
    scroll-margin-top: 108px;
}

.settings-accordion.ai-settings-entry {
    display: block;
}

.settings-accordion > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 18px;
    cursor: pointer;
    list-style: none;
    min-width: 0;
}

.settings-accordion > summary::-webkit-details-marker {
    display: none;
}

.settings-summary-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.settings-summary-copy strong {
    overflow-wrap: anywhere;
}

.settings-summary-copy small {
    color: var(--muted);
    font-size: 0.84rem;
    overflow-wrap: anywhere;
}

.settings-summary-meta {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.settings-toggle-icon {
    width: 26px;
    height: 26px;
    border: 1px solid var(--line);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-burgundy);
    background: #ffffff;
    font-weight: 700;
    flex: 0 0 auto;
}

.settings-toggle-icon::before {
    content: "+";
}

.settings-accordion[open] > summary .settings-toggle-icon::before {
    content: "-";
}

.settings-panel-body {
    padding: 0 18px 18px;
    min-width: 0;
}

.segmented-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.food-editor-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.food-editor-form .wide,
.user-form .wide {
    grid-column: 1 / -1;
}

.user-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 16px;
}

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

.user-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
}

.user-row .wide,
.user-actions {
    grid-column: 1 / -1;
}

.user-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.food-editor-form textarea,
.food-row textarea {
    width: 100%;
    min-height: 72px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
    color: var(--ink);
}

.food-settings {
    display: grid;
    gap: 14px;
    margin: 12px 0 16px;
}

.food-group {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    min-width: 0;
}

.food-group h3 {
    margin: 0;
    padding: 11px 12px;
    background: var(--surface-soft);
    font-size: 0.96rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.food-group h3 span {
    min-width: 0;
}

.food-group h3 small {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 400;
}

.group-toggle {
    min-height: auto;
    font-size: 0.82rem;
    font-weight: 400;
}

.food-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
}

.food-row > .check-line,
.food-row > .wide {
    grid-column: 1 / -1;
}

.food-row label {
    color: var(--ink);
    min-width: 0;
}

.food-row .check-line span {
    min-width: 0;
}

.food-row .check-line strong,
.food-row .check-line small {
    display: block;
    overflow-wrap: anywhere;
}

.food-row .check-line small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 400;
}

.food-row .check-line {
    min-width: 0;
}

.food-row input[type="number"] {
    min-width: 0;
}

.food-row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.food-delete-button {
    min-width: 0;
}

.food-row.is-deleting {
    opacity: 0.58;
    pointer-events: none;
}

.food-settings-empty {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 14px;
    color: var(--muted);
    background: var(--surface-soft);
}

.nutrition-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 0.78rem;
    text-align: center;
}

.barcode-result {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 12px;
    color: var(--ink);
}

.barcode-result strong,
.barcode-result span {
    display: block;
    overflow-wrap: anywhere;
}

.barcode-result span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.86rem;
}

.barcode-panel.lookup-busy {
    border-color: var(--brand-orange);
    box-shadow: 0 12px 28px rgba(255, 147, 10, 0.14);
}

.food-lookup-busy {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    border: 1px solid rgba(255, 147, 10, 0.38);
    border-radius: 8px;
    background: #fff6e7;
    padding: 12px;
    color: var(--ink);
}

.food-lookup-pulse {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    color: #ffffff;
    background: var(--brand-burgundy);
    font-weight: 800;
    letter-spacing: 0;
    box-shadow: 0 0 0 0 rgba(165, 3, 68, 0.34);
    animation: food-ai-pulse 1.2s ease-in-out infinite;
}

.food-lookup-busy-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.food-lookup-busy-copy small {
    color: var(--muted);
    overflow-wrap: anywhere;
}

@keyframes food-ai-pulse {
    0% {
        transform: scale(0.96);
        box-shadow: 0 0 0 0 rgba(165, 3, 68, 0.34);
    }

    60% {
        transform: scale(1);
        box-shadow: 0 0 0 12px rgba(165, 3, 68, 0);
    }

    100% {
        transform: scale(0.96);
        box-shadow: 0 0 0 0 rgba(165, 3, 68, 0);
    }
}

.food-group-disabled .food-row {
    opacity: 0.56;
}

.food-group-disabled .food-row input,
.food-group-disabled .food-row select {
    background: var(--surface-soft);
}

.compact-form {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.food-photo-picker {
    cursor: pointer;
}

.food-photo-title {
    color: var(--muted);
}

.food-photo-control {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.photo-pick-button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--brand-orange);
    color: #ffffff;
    font-weight: 700;
    padding: 10px 14px;
    box-shadow: 0 10px 22px rgba(255, 147, 10, 0.18);
    flex: 0 0 auto;
}

.food-photo-picker:hover .photo-pick-button,
.food-photo-picker:focus-within .photo-pick-button {
    background: #d9810e;
    color: #ffffff;
}

.photo-file-name {
    min-width: 0;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.visually-hidden-file {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    clip-path: inset(50%);
    pointer-events: none;
}

.ai-settings-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(19, 29, 39, 0.52);
}

.modal-overlay.hidden {
    display: none;
}

.modal-panel {
    width: min(560px, 100%);
    max-height: min(760px, calc(100vh - 36px));
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.confirm-panel {
    width: min(460px, 100%);
}

.scanner-panel {
    width: min(520px, 100%);
}

.scanner-video {
    width: 100%;
    aspect-ratio: 4 / 3;
    display: block;
    border-radius: 8px;
    background: var(--ink);
    object-fit: cover;
}

.confirm-text {
    color: var(--ink);
    margin-bottom: 18px;
}

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

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(420px, calc(100vw - 36px));
    background: var(--ink);
    color: #ffffff;
    border-radius: 8px;
    padding: 12px 14px;
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
    z-index: 50;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.notice {
    border-radius: 8px;
    padding: 12px;
    margin: 16px 0;
}

.notice.success {
    background: rgba(102, 165, 94, 0.14);
    color: var(--green);
}

.notice.danger {
    background: rgba(180, 35, 24, 0.08);
    color: var(--red);
}

.install-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 18px;
}

.install-shell {
    width: min(620px, 100%);
    padding: 28px;
}

.install-shell form {
    margin-top: 18px;
}

@media (max-width: 1100px) {
    .form-grid,
    .food-editor-form,
    .status-strip {
        grid-template-columns: 1fr 1fr;
    }

    .plan-output,
    .history-panel {
        grid-column: 1 / -1;
    }

    .food-row {
        grid-template-columns: minmax(170px, 1fr) repeat(3, minmax(80px, 1fr));
    }
}

@media (max-width: 900px) {
    .weight-chart-scroll {
        overflow-x: visible;
    }

    .weight-chart-frame {
        grid-template-columns: 40px minmax(0, 1fr);
        min-width: 0;
    }

    .weight-bars {
        gap: 6px;
    }

    .weight-bar {
        flex: 1 1 34px;
        max-width: 58px;
    }

    .weight-bar small {
        white-space: normal;
    }
}

@media (max-width: 760px) {
    body {
        padding-bottom: 74px;
    }

    .topbar {
        grid-template-columns: minmax(108px, 34vw) minmax(0, 1fr);
    }

    .topbar-actions {
        grid-column: 1 / -1;
        justify-content: stretch;
    }

    .logout-form,
    .main-tabs {
        width: 100%;
    }

    .logout-form {
        justify-content: space-between;
    }

    .main-tabs {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
        z-index: 55;
        width: auto;
        padding: 8px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: var(--shadow);
    }

    .main-tabs .tab-button {
        flex: 1;
    }

    .main-tabs .tab-button.active {
        display: none;
    }

    .workspace-grid,
    .form-grid,
    .food-editor-form,
    .user-form,
    .user-row,
    .status-strip,
    .plan-layout {
        grid-template-columns: 1fr;
    }

    .current-animal-card {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .current-animal-actions {
        grid-column: 1 / -1;
        justify-content: stretch;
    }

    .current-animal-actions .secondary-button {
        width: 100%;
    }

    .editor-panel {
        order: 2;
    }

    .list-panel {
        order: 1;
    }

    .ai-settings-entry,
    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .settings-accordion > summary {
        align-items: flex-start;
        padding: 14px;
    }

    .settings-summary-meta {
        align-items: flex-end;
        flex-direction: column-reverse;
        gap: 6px;
    }

    .settings-panel-body {
        padding: 0 14px 14px;
    }

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

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

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

    .form-actions {
        align-items: stretch;
    }

    .form-actions > button {
        width: 100%;
    }

    .history-card-header {
        align-items: stretch;
        flex-direction: column;
    }

    .history-actions {
        width: 100%;
    }

    .history-actions button {
        flex: 1;
    }

    .segmented-control {
        display: flex;
        width: 100%;
    }

    .segment-button {
        flex: 1;
    }
}

@media (max-width: 520px) {
    .topbar {
        gap: 10px;
        padding: 12px;
    }

    .brand-logo {
        width: min(38vw, 140px);
    }

    h1 {
        font-size: 1.08rem;
    }

    main {
        padding: 10px;
    }

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

    .plan-view {
        padding: 10px;
    }

    .plan-row-field {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .weight-chart-frame {
        grid-template-columns: 34px minmax(0, 1fr);
    }

    .weight-chart-plot {
        padding: 10px 8px 30px;
    }

    .weight-bars {
        gap: 4px;
    }

    .weight-bar {
        flex: 1 1 24px;
        max-width: 46px;
    }

    .weight-bar-fill .weight-value,
    .weight-bar-fill .weight-status,
    .weight-bar small {
        font-size: 0.68rem;
    }

    .list-panel,
    .editor-panel,
    .settings-panel,
    .weight-chart-panel,
    .plan-output,
    .history-panel,
    .modal-panel {
        padding: 12px;
    }

    .settings-accordion {
        padding: 0;
    }

    .settings-accordion > summary {
        padding: 12px;
    }

    .settings-panel-body {
        padding: 0 12px 12px;
    }

    .food-photo-control {
        align-items: stretch;
        flex-direction: column;
    }

    .photo-pick-button {
        width: 100%;
    }

    .photo-file-name {
        white-space: normal;
    }

    .tab-button,
    .secondary-button,
    .primary-button,
    .accent-button,
    .primary-link,
    .danger-button,
    .icon-button {
        white-space: normal;
    }

    .status-strip {
        gap: 8px;
    }

    .toast {
        right: 10px;
        bottom: 10px;
        max-width: calc(100vw - 20px);
    }
}
