:root {
    color-scheme: light;
    --bg-body: #f5f7fb;
    --bg-surface: #ffffff;
    --bg-subtle: #eef1f6;
    --text-main: #1a1d23;
    --text-muted: #5c6470;
    --text-soft: #8a92a3;
    --accent: #3465ff;
    --accent-soft: rgba(52, 101, 255, 0.12);
    --border-color: #dde3ef;
    --danger: #d1435b;
    --font-main: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(18, 22, 28, 0.06);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-main);
}

.logout-button {
    border: none;
    background: var(--accent);
    color: var(--bg-surface);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-weight: 500;
}

.logout-button:hover {
    background: #274dcc;
}

.settings-menu {
    position: relative;
}

.settings-button {
    border: none;
    background: transparent;
    color: var(--text-soft);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
}

.settings-button .settings-icon {
    width: 18px;
    height: 18px;
    display: block;
}

.settings-button:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
}

.settings-menu-list {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    background: var(--bg-surface);
    border-radius: 10px;
    box-shadow: 0 14px 30px rgba(18, 22, 28, 0.18);
    padding: 0.4rem 0;
    margin: 0;
    list-style: none;
    min-width: 220px;
    display: none;
    z-index: 40;
}

.settings-menu.is-open .settings-menu-list {
    display: block;
}

.settings-menu-item {
    padding: 0.35rem 0.9rem;
    font-size: 0.9rem;
    color: var(--text-main);
}

.settings-menu-item label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.settings-menu-item input[type="checkbox"] {
    accent-color: var(--accent);
}

.app-main {
    display: flex;
    flex: 1;
    min-height: 0;
}

.app-sidebar {
    width: 320px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.reset-filters {
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    cursor: pointer;
}

.reset-filters:hover {
    background: var(--bg-subtle);
}

.section-title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-soft);
    letter-spacing: 0.08em;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.filter-label {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.filter-field input,
.filter-field select {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 0.65rem;
    background: var(--bg-surface);
    color: var(--text-main);
}

.filter-field input:focus,
.filter-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#search-input {
    flex: 1;
}

#clear-search {
    position: absolute;
    right: 0.4rem;
    border: none;
    background: transparent;
    color: var(--text-soft);
    font-size: 0.9rem;
    line-height: 1;
    padding: 0.25rem;
}

#clear-search[disabled] {
    opacity: 0.3;
    cursor: default;
}

.sidebar-properties {
    flex: 1;
    min-height: 0;
}

.properties-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.property-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    border-radius: 8px;
    background: var(--bg-subtle);
    padding: 0.5rem;
    min-height: 200px;
}

.property-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    border: none;
    background: var(--bg-surface);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    text-align: left;
    box-shadow: 0 1px 3px rgba(18, 22, 28, 0.08);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.property-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(18, 22, 28, 0.12);
}

.property-item.active {
    border: 1px solid var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.property-item-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.property-item-meta {
    font-size: 0.78rem;
    color: var(--text-soft);
}

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.75rem;
}

.pagination-controls button {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
}

.pagination-controls button:disabled {
    opacity: 0.4;
    cursor: default;
}

.pagination-controls span {
    font-size: 0.85rem;
    color: var(--text-soft);
}

.app-content {
    flex: 1;
    min-width: 0;
    padding: 1.5rem 2rem;
    overflow-y: auto;
}

.content-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 4rem 0;
    color: var(--text-soft);
}

.spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.property-detail,
.tile-detail {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.property-header h2,
.tile-detail h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
}

.property-caption,
.tile-property-label {
    color: var(--text-soft);
    font-size: 0.9rem;
    margin: 0.25rem 0 0;
}

.overview-card {
    background: var(--bg-surface);
    border-radius: 12px;
    padding: 0.9rem;
    box-shadow: 0 20px 45px rgba(18, 22, 28, 0.1);
    display: inline-flex;
    flex-direction: column;
    gap: 0.75rem;
    width: clamp(520px, 64vw, 880px);
}

.overview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.overview-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-soft);
}

.overview-link {
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    margin-left: auto;
}

.overview-link:hover {
    text-decoration: underline;
}

/* Overview actions dropdown */
.overview-menu {
    position: relative;
}

.overview-menu-button {
    border: none;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.35rem 0.6rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}

.overview-menu-button:hover {
    background: var(--bg-subtle);
}

.overview-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(18, 22, 28, 0.12);
    padding: 0.35rem 0;
    list-style: none;
    margin: 0;
    display: none;
    z-index: 40;
}

.overview-menu.is-open .overview-menu-list {
    display: block;
}

.overview-menu-item {
    margin: 0;
}

.overview-menu-item > button,
.overview-menu-item > a {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--text-main);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.overview-menu-item > button:hover,
.overview-menu-item > a:hover {
    background: var(--bg-subtle);
}

.overview-body {
    display: flex;
    gap: 1.75rem;
    align-items: stretch;
}

.overview-thumb {
    position: relative;
    border-radius: 12px;
    background: radial-gradient(circle at 20% 20%, rgba(52, 101, 255, 0.12), rgba(18, 22, 28, 0.04));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.1rem;
    min-height: 220px;
    max-height: 280px;
    width: min(100%, 360px);
}

.overview-thumb img {
    display: block;
    max-width: 100%;
    max-height: 260px;
    object-fit: contain;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 12px 30px rgba(18, 22, 28, 0.18);
}

.overview-thumb--interactive,
.overview-thumb--interactive img {
    cursor: zoom-in;
}

.overview-thumb--static,
.overview-thumb--static img {
    cursor: default;
}

.overview-expand {
    position: absolute;
    top: 1rem;
    right: 1rem;
    border: none;
    background: rgba(18, 22, 28, 0.7);
    color: #fff;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.overview-expand:hover {
    transform: scale(1.05);
    background: rgba(18, 22, 28, 0.85);
}

.overview-expand:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.overview-details {
    flex: 1;
    min-width: 260px;
    display: flex;
    align-items: flex-start;
    padding-top: 0.4rem;
}

.overview-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, max-content));
    gap: 0.65rem 2.25rem;
    margin: 0;
}

.overview-detail-grid dt {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-soft);
    margin: 0;
    white-space: nowrap;
}

.overview-detail-grid dd {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    white-space: nowrap;
}

/* Small inline copy button next to property id */
.copy-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-soft);
    margin-left: 0.5rem;
    padding: 0.15rem;
    border-radius: 6px;
    cursor: pointer;
}

.copy-button:hover {
    color: var(--text-main);
    background: var(--bg-subtle);
}

.copy-button svg {
    width: 16px;
    height: 16px;
}

@media (max-width: 960px) {
    .overview-body {
        flex-direction: column;
    }

    .overview-details {
        justify-content: flex-start;
        width: 100%;
    }

    .overview-thumb {
        width: 100%;
        max-height: none;
    }

    .overview-detail-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem 1rem;
    }

    .overview-detail-grid dt,
    .overview-detail-grid dd {
        white-space: normal;
    }
}

body.lightbox-open {
    overflow: hidden;
}

.lightbox-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(14, 19, 30, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1300;
}

.lightbox-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-content {
    position: relative;
    max-width: min(90vw, 1200px);
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 85vh;
}

.lightbox-image-wrapper img {
    width: 100%;
    height: auto;
    max-height: 85vh;
    border-radius: 14px;
    box-shadow: 0 35px 80px rgba(8, 12, 20, 0.55);
    background: var(--bg-surface);
}

.lightbox-close {
    position: absolute;
    top: -16px;
    right: -16px;
    border: none;
    background: var(--bg-surface);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 28px rgba(8, 12, 20, 0.35);
    cursor: pointer;
    font-weight: 700;
}

.lightbox-close:hover {
    background: var(--accent);
    color: var(--bg-surface);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}

.metric-card {
    background: var(--bg-surface);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: 0 6px 16px rgba(18, 22, 28, 0.07);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px solid transparent;
}

.metric-card--hostlers {
    border-color: #ff3333;
}

.metric-card--trailers {
    border-color: #3465ff;
}

.metric-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-soft);
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 600;
}

.tiles-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tile-grid {
    display: grid;
    gap: 1rem;
}

.tile-grid.columns-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

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

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

.tile-grid.columns-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tile-card {
    background: var(--bg-surface);
    border-radius: 12px;
    box-shadow: 0 8px 18px rgba(18, 22, 28, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tile-card.tile-missing {
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.tile-card.tile-deleted {
    border: 1px solid rgba(209, 67, 91, 0.3);
}

.tile-image {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #dce1ec;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.tile-image.tile-image-detail {
    aspect-ratio: auto;
    max-width: 720px;
    width: 100%;
    margin: 1rem 0;
}

.tile-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tile-image.tile-image-detail img {
    height: auto;
    object-fit: contain;
    display: block;
}

.tile-image img.tile-image-expandable {
    cursor: zoom-in;
}

.tile-placeholder {
    font-size: 0.9rem;
    color: var(--text-soft);
}

.tile-meta {
    padding: 0.75rem 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tile-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.tile-box {
    position: absolute;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.tile-box--hostler {
    border: 3px solid #ff3333;
}

.tile-box--trailer {
    border: 3px solid #3465ff;
}

.tile-box-label {
    position: absolute;
    left: 0;
    top: 0;
    transform: translateY(-100%);
    margin-bottom: 2px;
    color: #ffffff;
    font-size: 0.9rem;
    padding: 0.1rem 0.3rem;
    border-radius: 3px 3px 3px 0;
    white-space: nowrap;
}

.tile-box-label--hostler {
    background: #3465ff;
}

.tile-box-label--trailer {
    background: #ff3333;
}

body.hide-hostler-boxes .tile-box--hostler {
    display: none;
}

body.hide-trailer-boxes .tile-box--trailer {
    display: none;
}

.tile-label {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.tile-deleted-label {
    color: var(--danger);
    font-weight: 600;
}

.tile-position,
.tile-counts {
    font-size: 0.85rem;
    color: var(--text-soft);
    margin: 0;
}

.tile-counts {
    display: flex;
    gap: 1.5rem;
}

.tile-card button {
    align-self: flex-start;
    border: none;
    background: var(--accent);
    color: var(--bg-surface);
    border-radius: 6px;
    padding: 0.45rem 0.95rem;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.tile-card button:hover {
    background: #274dcc;
}

.analysis-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.analysis-item {
    background: var(--bg-surface);
    border-radius: 10px;
    box-shadow: 0 6px 16px rgba(18, 22, 28, 0.07);
    padding: 0.5rem 0.75rem;
}

.analysis-item summary {
    font-weight: 600;
    cursor: pointer;
    outline: none;
}

.json-block {
    background: var(--bg-subtle);
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.4;
}

.back-button {
    align-self: flex-start;
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0;
}

.back-button::before {
    content: "←";
}

.info-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.info-card {
    background: var(--bg-surface);
    border-radius: 10px;
    padding: 0.75rem;
    box-shadow: 0 6px 16px rgba(18, 22, 28, 0.07);
    font-size: 0.9rem;
    color: var(--text-soft);
}

.info-card span {
    display: block;
    font-weight: 600;
    color: var(--text-main);
    margin-top: 0.25rem;
}

.data-source {
    font-size: 0.78rem;
    color: var(--text-soft);
}

.error-card {
    background: var(--bg-surface);
    border-radius: 10px;
    box-shadow: 0 6px 16px rgba(18, 22, 28, 0.08);
    padding: 2rem;
    text-align: center;
    color: var(--danger);
}

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(52, 101, 255, 0.18), rgba(34, 39, 47, 0.12));
    padding: 2rem;
}

.login-card {
    background: var(--bg-surface);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(30, 35, 42, 0.18);
    padding: 2.5rem 2.75rem;
    max-width: 360px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    font-size: 0.9rem;
    color: var(--text-soft);
}

.login-field input {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}

.login-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.login-error {
    margin: 0;
    padding: 0.75rem;
    border-radius: 8px;
    background: rgba(209, 67, 91, 0.08);
    color: var(--danger);
    font-size: 0.85rem;
}

.login-submit {
    margin-top: 0.5rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: var(--bg-surface);
    padding: 0.65rem;
    font-weight: 600;
}

.login-submit:hover {
    background: #274dcc;
}

@media (max-width: 1080px) {
    .app-main {
        flex-direction: column;
    }

    .app-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .sidebar-section {
        flex: 1 1 260px;
    }
}

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

    .logout-button {
        align-self: flex-end;
    }

    .app-content {
        padding: 1.25rem;
    }

    .tile-grid.columns-3,
    .tile-grid.columns-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .property-item {
        font-size: 0.85rem;
    }

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

    .metric-grid {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
}
