:root {
    color-scheme: light dark;

    --terracotta: #D45B28;
    --blush: #F4C2C2;
    --tint: #0E5CC9;

    --canvas: #FFFFFF;
    --sidebar: #EFEFF2;
    --group: #F7F7F9;
    --fill: rgba(118, 118, 128, 0.12);
    --fill-strong: rgba(118, 118, 128, 0.2);
    --separator: rgba(60, 60, 67, 0.16);
    --hairline: rgba(60, 60, 67, 0.11);
    --label: #1C1C1E;
    --label-secondary: rgba(60, 60, 67, 0.62);
    --label-tertiary: rgba(60, 60, 67, 0.32);
    --red: #C6362C;
    --green: #248A3D;
    --chrome: rgba(255, 255, 255, 0.78);

    --radius-group: 10px;
    --radius-control: 7px;
    --inset: 12px;
    --sidebar-width: 218px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --canvas: #1E1E20;
        --sidebar: #131315;
        --group: #29292C;
        --fill: rgba(118, 118, 128, 0.28);
        --fill-strong: rgba(118, 118, 128, 0.42);
        --separator: rgba(84, 84, 88, 0.65);
        --hairline: rgba(84, 84, 88, 0.45);
        --label: #F2F2F7;
        --label-secondary: rgba(235, 235, 245, 0.6);
        --label-tertiary: rgba(235, 235, 245, 0.32);
        --tint: #4C8DF6;
        --terracotta: #F0764A;
        --red: #FF6961;
        --green: #30D158;
        --chrome: rgba(30, 30, 32, 0.78);
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--canvas);
    color: var(--label);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 13px;
    line-height: 1.45;
    letter-spacing: -0.005em;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--tint);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.shell {
    display: flex;
    min-height: 100vh;
    align-items: flex-start;
}

.sidebar {
    position: sticky;
    top: 0;
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 10px 12px;
    background: var(--sidebar);
    border-right: 0.5px solid var(--separator);
}

.sidebar .brand {
    display: block;
    padding: 4px 10px 14px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--label);
}

.sidebar .brand:hover {
    text-decoration: none;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 400;
    color: var(--label);
}

.sidebar nav a svg {
    flex: 0 0 16px;
    color: var(--tint);
    opacity: 0.9;
}

.sidebar nav a:hover {
    background: var(--fill);
    text-decoration: none;
}

.sidebar nav a.active {
    background: var(--tint);
    color: #fff;
    font-weight: 500;
}

.sidebar nav a.active svg {
    color: #fff;
}

.sidebar .logout {
    padding: 6px 10px;
    font-size: 12px;
    color: var(--label-secondary);
    border-radius: 6px;
}

.sidebar .logout:hover {
    background: var(--fill);
    text-decoration: none;
}

.content {
    flex: 1;
    min-width: 0;
    padding: 0 28px 80px;
}

.centered {
    max-width: 320px;
    margin: 15vh auto 0;
    padding: 0 20px;
}

h1 {
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin: 0;
}

.page-head {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 56px;
    margin: 0 -28px 18px;
    padding: 0 28px;
    background: var(--chrome);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--hairline);
}

.card {
    background: var(--group);
    border: 0.5px solid var(--hairline);
    border-radius: var(--radius-group);
    padding: 14px 16px;
}

button,
.button {
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--label);
    background: var(--canvas);
    border: 0.5px solid var(--separator);
    border-radius: var(--radius-control);
    padding: 4px 11px;
    cursor: pointer;
    transition: background-color 0.12s ease;
}

button:hover,
.button:hover {
    background: var(--fill);
    text-decoration: none;
}

button:active,
.button:active {
    background: var(--fill-strong);
}

.primary,
button.primary {
    background: var(--terracotta);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}

.primary:hover,
button.primary:hover {
    background: var(--terracotta);
    filter: brightness(1.08);
}

.danger,
button.danger {
    color: var(--red);
}

input,
select,
textarea {
    font: inherit;
    font-size: 13px;
    color: var(--label);
    background: var(--canvas);
    border: 0.5px solid var(--separator);
    border-radius: var(--radius-control);
    padding: 4px 8px;
    max-width: 100%;
    appearance: none;
    -webkit-appearance: none;
}

select {
    padding-right: 26px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' d='M3.4 5 6 7.6 8.6 5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 11px;
    cursor: pointer;
}

input::placeholder,
textarea::placeholder {
    color: var(--label-tertiary);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--tint) 40%, transparent);
    outline-offset: 0;
    border-color: var(--tint);
}

textarea {
    width: 100%;
    resize: vertical;
    line-height: 1.5;
    padding: 7px 9px;
}

label {
    display: block;
    font-size: 12px;
    color: var(--label-secondary);
    margin: 12px 0 4px;
}

.form input:not([type="checkbox"]),
.form select {
    width: 100%;
    max-width: 460px;
}

fieldset {
    border: none;
    border-top: 0.5px solid var(--hairline);
    margin: 16px 0 0;
    padding: 12px 0 0;
}

legend {
    font-size: 12px;
    font-weight: 600;
    color: var(--label-secondary);
    padding: 0;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 4px 18px 4px 0;
    font-size: 13px;
    cursor: pointer;
}

.check input {
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--tint);
    appearance: auto;
    -webkit-appearance: checkbox;
    border: none;
}

.inline {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-top: 8px;
}

.inline label {
    margin-top: 0;
}

.filters {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.filters input[type="search"] {
    min-width: 220px;
}

.reset {
    font-size: 12.5px;
}

.count {
    font-size: 11.5px;
    color: var(--label-tertiary);
    margin: 0 0 6px;
    padding-left: 2px;
}

.rows,
.items,
.plain {
    list-style: none;
    margin: 0;
    padding: 0;
}

.rows {
    background: var(--group);
    border: 0.5px solid var(--hairline);
    border-radius: var(--radius-group);
    overflow: hidden;
}

.rows > li {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 0;
    padding: 7px var(--inset);
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border-top: 0.5px solid var(--hairline);
}

.rows > li:first-child {
    border-top: none;
}

.rows > li:hover {
    background: var(--fill);
}

.row-body {
    flex: 1;
    min-width: 0;
}

.row-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--label);
}

.row-title:hover {
    text-decoration: none;
    color: var(--tint);
}

.row-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.rows > li:hover .row-actions,
.row-actions:focus-within {
    opacity: 1;
}

.row-actions a {
    font-size: 12.5px;
    padding: 4px 9px;
    border-radius: var(--radius-control);
    border: 0.5px solid var(--separator);
    color: var(--label);
}

.row-actions a:hover {
    background: var(--canvas);
    text-decoration: none;
}

.meta,
.preview,
.intention {
    font-size: 11.5px;
    color: var(--label-secondary);
    margin: 1px 0 0;
}

.intention {
    font-style: italic;
}

.preview {
    white-space: pre-wrap;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

.chips {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
    margin: 3px 0 0;
}

.chip {
    background: var(--blush);
    color: #9E3A12;
    font-size: 10.5px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
}

.star {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--terracotta);
    margin-left: 5px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--tint) 15%, transparent);
    color: var(--tint);
    font-size: 10px;
    font-weight: 700;
}

.empty {
    color: var(--label-secondary);
    text-align: center;
    padding: 34px 20px;
}

.error,
.saved {
    font-size: 12.5px;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 0 0 14px;
}

.error {
    background: color-mix(in srgb, var(--red) 12%, transparent);
    color: var(--red);
}

.saved {
    background: color-mix(in srgb, var(--green) 14%, transparent);
    color: var(--green);
}

.centered h1 {
    font-size: 20px;
    text-align: center;
}

.centered .lead {
    font-size: 12.5px;
    color: var(--label-secondary);
    text-align: center;
    margin: 5px 0 22px;
}

.centered form {
    padding: 16px;
}

.centered label {
    margin-top: 0;
}

.centered input,
.centered button {
    width: 100%;
}

.centered button {
    margin-top: 14px;
    padding: 7px;
    font-size: 13px;
}

.scroll-list {
    max-height: 210px;
    overflow-y: auto;
    background: var(--canvas);
    border: 0.5px solid var(--separator);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
}

.filter-input {
    width: 100%;
    max-width: 280px;
}

.settings {
    margin-bottom: 14px;
}

.block {
    margin-bottom: 14px;
    padding-bottom: 4px;
}

.block-head {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
    padding-bottom: 10px;
    border-bottom: 0.5px solid var(--hairline);
}

.block-name {
    flex: 1;
    min-width: 160px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--terracotta);
    background: transparent;
    border-color: transparent;
}

.block-name:hover {
    background: var(--canvas);
    border-color: var(--separator);
}

.block-head button {
    font-size: 12px;
    padding: 3px 9px;
}

.section {
    padding: 10px 0 2px;
    border-bottom: 0.5px solid var(--hairline);
}

.section:last-of-type {
    border-bottom: none;
}

.section-head {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
}

.section-head input {
    flex: 1;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--label-secondary);
    background: transparent;
    border-color: transparent;
}

.section-head input:hover {
    background: var(--canvas);
    border-color: var(--separator);
}

.section-head button {
    font-size: 12px;
    padding: 3px 9px;
}

.items > li {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 7px 0;
    border-top: 0.5px solid var(--hairline);
}

.items > li:first-child {
    border-top: none;
}

.item-body {
    flex: 1;
    min-width: 0;
}

.item-body > select {
    font-size: 13px;
    font-weight: 500;
    max-width: 100%;
}

.item-tools {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 5px;
}

.item-tools select,
.item-tools input {
    font-size: 12px;
    padding: 3px 7px;
}

.item-tools select {
    padding-right: 22px;
}

.item-tools input[type="number"] {
    width: 66px;
}

.item-controls {
    display: flex;
    gap: 3px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.item-controls button {
    font-size: 12px;
    padding: 3px 8px;
}

.item-controls select {
    font-size: 12px;
    padding: 3px 22px 3px 7px;
    max-width: 140px;
}

.unit {
    font-size: 11.5px;
    color: var(--label-secondary);
    font-variant-numeric: tabular-nums;
}

.flow {
    background: color-mix(in srgb, var(--blush) 26%, transparent);
    border-radius: 8px;
    padding: 8px 10px;
    margin: 4px 0;
}

.flow-badge {
    background: var(--blush);
    color: #9E3A12;
    font-size: 10.5px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
}

.peak.on {
    background: var(--terracotta);
    border-color: transparent;
    color: #fff;
}

.section-add {
    display: flex;
    gap: 6px;
    margin: 10px 0 4px;
    flex-wrap: wrap;
}

.add-block {
    width: 100%;
    padding: 9px;
}

.save-bar {
    position: sticky;
    bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--chrome);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 0.5px solid var(--separator);
    border-radius: var(--radius-group);
    padding: 9px 12px;
    margin-top: 14px;
}

.save-bar button {
    padding: 6px 16px;
    font-size: 13px;
}

#summary {
    font-size: 13px;
    font-weight: 600;
    color: var(--terracotta);
    font-variant-numeric: tabular-nums;
}

.plain li {
    padding: 3px 0;
    font-size: 12.5px;
}

@media (max-width: 820px) {
    .shell {
        flex-direction: column;
    }

    .sidebar {
        position: static;
        width: 100%;
        flex: none;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        padding: 8px 14px;
        border-right: none;
        border-bottom: 0.5px solid var(--separator);
        overflow-x: auto;
    }

    .sidebar .brand {
        padding: 0 10px 0 0;
    }

    .sidebar nav {
        flex-direction: row;
        gap: 4px;
    }

    .content {
        padding: 0 14px 60px;
        width: 100%;
    }

    .page-head {
        margin: 0 -14px 14px;
        padding: 0 14px;
    }

    .rows > li,
    .items > li {
        flex-direction: column;
        align-items: stretch;
    }

    .row-actions {
        opacity: 1;
        justify-content: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
