:root {
    color-scheme: light;
    --bg: #f4f6f3;
    --panel: #ffffff;
    --input-bg: #ffffff;
    --line: #d2dbd2;
    --img-bg: #eaefe9;
    --text: #16201b;
    --muted: #4d5a51;
    --accent: #1f6b4f;
    --accent-2: #a8521f;
    --on-accent: #ffffff;
    --on-accent-2: #ffffff;
    --badge-bg: #eaefe9;
    --badge-text: #16201b;
    --good-bg: #dff0e9;
    --good-text: #15603f;
    --bad-bg: #f7e4dc;
    --bad-text: #8a391e;
    --warn-bg: #fff4e0;
    --warn-border: #ead0a8;
    --warn-text: #6e4a12;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f1714;
    --panel: #16211c;
    --input-bg: #1d2b25;
    --line: #2c3b34;
    --img-bg: #243029;
    --text: #e6ede9;
    --muted: #9db0a6;
    --accent: #4fb085;
    --accent-2: #d98a52;
    --on-accent: #0c130f;
    --on-accent-2: #0c130f;
    --badge-bg: #243029;
    --badge-text: #e6ede9;
    --good-bg: #173d2e;
    --good-text: #7fdcb0;
    --bad-bg: #4a221d;
    --bad-text: #f0a89f;
    --warn-bg: #352a14;
    --warn-border: #5a4a2a;
    --warn-text: #e8c98a;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 6px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    font-size: 16px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 12px 0;
}

.filter-bar input[type="text"],
.filter-bar input:not([type]) {
    max-width: 130px;
}

.new-badge {
    background: var(--accent);
    color: var(--on-accent);
}

.tag-badge {
    background: var(--line);
    color: var(--text);
    margin-left: 4px;
}

.bulk-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    font-size: 13px;
    color: var(--muted);
}

.saved-searches {
    margin: 12px 0;
}

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

.saved-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.saved-list form,
.saved-add {
    display: inline-flex;
    gap: 6px;
    margin: 0;
}

.saved-add {
    margin-top: 8px;
    flex-wrap: wrap;
}

.inline-status select {
    padding: 4px 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
}

@media (max-width: 760px) {
    .panel table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

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

a:hover {
    text-decoration: underline;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    padding: 24px 32px;
    background: #17372f;
    color: #fff;
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 24px;
    letter-spacing: 0;
}

.topbar p {
    margin: 0;
    color: #d9e5df;
}

.topbar a {
    color: #fff;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-form {
    margin: 0;
}

.nav-form button {
    border: 1px solid rgba(255, 255, 255, 0.45);
    padding: 7px 10px;
    background: transparent;
}

main {
    max-width: 1320px;
    margin: 0 auto;
    padding: 24px;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.metrics div,
.panel,
.flash,
.score-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metrics div {
    padding: 16px;
}

.label,
td span,
.panel-header p {
    color: var(--muted);
    font-size: 12px;
}

.metrics strong {
    display: block;
    margin-top: 6px;
    font-size: 20px;
}

.panel {
    margin-bottom: 16px;
    padding: 18px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

h2 {
    margin: 0 0 12px;
    font-size: 18px;
}

.panel-header h2 {
    margin-bottom: 2px;
}

.panel-header p {
    margin: 0;
}

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

th {
    text-align: left;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    border-bottom: 1px solid var(--line);
    padding: 10px 8px;
}

td {
    border-bottom: 1px solid var(--line);
    padding: 12px 8px;
    vertical-align: top;
}

tr:last-child td {
    border-bottom: 0;
}

.compact th,
.compact td {
    padding: 8px;
}

.history-table td {
    max-width: 220px;
    overflow-wrap: anywhere;
}

.title {
    display: block;
    font-weight: 700;
}

.source {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
}

.thumb {
    float: left;
    width: 76px;
    height: 54px;
    margin-right: 10px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--img-bg);
}

.score {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    color: var(--on-accent);
    background: var(--accent);
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--badge-text);
    background: var(--badge-bg);
}

.badge.blocked,
.badge.error {
    color: var(--bad-text);
    background: var(--bad-bg);
}

.badge.ok {
    color: var(--good-text);
    background: var(--good-bg);
}

.filters {
    display: flex;
    gap: 6px;
}

.filters a {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
}

.filters .active {
    color: var(--on-accent);
    border-color: var(--accent);
    background: var(--accent);
}

.funda-assist {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg);
}

.funda-assist strong,
.funda-assist span {
    display: block;
}

.funda-assist span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.funda-assist .assist-status {
    color: var(--accent-2);
    font-weight: 700;
}

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

.assist-actions form {
    margin: 0;
}

.assist-actions button {
    min-height: 39px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

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

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stack {
    display: grid;
    gap: 10px;
}

.two,
.three {
    display: grid;
    gap: 10px;
}

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

.three {
    grid-template-columns: repeat(3, 1fr);
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 11px;
    color: var(--text);
    background: var(--input-bg);
    font: inherit;
}

textarea {
    resize: vertical;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.checkbox input {
    width: auto;
}

button {
    border: 0;
    border-radius: 6px;
    padding: 11px 14px;
    color: var(--on-accent);
    background: var(--accent);
    font-weight: 700;
    cursor: pointer;
}

.flash {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-color: var(--warn-border);
    background: var(--warn-bg);
    color: var(--warn-text);
}

.flash p {
    margin: 0;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 28px;
}

.login-panel {
    max-width: 420px;
    margin: 64px auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    background: var(--panel);
}

.login-panel p {
    color: var(--muted);
    line-height: 1.5;
}

.warning {
    border: 1px solid var(--warn-border);
    border-radius: 6px;
    padding: 10px 12px;
    background: var(--warn-bg);
    color: var(--warn-text);
}

.property-head {
    display: grid;
    grid-template-columns: 180px 1fr 160px 160px;
    gap: 18px;
    align-items: stretch;
    margin-bottom: 16px;
}

.property-head img {
    width: 180px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
}

.property-head h2 {
    margin: 8px 0 4px;
    font-size: 24px;
}

.property-head p {
    margin: 0 0 8px;
    color: var(--muted);
}

.property-head a + a {
    margin-left: 10px;
}

.score-card {
    display: grid;
    place-items: center;
    padding: 18px;
}

.score-card span {
    color: var(--muted);
}

.score-card strong {
    font-size: 38px;
    color: var(--accent);
}

.score-card.negotiation strong {
    color: var(--accent-2);
}

.score-card.quality strong {
    font-size: 30px;
    color: var(--muted);
}

.description {
    color: var(--muted);
    line-height: 1.55;
}

.media-section {
    margin: 16px 0 20px;
}

.media-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.media-header h3 {
    margin: 0;
    font-size: 15px;
}

.media-header span {
    color: var(--muted);
    font-size: 12px;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin: 14px 0;
}

.gallery img {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 6px;
    object-fit: cover;
    background: var(--img-bg);
}

.gallery.floorplans img {
    aspect-ratio: 1 / 1.35;
    object-fit: contain;
}

.gallery a {
    cursor: zoom-in;
    display: block;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    background: rgba(12, 16, 14, 0.88);
}

.lightbox[hidden] {
    display: none;
}

.lightbox-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 140px);
}

.lightbox-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    background: #0c100e;
}

.lightbox-thumbs {
    display: flex;
    gap: 6px;
    max-width: 100%;
    overflow-x: auto;
    padding: 4px;
}

.lightbox-thumbs img {
    height: 54px;
    width: 72px;
    object-fit: cover;
    border-radius: 4px;
    opacity: 0.55;
    cursor: pointer;
    transition: opacity 0.15s ease;
    flex: 0 0 auto;
}

.lightbox-thumbs img.active,
.lightbox-thumbs img:hover {
    opacity: 1;
    outline: 2px solid var(--accent);
}

.lightbox-icon {
    position: absolute;
    top: 16px;
    right: 70px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

.lightbox-icon:hover {
    background: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
    .lightbox-nav,
    .lightbox-thumbs img {
        transition: none;
    }
}

.lightbox-nav {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}

.lightbox-nav:hover {
    background: var(--accent);
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.lightbox-close:hover {
    background: var(--accent-2);
}

.lightbox-counter {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 13px;
    letter-spacing: 0.04em;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 12px;
    border-radius: 999px;
}

@media (max-width: 640px) {
    .lightbox-img {
        max-width: calc(100% - 16px);
    }
    .lightbox-nav {
        position: absolute;
        bottom: 16px;
    }
    .lightbox-prev { left: 24px; }
    .lightbox-next { right: 24px; }
}

.satellite-preview {
    display: block;
}

.satellite-preview img {
    width: 100%;
    max-height: 420px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--img-bg);
}

.button-link {
    display: inline-block;
    border-radius: 6px;
    padding: 10px 12px;
    color: var(--on-accent);
    background: var(--accent);
    font-weight: 700;
}

.button-link:hover {
    color: var(--on-accent);
}

.button-link.secondary {
    color: var(--accent);
    border: 1px solid var(--line);
    background: var(--panel);
}

.button-link.secondary:hover {
    color: var(--accent);
}

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

.bookmarklet p {
    max-width: 760px;
    line-height: 1.55;
}

.bookmarklet-button {
    display: inline-block;
    margin: 10px 0;
    border-radius: 6px;
    padding: 11px 14px;
    color: var(--on-accent-2);
    background: var(--accent-2);
    font-weight: 700;
}

.bookmarklet-button:hover {
    color: var(--on-accent-2);
}

@media (max-width: 860px) {
    .metrics,
    .split,
    .property-head,
    .funda-assist,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .funda-assist {
        display: grid;
    }

    .assist-actions {
        justify-content: flex-start;
    }

    main {
        padding: 14px;
    }

    .topbar {
        padding: 18px;
    }

    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

.log-tail {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--muted);
}

.assist-steps {
    margin: 8px 0;
    padding-left: 20px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}
