:root {
    --orange-600: #d76800;
    --orange-500: #f28c28;
    --gray-900: #1f2933;
    --gray-700: #52606d;
    --gray-500: #7b8794;
    --gray-200: #e4e7eb;
    --gray-100: #f3f4f6;
    --white: #ffffff;
    --pad: 10px;
    --gap: 10px;
    --r: 12px;
    --search-col-height: 76vh;
    --gap-sm: 0.6rem;
    --traits-panel-height: min(72vh, 680px);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--gray-900);
    background: var(--gray-100);
    display: flex;
    flex-direction: column;
}

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

a:hover {
    color: var(--gray-900);
}

.container {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    padding: var(--pad);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    padding: var(--pad);
    border-radius: 0;
    background: var(--orange-600);
}

.topbar-title {
    margin: 0;
    font-size: clamp(20px, 4.2vmin, 36px);
    line-height: 1.05;
    text-align: left;
}

.topbar-title a {
    color: var(--white);
}

.topbar-actions {
    position: static;
    display: flex;
    align-items: center;
    gap: var(--gap-sm);
    flex-wrap: wrap;
}

.topbar-actions a {
    color: var(--white);
}

.topbar-actions a:hover {
    color: var(--gray-100);
}

.topbar .btn-secondary {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
    color: var(--white);
}

.topbar .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.28);
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
    min-height: 0;
    padding: var(--pad);
    padding-bottom: 6px;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.site-footer {
    flex-shrink: 0;
    background: #efe6de;
    color: var(--gray-700);
    text-align: center;
    padding: 6px 0;
    font-size: 13px;
}

.site-footer .container {
    padding: 0 var(--pad);
}

.hero {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
}

.hero-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 16px;
    padding: 2.5rem;
    max-width: 720px;
    box-shadow: 0 12px 30px rgba(11, 44, 86, 0.08);
    text-align: center;
}

.hero-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--gray-200);
    border-radius: var(--r);
    padding: var(--pad);
    margin-bottom: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    min-height: 0;
}

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

.grid.cards {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

@media (min-width: 1100px) {
    .grid.cards {
        grid-template-columns: repeat(3, minmax(260px, 1fr));
    }
}

.btn {
    display: inline-block;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.btn-small {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--orange-600);
    color: var(--white);
}

.btn-primary:hover {
    background: #b85700;
}

.btn-secondary {
    background: var(--gray-100);
    border-color: var(--gray-200);
    color: var(--gray-900);
}

.btn-secondary:hover {
    border-color: var(--orange-500);
}

.btn-danger {
    background: #fce8e6;
    border-color: #f9c4c0;
    color: #b42318;
}

.btn-danger:hover {
    border-color: #f28c28;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--gap);
    align-items: start;
}

.form-grid label {
    margin-bottom: 0;
}

.form-grid > .grid,
.form-grid > .form-actions,
.form-grid > .full,
.form-grid > button,
.form-grid > .btn {
    grid-column: 1 / -1;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    background: var(--white);
    margin-top: 0.35rem;
    font-size: 0.95rem;
}

textarea {
    resize: vertical;
}

.inline {
    display: inline-block;
}

.error {
    color: #b42318;
    font-size: 0.85rem;
}

.muted {
    color: var(--gray-500);
    font-size: 0.9rem;
}

.alert {
    padding: 0.8rem 1rem;
    border-radius: 10px;
    margin-bottom: 0.6rem;
}

.alert-success {
    background: #e7f6ed;
    color: #0f5132;
}

.alert-danger {
    background: #fce8e6;
    color: #842029;
}

.alert-warning {
    background: #fff4e5;
    color: #8a4b00;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.badge {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    font-size: 0.85rem;
}

.badge-primary {
    background: rgba(242, 140, 40, 0.2);
    color: var(--orange-600);
}

.badge-warning {
    background: rgba(242, 140, 40, 0.2);
    color: var(--orange-600);
}

.profile-card {
    display: grid;
    gap: 1rem;
    grid-template-columns: 96px 1fr;
    align-items: start;
    min-height: 180px;
    padding-bottom: calc(var(--pad) + 20px);
}

.profile-media {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.profile-badges {
    display: flex;
    flex-direction: row;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--orange-500);
}

.avatar.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    color: var(--gray-500);
    font-size: 2rem;
}

.trait-group {
    margin-bottom: 1rem;
}

.trait-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.8rem;
    margin-top: 0.4rem;
    align-content: flex-start;
}

.check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.weight {
    max-width: 80px;
}

.search-profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: stretch;
    min-height: 0;
}

.search-left {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: var(--gap-sm);
    min-height: 0;
}

.pane {
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 0.7rem;
    background: var(--white);
    min-height: 220px;
    max-height: 320px;
    overflow: auto;
}

.category-list {
    display: grid;
    gap: 0.4rem;
    margin-top: 0.5rem;
    align-content: start;
}

.category-btn {
    text-align: left;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-weight: 600;
    color: var(--gray-900);
    cursor: pointer;
    height: 38px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-btn.active {
    background: #c9ebe7;
    color: var(--gray-900);
    border-color: #a7d9d3;
}

.trait-item {
    padding: 0.4rem 0;
    border-bottom: 1px dashed var(--gray-200);
}

.trait-item.hidden {
    display: none;
}

.trait-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.trait-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.trait-select {
    width: 100%;
    text-align: left;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    font-weight: 600;
    color: var(--gray-900);
    cursor: pointer;
    height: 38px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trait-select.active {
    border-color: var(--orange-500);
    background: rgba(242, 140, 40, 0.15);
    color: var(--gray-900);
}

.pane-lite {
    margin-bottom: 1rem;
}

.selected-traits-list .selected-traits-item {
    gap: 0.5rem;
}

.weight-input {
    width: 70px;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    border: 1px solid var(--gray-200);
    margin-left: 0.5rem;
}

.selected-traits {
    border: 1px dashed var(--gray-200);
    border-radius: 12px;
    padding: 1rem;
    background: var(--gray-100);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.search-profile-grid .pane {
    max-height: none;
    min-height: 0;
}

.traits-section {
    overflow: hidden;
}

.traits-section .search-profile-grid {
    height: var(--search-col-height);
    min-height: 0;
}

.traits-section .search-left {
    height: 100%;
}

.traits-section .pane {
    height: 100%;
}

.traits-section .selected-traits {
    height: 100%;
}

.selected-traits-list {
    display: grid;
    gap: 0.35rem;
    margin-top: 0.5rem;
    align-content: start;
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.selected-traits-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    font-size: 0.9rem;
    height: 40px;
    overflow: hidden;
    max-width: 100%;
}

.selected-traits-item > span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.selected-traits-item > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-trait {
    border: none;
    background: transparent;
    color: var(--orange-600);
    font-weight: 700;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}

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

.list li {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--gray-200);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.table th,
.table td {
    border-bottom: 1px solid var(--gray-200);
    padding: 0.6rem;
    text-align: left;
}

.chat {
    max-height: 360px;
    overflow-y: auto;
}

.chat-message {
    margin-bottom: 1rem;
}

.chat-message.from-me {
    text-align: right;
}

.chat-body {
    display: inline-block;
    background: var(--gray-100);
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
}

.pagination {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 0.6rem 0;
}

.pagination a {
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    border: 1px solid var(--gray-200);
}

.pagination a.active {
    background: var(--orange-600);
    color: var(--white);
}

.admin-links {
    margin-top: 1rem;
    display: flex;
    gap: 1rem;
}

.stat {
    font-size: 2rem;
    font-weight: 700;
    color: var(--orange-600);
}

.profile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    flex-wrap: wrap;
}

.profile-header h2 {
    margin: 0;
}

.profile-menu {
    display: grid;
    gap: 0.75rem;
}

.menu-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.menu-link {
    border: 1px solid var(--gray-200);
    background: var(--gray-100);
    color: var(--gray-900);
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
}

.menu-link.active {
    background: var(--orange-600);
    border-color: var(--orange-600);
    color: var(--white);
}

.profile-section {
    display: none;
}

.profile-section.active {
    display: block;
}

.search-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    margin-bottom: 0;
}

.search-header h2 {
    margin: 0;
}

.search-toolbar {
    display: flex;
    justify-content: flex-end;
}

.search-filters {
    display: none;
}

.search-filters.open {
    display: block;
}

.search-layout {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    align-items: start;
    flex: 1;
    min-height: 0;
}

.search-profile-form {
    display: contents;
}

.search-profile-left,
.search-profile-selected {
    height: 100%;
    min-height: 0;
}

.search-profile-left {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: var(--gap-sm);
}

.search-profile-selected {
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
}

.search-profile-left .card,
.search-profile-selected .card {
    margin-bottom: 0;
}

.search-profile-left .search-profile-compact {
    height: 100%;
}

.search-profile-compact {
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.search-profile-compact .category-list,
.search-profile-compact .trait-list {
    display: grid;
    grid-auto-rows: 38px;
    align-content: start;
    overflow-y: auto;
    flex: 1;
    max-height: none;
    padding-right: 0.5rem;
    scrollbar-gutter: stable both-edges;
    min-height: 0;
}

.search-profile-compact .selected-traits-list {
    display: grid;
    grid-auto-rows: 40px;
    align-content: start;
    overflow-y: auto;
    flex: 1;
    max-height: none;
    padding-right: 0.5rem;
    scrollbar-gutter: stable both-edges;
    min-height: 0;
}

.profile-meta {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-bottom: 8px;
}

.profile-meta .btn {
    margin-top: 0.5rem;
}

.profile-meta h3,
.profile-meta p {
    margin: 0;
}

.search-profile-selected .search-profile-compact {
    height: 100%;
}

.search-profile-selected .selected-traits-list {
    flex: 1 1 auto;
}

.search-profile-compact .search-profile-grid.compact {
    grid-template-columns: 1fr 1fr;
}

.search-profile-compact .pane {
    max-height: 280px;
}

.search-results-column {
    display: grid;
    gap: 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.search-results-column .card {
    margin-bottom: 0;
}

.search-results-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

@media (max-width: 900px) {
    .search-layout {
        grid-template-columns: 1fr;
    }

    .search-profile-form {
        display: block;
    }

    .search-results-panel {
        height: auto;
    }

    .search-profile-left,
    .search-profile-selected {
        height: auto;
    }

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

    .topbar-actions {
        position: static;
    }
}

@media (max-width: 720px) {
    .header-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .profile-card {
        grid-template-columns: 1fr;
    }

    .search-profile-grid {
        grid-template-columns: 1fr;
        height: auto;
    }

    .pane {
        max-height: none;
        height: auto;
    }
}
