:root {
    --bg: #f4f6f9;
    --bg-accent: #e8f0ff;
    --bg-accent-2: #f4f6f9;
    --surface: #ffffff;
    --text: #1a202c;
    --muted: #5f6b7a;
    --primary: #1f6feb;
    --primary-2: #0a4bb3;
    --border: #d8dee8;
    --success: #1f8a45;
    --error: #b42318;
    --link: #0a57c2;
    --link-hover: #073f8b;
    --header-bg: rgba(255, 255, 255, 0.92);
    --chip-border: #9ea7b4;
    --shadow: 0 12px 30px rgba(11, 31, 68, 0.08);
    --title-fill: #1f2a3b;
    --editable-cursor: url('/images/pencil-cursor-yellow.svg') 2 18, text;
}

:root[data-theme="dark"] {
    --bg: #0d1117;
    --bg-accent: #121b2b;
    --bg-accent-2: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #9ba7b7;
    --primary: #4b9eff;
    --primary-2: #2f6cd3;
    --border: #2d3746;
    --success: #4fb575;
    --error: #f26d6d;
    --link: #8ec5ff;
    --link-hover: #b9dcff;
    --header-bg: rgba(22, 27, 34, 0.9);
    --chip-border: #4d5969;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    --title-fill: #f3f7fc;
    --editable-cursor: url('/images/pencil-cursor-yellow.svg') 2 18, text;
}

:root[data-theme="rainbow"] {
    --bg: #fff6fd;
    --bg-accent: #ffe8f7;
    --bg-accent-2: #e7f6ff;
    --surface: #ffffff;
    --text: #2d183a;
    --muted: #6f5b80;
    --primary: #e65188;
    --primary-2: #7c4dff;
    --border: #e7c8df;
    --success: #1e9960;
    --error: #d13f63;
    --link: #3e4bd0;
    --link-hover: #7c2fbe;
    --header-bg: rgba(244, 219, 236, 0.96);
    --chip-border: #c5a3bf;
    --shadow: 0 12px 30px rgba(90, 45, 120, 0.14);
    --title-fill: linear-gradient(
        92deg,
        #e65188 0%,
        #ff6b9a 18%,
        #7c4dff 36%,
        #2f8bff 54%,
        #12b886 72%,
        #f6b73c 88%,
        #e65188 100%
    );
    --editable-cursor: url('/images/pencil-cursor-rainbow.svg') 2 18, text;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    background: radial-gradient(circle at top right, var(--bg-accent) 0%, var(--bg-accent-2) 38%, var(--bg) 75%);
    color: var(--text);
}

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    backdrop-filter: blur(6px);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 0;
}

.logo {
    display: block;
    width: 44px;
    height: 44px;
    background: url("/images/logo.svg") center / contain no-repeat;
}

:root[data-theme="dark"] .logo {
    filter: brightness(0) invert(1);
}

:root[data-theme="rainbow"] .logo {
    filter: saturate(1.35) hue-rotate(8deg);
}

@supports ((-webkit-mask: url("/images/logo.svg")) or (mask: url("/images/logo.svg"))) {
    .logo {
        background: var(--title-fill);
        filter: none;
        -webkit-mask: url("/images/logo.svg") center / contain no-repeat;
        mask: url("/images/logo.svg") center / contain no-repeat;
    }
}

.brand-title {
    margin: 0;
    line-height: 0;
}

.brand-title-image {
    display: block;
    width: min(300px, 62vw);
    aspect-ratio: 600 / 116;
    background: url("/images/title.png") center / contain no-repeat;
}

:root[data-theme="dark"] .brand-title-image {
    filter: brightness(0) invert(1);
}

:root[data-theme="rainbow"] .brand-title-image {
    filter: saturate(1.35) hue-rotate(8deg);
}

@supports ((-webkit-mask: url("/images/title.png")) or (mask: url("/images/title.png"))) {
    .brand-title-image {
        background: var(--title-fill);
        filter: none;
        -webkit-mask: url("/images/title.png") center / contain no-repeat;
        mask: url("/images/title.png") center / contain no-repeat;
    }
}

a {
    color: var(--link);
}

a:hover {
    color: var(--link-hover);
}

.brand-wrap p {
    margin: 0.1rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.top-nav {
    display: flex;
    gap: 0.95rem;
    flex-wrap: wrap;
}

.top-nav a {
    text-decoration: none;
    color: var(--link);
    font-weight: 600;
}

.top-nav a:hover {
    color: var(--link-hover);
}

.container {
    max-width: 1100px;
    margin: 1.7rem auto;
    padding: 0 1rem 2rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 1.15rem;
    margin-bottom: 1rem;
}

.auth-card {
    max-width: 520px;
    margin: 2.2rem auto;
}

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

h2,
h3 {
    margin-top: 0;
}

.row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.row-wrap {
    flex-wrap: wrap;
}

.row-space {
    justify-content: space-between;
}

.inline-left {
    flex: 1;
}

.search-form {
    justify-content: flex-end;
}

.form-grid,
.inline-form {
    display: flex;
    gap: 0.7rem;
    align-items: end;
    flex-wrap: wrap;
}

.form-grid {
    flex-direction: column;
    align-items: stretch;
}

.card-section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.93rem;
    font-weight: 600;
}

.grow {
    flex: 1;
}

input,
button,
select,
textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    padding: 0.55rem 0.65rem;
    background: var(--surface);
    color: var(--text);
}

button {
    background: linear-gradient(160deg, var(--primary), var(--primary-2));
    color: #fff;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    filter: brightness(1.07);
}

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

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

th,
td {
    padding: 0.65rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 0.84rem;
}

.strong {
    font-weight: 700;
}

.alert {
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
}

.alert-error {
    background: #ffe4e2;
    color: var(--error);
}

.alert-success {
    background: #def7e8;
    color: var(--success);
}

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

.list-clean li {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0;
}

.pagination {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    flex-wrap: wrap;
}

.page-current {
    font-weight: 700;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.2rem 0.5rem;
    background: var(--surface);
}

.status-ok {
    color: var(--success);
    font-weight: 700;
}

.status-not-ok {
    color: var(--error);
    font-weight: 700;
}

.row-needs-floss td {
    background: color-mix(in srgb, var(--error) 10%, transparent);
}

.row-needs-floss td:first-child {
    border-left: 3px solid var(--error);
}

.floss-preview {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.48rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 230px;
}

.floss-preview-text {
    min-width: 0;
}

.floss-preview-text [data-floss-name] {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chip {
    display: inline-block;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    max-width: 20px;
    max-height: 20px;
    flex: 0 0 20px;
    border-radius: 4px;
    border: 1px solid var(--chip-border);
    background: #fff;
}

.chip-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.buy-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--link);
    text-decoration: none;
}

.buy-link:hover {
    color: var(--link-hover);
    background: var(--bg-accent);
}

.buy-icon {
    width: 13px;
    height: 13px;
    display: block;
    background: currentColor;
    -webkit-mask: url('/images/buy.svg') center / contain no-repeat;
    mask: url('/images/buy.svg') center / contain no-repeat;
}

.pattern-name-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.pattern-thumb {
    display: inline-block;
    border: 1px solid var(--chip-border);
    border-radius: 4px;
    background: var(--surface);
    object-fit: cover;
    flex: 0 0 auto;
}

.pattern-thumb-chip {
    width: 20px;
    height: 20px;
}

.pattern-thumb-large {
    width: 100px;
    height: 100px;
    border-radius: 10px;
}

.pattern-thumb-placeholder {
    background: linear-gradient(160deg, var(--bg-accent), var(--surface));
}

.pattern-header-main {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.pattern-header-main h2 {
    margin: 0 0 0.2rem;
}

.pattern-header-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.pattern-header-details .muted {
    margin: 0;
}

.pattern-metadata-line {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.pattern-meta-separator {
    color: var(--border);
    padding: 0 0.15rem;
}

.thumbnail-upload-form {
    margin: 0;
}

.thumbnail-upload-label {
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.thumbnail-upload-hint {
    position: absolute;
    right: 6px;
    bottom: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.35rem;
    border-radius: 999px;
    background: rgba(10, 12, 18, 0.72);
    color: #fff;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.thumbnail-upload-label:hover .thumbnail-upload-hint,
.thumbnail-upload-label:focus-within .thumbnail-upload-hint {
    opacity: 1;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.owned-input {
    width: 90px;
    text-align: right;
}

.table-num {
    width: 7ch;
}

.editable-cell {
    position: relative;
    cursor: var(--editable-cursor);
    min-width: 8ch;
}

.editable-cell[data-field="stitch_count"] {
    width: 9ch;
}

.editable-cell[data-field="strand_count"] {
    width: 6ch;
}

.editable-cell [data-value-display] {
    display: inline-block;
    width: 100%;
}

.editable-cell [data-inline-input] {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 100%;
    padding: 0.2rem 0.35rem;
    visibility: hidden;
    pointer-events: none;
}

.editable-cell.editing [data-value-display] {
    visibility: hidden;
}

.editable-cell.editing [data-inline-input] {
    visibility: visible;
    pointer-events: auto;
}

.inline-editable {
    position: relative;
    display: inline-block;
    cursor: var(--editable-cursor);
}

.inline-editable [data-inline-editor] {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    visibility: hidden;
    pointer-events: none;
    width: 100%;
}

.inline-editable.editing [data-value-display] {
    visibility: hidden;
}

.inline-editable.editing [data-inline-editor] {
    visibility: visible;
    pointer-events: auto;
}

.inline-editable.editing {
    z-index: 80;
}

.pattern-name-editable {
    min-width: 16ch;
    max-width: 34ch;
}

.pattern-name-editable [data-inline-editor] {
    min-width: 16ch;
    padding: 0.2rem 0.4rem;
}

.pattern-grid-editable {
    min-width: 3ch;
    text-align: right;
}

.pattern-grid-editable [data-inline-editor] {
    width: auto;
    min-width: 7ch;
}

.pattern-source-editable {
    min-width: 24ch;
    max-width: 74ch;
}

.pattern-source-editable [data-value-display] {
    display: inline-flex;
    align-items: center;
    max-width: 58ch;
}

.pattern-source-editable [data-source-name-text] {
    display: inline-block;
    max-width: 58ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pattern-source-editable [data-inline-editor] {
    width: auto;
}

.source-inline-editor-wrap {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.45rem;
    box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.34), var(--shadow);
}

.source-inline-editor-wrap input {
    min-width: 32ch;
    padding: 0.25rem 0.45rem;
}

.source-inline-editor-wrap input[type="url"] {
    min-width: 50ch;
    order: 1;
}

.source-url-ghost-wrap {
    position: relative;
    display: inline-block;
    order: 1;
}

.source-url-ghost {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: 0.25rem 0.45rem;
    color: var(--muted);
    opacity: 0.55;
    pointer-events: none;
    z-index: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.source-inline-editor-wrap input[type="url"].source-url-input-ghosted {
    position: relative;
    z-index: 2;
    background: transparent;
}

.source-inline-editor-wrap input[data-source-name-input] {
    min-width: 24ch;
    order: 3;
}

.source-match-suggestion {
    display: inline-flex;
    align-items: center;
    margin-left: 0.15rem;
    order: 4;
}

.source-match-suggestion.reserve-space {
    margin-left: 0;
}

.source-match-suggestion[hidden] {
    display: none !important;
}

.source-match-suggestion.reserve-space[hidden] {
    display: inline-flex !important;
    visibility: hidden;
}

.source-match-slot {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    align-self: flex-end;
    min-width: 44px;
    min-height: 42px;
    margin-bottom: 0.05rem;
}

.source-match-accept {
    min-width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-accent);
    color: var(--success);
    line-height: 1;
    padding: 0 0.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.source-match-accept-icon {
    width: 13px;
    height: 13px;
    display: block;
    background: currentColor;
    -webkit-mask: url('/images/check.svg') center / contain no-repeat;
    mask: url('/images/check.svg') center / contain no-repeat;
}

.source-match-accept:hover {
    background: var(--surface);
    border-color: var(--success);
}

.source-match-accept:active {
    transform: translateY(1px);
}

.source-display-row {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    vertical-align: middle;
}

.pattern-fabric-editable {
    min-width: 16ch;
    max-width: 48ch;
}

.pattern-fabric-editable [data-inline-editor] {
    width: auto;
}

.pattern-fabric-editable [data-value-display] {
    display: inline-flex;
    align-items: center;
    max-width: 40ch;
}

.pattern-fabric-editable [data-fabric-name-text] {
    display: inline-block;
    max-width: 40ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fabric-inline-editor-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 26ch;
}

.fabric-inline-editor-wrap input[type="text"] {
    min-width: 24ch;
    padding: 0.22rem 0.42rem;
}

.fabric-suggestions {
    position: absolute;
    left: 0;
    top: calc(100% + 0.25rem);
    z-index: 400;
    min-width: max(100%, 36ch);
    max-width: 68ch;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 0.25rem;
}

.fabric-suggestion-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    border-radius: 6px;
    padding: 0.32rem 0.45rem;
}

.fabric-suggestion-item:hover,
.fabric-suggestion-item.active,
.fabric-suggestion-item:focus-visible {
    background: var(--bg-accent);
    border-color: var(--border);
    outline: none;
}

.fabric-suggestion-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--border);
    object-fit: cover;
    flex: 0 0 auto;
}

.fabric-suggestion-thumb-empty {
    background: color-mix(in srgb, var(--bg-accent) 50%, var(--surface));
    border-style: dashed;
}

.fabric-suggestion-label {
    display: block;
    line-height: 1.25;
    white-space: normal;
}

.fabric-suggestion-label-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.fabric-suggestion-catalog-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.24rem;
    width: fit-content;
    padding: 0.16rem 0.42rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--link) 32%, var(--border));
    background: color-mix(in srgb, var(--link) 10%, var(--surface));
    color: color-mix(in srgb, var(--link) 68%, var(--text));
    font-size: 0.69rem;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.fabric-suggestion-catalog-icon {
    width: 11px;
    height: 11px;
    display: inline-block;
    background: currentColor;
    -webkit-mask: url('/images/buy.svg') center / contain no-repeat;
    mask: url('/images/buy.svg') center / contain no-repeat;
}

.fabric-url-link {
    display: inline-block;
    max-width: 62ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.fabric-preview-image-wrap {
    margin-top: 0;
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 0 0 auto;
    align-self: flex-start;
    margin-top: 1.55rem;
}

.fabric-preview-image {
    width: 92px;
    height: 92px;
    border: 1px solid var(--border);
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface);
}

.fabric-preview-image.is-empty {
    border-style: dashed;
    background: color-mix(in srgb, var(--bg-accent) 50%, var(--surface));
}

.fabric-preview-picker {
    cursor: pointer;
}

.fabric-preview-picker::after {
    content: "Click to upload";
    font-size: 0.75rem;
    color: var(--muted);
}

.fabric-add-description {
    flex: 1 1 100%;
}

.fabric-add-meta-row {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
}

.fabric-add-meta-fields {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.fabric-inline-upload {
    display: inline-flex;
    margin: 0;
}

.fabric-thumb-upload-picker {
    cursor: pointer;
}

.fabric-thumb-upload-picker::after {
    content: none;
}

.admin-fabric-image {
    width: min(220px, 60vw);
    height: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.admin-menu {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.admin-menu .mini-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.8rem;
    font-size: 0.94rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--link);
}

.admin-menu .mini-btn.active {
    border-color: var(--link);
    color: var(--link);
    background: var(--bg-accent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--link) 35%, transparent);
}

.admin-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    line-height: 1;
    padding: 0 0.33rem;
    background: var(--error);
    color: #fff;
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.7rem;
}

.admin-stat-card {
    border: 1px solid var(--border);
    background: var(--bg-accent);
    border-radius: 10px;
    padding: 0.55rem 0.65rem;
}

.admin-stat-value {
    font-weight: 800;
    font-size: 1.45rem;
    line-height: 1.2;
}

.pattern-delete-card form {
    margin-top: 0.35rem;
}

.external-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--link);
    text-decoration: none;
}

.external-link:hover {
    color: var(--link-hover);
    background: var(--bg-accent);
}

.external-link-icon {
    width: 13px;
    height: 13px;
    display: block;
    background: currentColor;
    -webkit-mask: url('/images/external-link.svg') center / contain no-repeat;
    mask: url('/images/external-link.svg') center / contain no-repeat;
}

.source-patterns-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--link);
    text-decoration: none;
}

.source-patterns-link:hover {
    color: var(--link-hover);
    background: var(--bg-accent);
}

.source-patterns-icon {
    width: 13px;
    height: 13px;
    display: block;
    background: currentColor;
    -webkit-mask: url('/images/magnify.svg') center / contain no-repeat;
    mask: url('/images/magnify.svg') center / contain no-repeat;
}

.external-link[hidden],
.source-patterns-link[hidden] {
    display: none !important;
}

.align-right {
    text-align: right;
}

.align-left {
    text-align: left;
}

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

.align-right .table-num {
    text-align: right;
}

.align-center .table-num {
    text-align: center;
}

.row-actions {
    white-space: nowrap;
}

.mini-btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.85rem;
    text-decoration: none;
    display: inline-block;
}

.compact-field input {
    width: 8ch;
}

.compact-field-code input {
    width: 10ch;
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    width: 42px;
    height: 42px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.theme-toggle:hover {
    transform: translateY(-1px);
}

.theme-toggle-icon {
    width: 20px;
    height: 20px;
    display: block;
    background: currentColor;
    -webkit-mask: url('/images/bobbin.svg') center / contain no-repeat;
    mask: url('/images/bobbin.svg') center / contain no-repeat;
}

:root[data-theme="rainbow"] .theme-toggle-icon {
    background: linear-gradient(160deg, var(--primary), var(--primary-2));
}

.theme-menu-wrap {
    position: relative;
}

.theme-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.45rem);
    min-width: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 0.3rem;
    z-index: 20;
}

.theme-option {
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--text);
    border: 1px solid transparent;
    border-radius: 7px;
    font-weight: 600;
    padding: 0.45rem 0.55rem;
}

.theme-option:hover {
    background: var(--bg-accent);
}

.theme-option.active {
    border-color: var(--border);
    background: var(--bg-accent);
}

.text-link-btn {
    background: transparent;
    border: none;
    color: var(--link);
    padding: 0;
    font-weight: 600;
    box-shadow: none;
}

.text-link-btn:hover {
    color: var(--link-hover);
    filter: none;
    text-decoration: underline;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 18, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    padding: 1rem;
}

.modal-backdrop[hidden] {
    display: none !important;
}

.modal-panel {
    width: min(760px, 96vw);
    max-height: 88vh;
    overflow: auto;
    box-shadow: 0 20px 44px rgba(0, 0, 0, 0.34), var(--shadow);
}

textarea {
    width: 100%;
    resize: vertical;
}

@media (max-width: 860px) {
    .grid-two {
        grid-template-columns: 1fr;
    }

    .site-header {
        flex-direction: column;
        align-items: start;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .list-clean li {
        flex-direction: column;
        gap: 0.2rem;
    }

    .compact-field input,
    .compact-field-code input {
        width: 100%;
    }

    .modal-panel {
        width: 100%;
    }
}

.owned-input.error {
    border-color: var(--error);
}

.shortcut-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    padding: 0.28rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-accent);
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stitch-counter-name {
    font-weight: 600;
}

.stitch-counter-count {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.stitch-counter-actions {
    justify-content: flex-end;
}

.stitch-counter-input-wrap {
    position: relative;
    display: block;
    width: 100%;
}

.stitch-counter-input-wrap input {
    width: 100%;
}

.stitch-counter-dropdown {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    z-index: 25;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.45rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.stitch-counter-dropdown[hidden] {
    display: none !important;
}

.stitch-counter-suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.stitch-counter-suggestion:hover,
.stitch-counter-suggestion.active,
.stitch-counter-suggestion:focus-visible {
    background: var(--bg-accent);
    border-color: var(--border);
    outline: none;
}

.stitch-counter-suggestion-labels {
    display: flex;
    flex-direction: column;
    gap: 0.08rem;
    min-width: 0;
}

.stitch-counter-suggestion-label {
    font-weight: 600;
}

.stitch-counter-suggestion-meta {
    color: var(--muted);
    font-size: 0.84rem;
}

.stitch-counter-panel-actions {
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
}

.stitch-counter-history {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.stitch-counter-history:empty {
    display: none;
}

.stitch-counter-history-item {
    display: flex;
    align-items: baseline;
    gap: 0.7rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-soft);
}

.stitch-counter-history-time {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.84rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stitch-counter-history-text {
    min-width: 0;
    font-weight: 600;
}
