:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --line: #e4e9f1;
    --line-strong: #d4dce8;
    --text: #202a37;
    --muted: #667085;
    --faint: #98a2b3;
    --primary: #ff2f55;
    --primary-dark: #df1f42;
    --primary-soft: #fff1f4;
    --blue: #1263d6;
    --blue-soft: #eaf2ff;
    --green: #178b57;
    --green-soft: #eaf7ef;
    --amber: #b7791f;
    --amber-soft: #fff7df;
    --danger: #d92d20;
    --danger-soft: #fff1f0;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, label { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: 0.58; }
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration { display: none; }

.container {
    width: min(100%, 920px);
    margin: 0 auto;
    padding: 22px 18px 38px;
    position: relative;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0 18px;
    min-width: 0;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 1.35rem;
    font-weight: 900;
    box-shadow: var(--shadow-sm);
}

.brand-copy {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    transition: flex-basis 0.22s ease, opacity 0.18s ease, transform 0.22s ease;
}

h1 {
    color: var(--text);
    margin: 0;
    font-size: 1.65rem;
    line-height: 1.15;
    font-weight: 850;
    white-space: nowrap;
}

.header-search {
    position: relative;
    flex: 0 0 auto;
    width: 82px;
    height: 42px;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: text;
    overflow: hidden;
    transition: width 0.24s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.header-search.expanded {
    width: min(320px, 38vw);
    background: var(--surface);
    border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(32, 42, 55, 0.08), var(--shadow-sm);
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 14px;
    width: 14px;
    height: 14px;
    border: 2px solid var(--blue);
    border-radius: 50%;
    transform: translateY(-50%);
    transition: border-color 0.2s ease, opacity 0.2s ease;
}

.search-icon::after {
    content: "";
    position: absolute;
    right: -5px;
    bottom: -3px;
    width: 7px;
    height: 2px;
    border-radius: 999px;
    background: var(--blue);
    transform: rotate(45deg);
    transform-origin: left center;
    transition: background-color 0.2s ease;
}

.header-search.expanded .search-icon {
    border-color: var(--text);
}

.header-search.expanded .search-icon::after {
    background: var(--text);
}

.search-short-label {
    position: absolute;
    left: 39px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--blue);
    font-size: 0.9rem;
    font-weight: 780;
    line-height: 1;
    white-space: nowrap;
    transition: opacity 0.14s ease, transform 0.18s ease;
}

.header-search.expanded .search-short-label {
    opacity: 0;
    transform: translate(-6px, -50%);
    pointer-events: none;
}

.keyword-search-input {
    width: 100%;
    height: 100%;
    padding: 0 39px 0 42px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 720;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease;
}

.keyword-search-input::placeholder {
    color: var(--faint);
}

.header-search.expanded .keyword-search-input {
    opacity: 1;
    pointer-events: auto;
}

.search-clear-btn {
    position: absolute;
    top: 50%;
    right: 7px;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 1rem;
    line-height: 1;
    transform: translateY(-50%);
}

.search-clear-btn:hover {
    background: #eef2f7;
    color: var(--text);
}

.search-clear-btn[hidden] { display: none; }

.action-btn,
.delete-btn,
.tab-btn,
.filter-btn,
.copy-btn,
.manual-use-btn,
.icon-btn,
.edit-btn-save,
.edit-btn-cancel,
.load-more-btn,
.confirm-cancel,
.confirm-ok,
.category-add-btn,
.category-remove-btn,
.modal-close-btn,
.search-clear-btn {
    border: none;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.batch-control {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.batch-left,
.batch-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.batch-select-wrap {
    display: block;
    flex: 0 0 auto;
    color: var(--muted);
}

.batch-select-wrap select {
    width: auto;
    min-width: 158px;
    max-width: 190px;
    padding: 8px 30px 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--line-strong);
    outline: none;
    background: var(--surface-soft);
    color: var(--text);
    cursor: pointer;
}

.batch-select-wrap select:focus,
.edit-input:focus,
.edit-textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(18, 99, 214, 0.12);
}

.action-btn {
    min-height: 38px;
    padding: 8px 13px;
    border-radius: var(--radius);
    font-weight: 750;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.upload-btn {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 6px 14px rgba(18, 99, 214, 0.18);
}

.upload-btn:hover { background: #0f55b8; transform: translateY(-1px); }

.delete-btn {
    min-height: 38px;
    background: var(--surface);
    color: var(--danger);
    border: 1px solid #ffd0cc;
    border-radius: var(--radius);
    padding: 8px 13px;
    font-weight: 720;
}

.delete-btn:hover { background: var(--danger-soft); }

.tabs-wrapper {
    position: sticky;
    top: 0;
    z-index: 100;
    margin: 0 -18px 16px;
    padding: 10px 18px 12px;
    background: rgba(245, 247, 251, 0.96);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.tabs-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.tabs-container,
.filter-container {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.tabs-container,
.filter-container {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.tabs-container::-webkit-scrollbar,
.filter-container::-webkit-scrollbar { display: none; }

.category-manage-btn {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--blue);
    font-size: 0.9rem;
    font-weight: 780;
    line-height: 1.4;
    white-space: nowrap;
    cursor: pointer;
}

.category-manage-btn:hover { color: #0f55b8; }

.tab-btn,
.filter-btn {
    min-height: 36px;
    padding: 7px 13px;
    border-radius: 999px;
    white-space: nowrap;
    font-size: 0.9rem;
    font-weight: 760;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
}

.tab-btn:hover,
.filter-btn:hover { color: var(--primary); border-color: #ffc4cf; }

.tab-btn.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 8px 18px rgba(255, 47, 85, 0.22);
}

.filter-btn.active {
    color: var(--blue);
    background: var(--blue-soft);
    border-color: #9fc2ff;
}

.filter-container {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--line-strong);
}

.note-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}

.note-card:hover { box-shadow: var(--shadow-md); }

.note-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.note-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.note-index {
    font-size: 1rem;
    font-weight: 850;
    color: var(--text);
}

.note-score-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid #f4d48a;
    background: #fff8e6;
    color: #9a6400;
    font-size: 0.78rem;
    font-weight: 820;
    line-height: 1.1;
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
}

.manual-use-btn {
    border: 1px solid #ffd0cc;
    background: var(--danger-soft);
    color: var(--danger);
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    flex: 0 0 auto;
}

.manual-use-btn.restore {
    border-color: #bfe7cf;
    background: var(--green-soft);
    color: var(--green);
}

.icon-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: var(--radius);
    display: inline-grid;
    place-items: center;
    background: var(--surface-soft);
    border: 1px solid var(--line);
}

.icon-btn:hover { background: #eef2f7; }
.icon-btn-delete:hover { background: var(--danger-soft); border-color: #ffd0cc; }

.section { margin-bottom: 13px; }
.section:last-child { margin-bottom: 0; }

.section-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.section-title-left {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex-wrap: wrap;
}

.section-label,
.copy-state-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1.2;
}

.section-label {
    color: var(--text);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    padding: 5px 9px;
}

.copy-state-badge {
    background: var(--green-soft);
    color: var(--green);
    border: 1px solid #bfe7cf;
    padding: 4px 8px;
}

.copy-btn {
    min-height: 38px;
    min-width: 94px;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 820;
    line-height: 1.15;
    white-space: nowrap;
    box-shadow: 0 6px 14px rgba(255, 47, 85, 0.2);
}

.copy-btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.copy-btn.copied { background: var(--green); box-shadow: 0 6px 14px rgba(23, 139, 87, 0.2); }

.content-box {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 11px 12px;
    font-size: 0.95rem;
    line-height: 1.65;
    color: #354052;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.tag-box {
    color: var(--blue);
    background: #f4f8ff;
    border-color: #cfe0ff;
    font-weight: 650;
    margin-top: 8px;
}

.edit-container { display: none; margin-top: 10px; }

.edit-input,
.edit-textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 11px 12px;
    outline: none;
    background: var(--surface-soft);
    color: var(--text);
}

.edit-textarea {
    min-height: 86px;
    resize: none;
    overflow-y: hidden;
    line-height: 1.6;
}

.edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 4px;
}

.edit-btn-save,
.edit-btn-cancel {
    min-height: 38px;
    padding: 8px 15px;
    border-radius: var(--radius);
    font-weight: 780;
}

.edit-btn-save { background: var(--blue); color: #fff; }
.edit-btn-save:hover { background: #0f55b8; }
.edit-btn-cancel { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.edit-btn-cancel:hover { background: var(--surface-soft); }

.empty-state {
    min-height: 220px;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 28px 18px;
}

.empty-state strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
    font-size: 1.05rem;
}

.load-more-wrap {
    display: flex;
    justify-content: center;
    margin: 6px 0 20px;
}

.load-more-btn {
    min-height: 40px;
    padding: 9px 18px;
    border-radius: 999px;
    color: var(--blue);
    background: var(--blue-soft);
    border: 1px solid #cfe0ff;
    font-weight: 800;
}

.toast-root {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 1000;
    display: grid;
    gap: 8px;
    width: min(360px, calc(100vw - 28px));
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    padding: 11px 13px;
    border-radius: var(--radius);
    background: #172033;
    color: #fff;
    box-shadow: var(--shadow-md);
    font-size: 0.92rem;
    font-weight: 720;
    pointer-events: auto;
}

.toast.success { background: #0f6f46; }
.toast.error { background: #aa241a; }
.toast.info { background: #172033; }

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.38);
}

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

.confirm-dialog {
    width: min(360px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-md);
}

.confirm-dialog h2 {
    margin: 0 0 8px;
    font-size: 1.08rem;
}

.confirm-dialog p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.confirm-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 16px;
}

.confirm-cancel,
.confirm-ok {
    min-height: 40px;
    border-radius: var(--radius);
    font-weight: 800;
}

.confirm-cancel {
    background: var(--surface-soft);
    color: var(--muted);
    border: 1px solid var(--line);
}

.confirm-ok {
    background: var(--danger);
    color: #fff;
}

.category-dialog {
    width: min(560px, 100%);
    max-height: min(78vh, 680px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-md);
}

.category-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.category-dialog-header h2 {
    margin: 0;
    font-size: 1.08rem;
}

.modal-close-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    background: var(--surface-soft);
    color: var(--muted);
    border: 1px solid var(--line);
    font-size: 1.2rem;
    line-height: 1;
}

.modal-close-btn:hover { color: var(--text); border-color: var(--line-strong); }

.category-list {
    display: grid;
    gap: 10px;
    margin: 14px 0 12px;
    padding-right: 2px;
    overflow: auto;
}

.category-row {
    display: grid;
    grid-template-columns: minmax(96px, 0.34fr) minmax(0, 1fr) auto;
    gap: 8px;
    align-items: start;
}

.category-name-input,
.category-keywords-input {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--text);
    outline: none;
}

.category-name-input {
    min-height: 40px;
    padding: 8px 10px;
}

.category-keywords-input {
    min-height: 40px;
    resize: vertical;
    padding: 8px 10px;
    line-height: 1.45;
}

.category-name-input:focus,
.category-keywords-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(18, 99, 214, 0.12);
}

.category-remove-btn {
    min-height: 40px;
    padding: 8px 11px;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--danger);
    border: 1px solid #ffd0cc;
    font-weight: 760;
}

.category-remove-btn:hover { background: var(--danger-soft); }

.category-add-btn {
    align-self: flex-start;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--blue-soft);
    color: var(--blue);
    border: 1px solid #c7dcff;
    font-weight: 780;
}

.category-add-btn:hover { border-color: #9fc2ff; }

.category-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 14px;
}

.category-save-btn {
    background: var(--blue);
}

.category-empty {
    padding: 16px 12px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

@media (max-width: 720px) {
    .container {
        width: 100%;
        padding: 14px 12px 30px;
    }

    .app-header {
        gap: 10px;
        margin: 4px 0 13px;
    }

    .app-header.search-expanded {
        gap: 8px;
    }

    .app-header.search-expanded .brand-copy {
        flex: 0 1 0;
        opacity: 0;
        transform: translateX(-8px);
        pointer-events: none;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        font-size: 1.2rem;
    }

    h1 {
        font-size: 1.4rem;
        line-height: 1.12;
    }

    .header-search {
        width: 78px;
        height: 38px;
    }

    .header-search.expanded {
        width: min(270px, calc(100vw - 74px));
    }

    .search-icon {
        left: 13px;
        width: 13px;
        height: 13px;
    }

    .search-icon::after {
        right: -5px;
        bottom: -3px;
        width: 7px;
    }

    .search-short-label {
        left: 37px;
        font-size: 0.86rem;
    }

    .keyword-search-input {
        padding-left: 39px;
        padding-right: 36px;
        font-size: 16px;
    }

    .search-clear-btn {
        right: 5px;
        width: 27px;
        height: 27px;
    }

    .batch-control {
        gap: 8px;
        padding: 10px;
        margin-bottom: 10px;
        flex-wrap: nowrap;
    }

    .batch-left,
    .batch-right {
        width: auto;
        flex: 0 0 auto;
    }

    .batch-left {
        min-width: 0;
        flex: 1 1 auto;
    }

    .batch-select-wrap { min-width: 0; }
    .batch-select-wrap select {
        min-width: 0;
        width: 17ch;
        max-width: 100%;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .batch-right {
        gap: 8px;
    }

    .action-btn,
    .delete-btn {
        width: auto;
        min-height: 38px;
        padding: 8px 11px;
        line-height: 1.2;
    }

    .tabs-wrapper {
        margin: 0 -12px 12px;
        padding: 9px 12px 11px;
    }

    .tabs-toolbar {
        gap: 10px;
    }

    .tabs-container {
        flex: 1 1 auto;
    }

    .category-manage-btn {
        font-size: 0.86rem;
    }

    .tab-btn,
    .filter-btn {
        min-height: 34px;
        padding: 7px 12px;
        font-size: 0.86rem;
    }

    .filter-container {
        margin-top: 8px;
        padding-top: 8px;
    }

    .note-card {
        padding: 12px;
        margin-bottom: 12px;
    }

    .note-header {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
        margin-bottom: 11px;
        padding-bottom: 10px;
    }

    .note-title-wrap {
        justify-content: flex-start;
        align-items: center;
    }

    .note-index {
        white-space: nowrap;
    }

    .note-score-badge {
        min-height: 24px;
        padding: 4px 8px;
        font-size: 0.74rem;
    }

    .header-right {
        width: auto;
        justify-content: flex-end;
        gap: 6px;
    }

    .manual-use-btn {
        flex: 0 0 auto;
        min-height: 34px;
        padding: 6px 9px;
        font-size: 0.78rem;
        text-align: center;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        flex: 0 0 34px;
    }

    .section-header {
        gap: 8px;
    }

    .section-label {
        max-width: 100%;
    }

    .copy-btn {
        min-width: 90px;
        min-height: 40px;
        padding: 8px 11px;
        font-size: 0.9rem;
    }

    .content-box {
        padding: 10px 11px;
        font-size: 0.96rem;
        line-height: 1.62;
    }

    .edit-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .category-dialog {
        max-height: 84vh;
        padding: 14px;
    }

    .category-row {
        grid-template-columns: 1fr auto;
        gap: 8px;
    }

    .category-name-input {
        grid-column: 1 / -1;
    }

    .category-keywords-input {
        min-height: 72px;
    }

    .category-actions {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        padding-top: 12px;
    }
}
