:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-muted: #999;
    --border: #1a1a1a;
    --border-light: #e8e8e8;
    --accent: #1e2235;
    --accent-hover: #2d3352;
    --tint: #f7f8fa;
    --red: #c0392b;
    --green: #27ae60;
    --orange: #d4820a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ===== HERO ===== */
#hero {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 24px;
}

.hero-box {
    width: 100%;
    max-width: 580px;
    background: var(--surface);
    padding: 48px 40px 40px;
    text-align: center;
}

.hero-box h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.hero-sub {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.hero-labels {
    display: flex;
    gap: 0;
    text-align: left;
    margin-bottom: 4px;
}

.hero-labels label {
    flex: 1;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.hero-inputs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
}

.hero-inputs input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    background: var(--surface);
}

.hero-inputs .input-wrap {
    flex: 1;
    position: relative;
}

.hero-inputs .input-wrap input { width: 100%; border-right: none; }
.hero-inputs input:focus { background: var(--tint); }

/* KO autocomplete dropdown */
.ko-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    max-height: 220px;
    overflow-y: auto;
    z-index: 200;
}

.ko-dropdown .ko-item {
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
}

.ko-dropdown .ko-item:hover,
.ko-dropdown .ko-item.active {
    background: var(--tint);
}

.ko-dropdown .ko-id {
    color: var(--text-muted);
    font-size: 12px;
}

#search-form button,
#search-form-compact button {
    width: 100%;
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: 1px solid var(--accent);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: background 0.15s;
}

#search-form button:hover,
#search-form-compact button:hover { background: var(--accent-hover); }
#search-form button:disabled,
#search-form-compact button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== LOGO ===== */
.logo-icon {
    width: 24px;
    height: 24px;
    background: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-icon svg { width: 14px; height: 14px; }

.logo-icon--sm { width: 20px; height: 20px; }
.logo-icon--sm svg { width: 12px; height: 12px; }

/* ===== COMPACT HEADER ===== */
#results-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    padding: 12px 0;
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

#results-header h1 {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.3px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

#search-form-compact {
    display: flex;
    gap: 0;
    flex: 1;
    justify-content: flex-end;
}

#search-form-compact input {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-right: none;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    width: 140px;
    background: var(--surface);
}

#search-form-compact input:focus { background: var(--tint); }
#search-form-compact button { width: auto; padding: 7px 18px; font-size: 13px; }

/* ===== MAIN ===== */
main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 24px;
}

.hidden { display: none !important; }

/* ===== LOADING ===== */
#loading {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(250,250,250,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

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

/* Building blocks spinner */
.spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 20px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 2px;
}

.spinner-block {
    background: var(--border);
    animation: block-pulse 1.2s ease-in-out infinite;
}

.spinner-block:nth-child(1) { animation-delay: 0s; }
.spinner-block:nth-child(2) { animation-delay: 0.1s; }
.spinner-block:nth-child(3) { animation-delay: 0.2s; }
.spinner-block:nth-child(4) { animation-delay: 0.1s; }
.spinner-block:nth-child(5) { animation-delay: 0.2s; }
.spinner-block:nth-child(6) { animation-delay: 0.3s; }
.spinner-block:nth-child(7) { animation-delay: 0.2s; }
.spinner-block:nth-child(8) { animation-delay: 0.3s; }
.spinner-block:nth-child(9) { animation-delay: 0.4s; }

@keyframes block-pulse {
    0%, 100% { opacity: 0.15; transform: scale(0.85); }
    40% { opacity: 1; transform: scale(1); }
}

.loading-steps {
    text-align: left;
    display: inline-block;
}

.loading-step {
    font-size: 13px;
    padding: 3px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    transition: color 0.2s;
}

.loading-step.active {
    color: var(--text);
}

.loading-step.done {
    color: var(--green);
}

.step-icon {
    width: 16px;
    text-align: center;
    font-size: 11px;
    flex-shrink: 0;
}

.step-spinner {
    width: 10px; height: 10px;
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 1px;
}

.step-spinner-block {
    background: var(--border);
    animation: block-pulse 0.8s ease-in-out infinite;
}

.step-spinner-block:nth-child(1) { animation-delay: 0s; }
.step-spinner-block:nth-child(2) { animation-delay: 0.1s; }
.step-spinner-block:nth-child(3) { animation-delay: 0.2s; }
.step-spinner-block:nth-child(4) { animation-delay: 0.3s; }

/* ===== ERROR ===== */
#error-msg {
    max-width: 580px;
    margin: 40px auto;
    background: var(--surface);
    border: 1px solid var(--red);
    padding: 12px 16px;
    color: var(--red);
    font-weight: 600;
    font-size: 14px;
    text-align: center;
}

/* ===== TITLE BAR ===== */
.title-bar {
    background: var(--accent);
    color: white;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.title-bar-left { display: flex; align-items: center; gap: 8px; }
.title-sep { opacity: 0.4; }

#export-pdf-btn {
    background: transparent;
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: border-color 0.15s;
}

#export-pdf-btn:hover { border-color: rgba(255,255,255,0.7); }

/* ===== TOP ROW ===== */
.top-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

@media (max-width: 800px) { .top-row { grid-template-columns: 1fr; } }

.panel { background: var(--surface); overflow: hidden; }

.panel h2 {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light);
}

#map { height: 450px; }

#envelope-diagram {
    height: 450px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

#envelope-diagram svg { max-width: 100%; max-height: 100%; }

.muted { color: var(--text-muted); font-size: 13px; }

/* ===== CARDS ===== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

@media (max-width: 900px) { .cards-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 500px) { .cards-grid { grid-template-columns: repeat(2, 1fr); } }

.card {
    background: var(--surface);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.card-icon { margin-bottom: 4px; }
.card-icon svg { width: 20px; height: 20px; stroke: var(--text); stroke-width: 1.5; fill: none; }

.card-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
}

.card-value {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.5px;
}

.card-sub {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.val--red { color: var(--red); }
.val--green { color: var(--green); }
.val--orange { color: var(--orange); }

/* ===== ZONE LIST ===== */
.zone-list { list-style: none; padding: 0; }

.zone-list li {
    font-size: 14px;
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #f0f0f0;
}

.zone-list li:last-child { border-bottom: none; }

.zone-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.zone-dot--orange { background: var(--orange); }
.zone-dot--red { background: var(--red); }

/* ===== DETAILS ===== */
.details { display: flex; flex-direction: column; gap: 8px; }

.detail-section { background: var(--surface); }

.detail-header {
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.detail-header:hover { background: var(--tint); }

.detail-header .arrow {
    font-size: 10px;
    transition: transform 0.15s;
    display: inline-block;
    color: var(--text-muted);
}

.detail-section.open .detail-header .arrow { transform: rotate(90deg); }

.detail-body { display: none; padding: 0 16px 16px; }
.detail-section.open .detail-body { display: block; }

/* ===== TABLES ===== */
table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
    text-align: left;
    padding: 8px 10px;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
}

td {
    padding: 8px 10px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* ===== RULES ===== */
.rules-group {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.rules-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.rules-group h4 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--accent);
    margin-bottom: 10px;
    padding-left: 10px;
    border-left: 3px solid var(--accent);
}

.rules-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; }
.rules-list li { font-size: 14px; padding: 5px 12px; border: 1px solid var(--border-light); background: var(--tint); }

.rules-kv { list-style: none; }
.rules-kv li { font-size: 14px; padding: 7px 0; border-bottom: 1px solid #f0f0f0; display: flex; gap: 12px; }
.rules-kv li:last-child { border-bottom: none; }
.rules-kv .kv-label { font-weight: 700; min-width: 170px; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }

/* ===== DIAGRAM LOADING ===== */
.diagram-loading {
    text-align: center;
}

.diagram-loading .spinner {
    width: 28px;
    height: 28px;
    margin: 0 auto 14px;
}

.diagram-loading-step {
    font-size: 12px;
    color: var(--text-muted);
    transition: opacity 0.3s;
}

/* ===== ODMIK MAP LABELS ===== */
.odmik-label {
    background: rgba(255,255,255,0.85);
    border: 1px solid #1a1a1a;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 700;
    font-family: "Inter", sans-serif;
    color: #1a1a1a;
    box-shadow: none;
}

/* ===== LOADING INLINE ===== */
.loading-inline { color: var(--text-muted); font-size: 14px; padding: 8px 0; }
