:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #17212b;
    --muted: #66727e;
    --border: #dfe5ea;
    --primary: #126a55;
    --primary-dark: #0b5140;
    --primary-soft: #e4f3ee;
    --danger: #b42318;
    --danger-soft: #feeceb;
    --warning: #9a5800;
    --shadow: 0 8px 28px rgba(27, 42, 55, .08);
    font-family: Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); font-size: 15px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.topbar {
    min-height: 62px;
    padding: 0 28px;
    background: #12372f;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.brand { color: #fff; font-size: 20px; font-weight: 700; }
.brand:hover { text-decoration: none; }
.topbar-user { display: flex; gap: 18px; align-items: center; }
.topbar-user form { margin: 0; }
.link-button { padding: 0; border: 0; color: #d9eee7; background: transparent; }

.page-container { width: min(1500px, calc(100% - 36px)); margin: 30px auto 60px; }
.page-heading, .detail-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 30px; }
h2 { font-size: 21px; }
.page-heading p, .detail-heading p { margin: 0; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }

.sync-status { display: inline-block; margin-right: 8px; padding: 3px 8px; border-radius: 999px; font-size: 12px; }
.sync-success { background: var(--primary-soft); color: var(--primary-dark); }
.sync-partial { background: #fff3d8; color: var(--warning); }
.sync-failed { background: var(--danger-soft); color: var(--danger); }

.view-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 15px; }
.view-tab { white-space: nowrap; padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: #34424f; }
.view-tab span { display: inline-block; min-width: 24px; margin-right: 5px; padding: 2px 6px; border-radius: 999px; background: #edf1f4; text-align: center; font-size: 12px; }
.view-tab.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.view-tab.active span { color: var(--primary-dark); background: #fff; }
.view-tab:hover { text-decoration: none; border-color: var(--primary); }

.filter-panel, .table-card, .detail-grid, .detail-section, .login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.filter-panel { padding: 16px; margin-bottom: 16px; }
.filters-form { display: grid; grid-template-columns: minmax(230px, 1.7fr) repeat(4, minmax(130px, 1fr)) auto; gap: 12px; align-items: end; }
label { display: grid; gap: 6px; color: #42505c; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cbd4db; border-radius: 8px; background: #fff; color: var(--text); padding: 9px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18, 106, 85, .12); }
textarea { resize: vertical; line-height: 1.55; }
.filter-actions { display: flex; gap: 7px; }
.button { display: inline-flex; min-height: 38px; padding: 8px 15px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; font-weight: 700; }
.button:hover { text-decoration: none; }
.button:disabled { cursor: wait; opacity: .65; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { color: #fff; background: var(--primary-dark); }
.button-secondary { color: #34424f; background: #fff; border-color: var(--border); }
.button-full { width: 100%; }

.table-card { overflow: hidden; }
.table-summary { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.table-scroll { overflow-x: auto; }
.tenders-table { width: 100%; min-width: 1400px; border-collapse: collapse; }
.tenders-table th { padding: 11px 12px; background: #f7f9fa; border-bottom: 1px solid var(--border); color: #53616d; text-align: right; font-size: 12px; }
.tenders-table td { padding: 13px 12px; border-bottom: 1px solid #edf0f2; vertical-align: top; line-height: 1.5; }
.tenders-table tbody tr:last-child td { border-bottom: 0; }
.tenders-table tbody tr:hover { background: #fbfcfc; }
.tenders-table tr.row-saved { background: var(--primary-soft); }
.tender-number { font-weight: 700; font-size: 16px; }
.source-link { display: inline-block; margin-top: 5px; font-size: 12px; }
.tender-links { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; }
.inline-link-button { padding: 0; border: 0; color: var(--primary); background: transparent; }
.inline-link-button:hover { text-decoration: underline; }
.sort-link { display: inline-flex; align-items: center; gap: 5px; color: #53616d; white-space: nowrap; }
.sort-link:hover { color: var(--primary); text-decoration: none; }
.sort-link.active { color: var(--primary-dark); font-weight: 700; }
.sort-link span { font-size: 15px; line-height: 1; }
.purpose-badge {
    display: inline-block;
    margin-bottom: 6px;
    padding: 4px 9px;
    border: 1px solid #b9c7d1;
    border-radius: 999px;
    color: #263b49;
    background: #e9f0f4;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
}
.numeric { white-space: nowrap; }
.housing-units { text-align: center; font-size: 16px; font-weight: 700; }
.last-update { white-space: nowrap; }
.toggle-complexes {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    padding: 4px 8px;
    border: 1px solid #b9d7ce;
    border-radius: 6px;
    color: var(--primary-dark);
    background: var(--primary-soft);
    font-size: 12px;
    font-weight: 700;
}
.toggle-complexes:hover { border-color: var(--primary); }
.complexes-pending { margin-top: 7px; color: var(--muted); font-size: 11px; }
.complexes-row { display: none; }
.complexes-row.open { display: table-row; }
.complexes-cell { padding: 0 !important; background: #f1f6f4; }
.complexes-scroll { overflow-x: auto; padding: 14px 18px 18px; }
.complexes-table { width: 100%; min-width: 1000px; border-collapse: separate; border-spacing: 0; border: 1px solid #cfddd8; border-radius: 9px; overflow: hidden; background: #fff; }
.complexes-table th { padding: 9px 10px; background: #e8f1ee; color: #40524c; text-align: right; font-size: 11px; }
.complexes-table td { padding: 10px; border-top: 1px solid #e5ece9; border-bottom: 0 !important; vertical-align: top; white-space: nowrap; }
.complexes-table tbody tr:hover { background: #f9fbfa; }
.deadline { white-space: nowrap; border-right: 3px solid transparent; }
.deadline-critical { background: #fff0ef; border-right-color: #d92d20; }
.deadline-warning { background: #fff7e6; border-right-color: #f79009; }
.deadline-soon { background: #fffbea; border-right-color: #eaaa08; }
.deadline-expired { color: var(--muted); }
.rmi-status { display: inline-block; max-width: 180px; }
.badge { display: inline-block; margin-top: 5px; padding: 2px 7px; border-radius: 999px; font-size: 11px; }
.badge-gray { color: #59636e; background: #edf0f2; }
.review-status { min-width: 125px; padding: 7px 8px; border-right-width: 4px; font-weight: 700; }
.status-new { border-right-color: #7a8691; }
.status-relevant { border-right-color: #12b76a; background: #f0fbf5; }
.status-not_relevant { border-right-color: #d92d20; background: #fff7f6; }
.save-state { display: block; min-height: 18px; margin-top: 4px; color: var(--primary); font-size: 12px; }
.save-error { color: var(--danger); }
.text-action, .change-button { border: 0; background: transparent; color: var(--primary); padding: 0; text-align: right; }
.change-button { padding: 4px 8px; border-radius: 6px; color: #8a4b00; background: #fff1d4; font-weight: 700; }
.note-preview { max-width: 220px; margin-top: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-state { padding: 45px !important; text-align: center; color: var(--muted); }

.modal { display: none; position: fixed; inset: 0; z-index: 50; padding: 20px; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(18, 31, 38, .55); }
.modal-dialog { position: relative; z-index: 1; width: min(560px, 100%); max-height: 85vh; overflow-y: auto; padding: 25px; border-radius: 13px; background: #fff; box-shadow: 0 24px 70px rgba(0, 0, 0, .24); }
.modal-wide { width: min(760px, 100%); }
.modal-map { width: min(1200px, 100%); max-height: 94vh; overflow: hidden; padding: 20px; }
.modal-close { position: absolute; z-index: 5; top: 12px; left: 15px; border: 0; background: transparent; color: var(--muted); font-size: 28px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-subtitle { color: var(--muted); }
.map-heading { display: flex; align-items: center; justify-content: space-between; gap: 25px; padding-left: 34px; }
.map-heading h2 { margin-bottom: 4px; }
.map-heading p { margin-bottom: 0; }
.map-legend { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); white-space: nowrap; font-size: 12px; }
.map-legend i { width: 17px; height: 13px; border: 2px solid rgb(19, 80, 104); background: rgba(19, 80, 104, .3); }
.map-status { min-height: min(68vh, 650px); margin-top: 14px; display: grid; place-items: center; color: var(--muted); background: #f5f7f8; border-radius: 9px; text-align: center; }
.map-status.alert { padding: 30px; }
.map-canvas-wrap { position: relative; height: min(68vh, 650px); margin-top: 14px; overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: #edf1f3; }
.map-canvas-wrap[hidden] { display: none; }
.map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; direction: ltr; }

.back-link { display: inline-block; margin-bottom: 18px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; overflow: hidden; }
.detail-item { min-height: 84px; padding: 17px; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); }
.detail-item span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.detail-item strong { line-height: 1.45; }
.detail-section { padding: 22px; margin-bottom: 18px; }
.review-panel { display: grid; grid-template-columns: 190px 1fr auto; gap: 14px; align-items: end; }
.review-notes-label { grid-row: span 2; }
.history-list, .changes-content { display: grid; gap: 10px; }
.history-item { padding: 13px 15px; border: 1px solid var(--border); border-radius: 8px; background: #fbfcfc; }
.history-header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 8px; }
.history-header time { color: var(--muted); font-size: 12px; }
.history-values { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.history-values span { min-width: 0; overflow-wrap: anywhere; }
.history-values b { color: var(--primary); }

.login-page { background: linear-gradient(145deg, #e6f2ee, #f5f7f8 48%, #eef3f1); }
.login-page .page-container { min-height: calc(100vh - 60px); display: grid; place-items: center; margin-top: 0; margin-bottom: 0; }
.login-card { width: min(420px, 100%); padding: 34px; text-align: center; }
.login-card form { display: grid; gap: 16px; margin-top: 25px; text-align: right; }
.login-mark { width: 68px; height: 68px; margin: 0 auto 17px; border-radius: 18px; display: grid; place-items: center; color: #fff; background: var(--primary); font-size: 20px; font-weight: 700; }
.login-card h1 { margin-bottom: 6px; }
.login-card > p { color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 8px; }
.alert-error { color: var(--danger); background: var(--danger-soft); }

.toast { position: fixed; z-index: 100; bottom: 25px; left: 25px; max-width: 360px; padding: 11px 16px; border-radius: 8px; color: #fff; background: #25313a; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--primary); }
.toast-error { background: var(--danger); }

@media (max-width: 1100px) {
    .filters-form { grid-template-columns: repeat(3, 1fr); }
    .filter-search { grid-column: span 2; }
    .detail-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 720px) {
    .topbar { padding: 0 16px; }
    .page-container { width: min(100% - 20px, 1500px); margin-top: 18px; }
    .page-heading, .detail-heading { align-items: flex-start; flex-direction: column; }
    h1 { font-size: 25px; }
    .filters-form { grid-template-columns: 1fr; }
    .filter-search { grid-column: auto; }
    .filter-actions .button { flex: 1; }
    .detail-grid { grid-template-columns: repeat(2, 1fr); }
    .review-panel { grid-template-columns: 1fr; }
    .review-notes-label { grid-row: auto; }
    .modal { padding: 10px; }
    .modal-dialog { padding: 22px 17px; }
    .modal-map { padding: 17px 10px 10px; }
    .map-heading { align-items: flex-start; flex-direction: column; gap: 7px; padding: 0 35px 0 7px; }
    .map-canvas-wrap, .map-status { height: 72vh; min-height: 72vh; }
    .detail-actions { justify-content: flex-start; }
    .history-values { grid-template-columns: 1fr; }
    .history-values b { transform: rotate(-90deg); text-align: center; }
}

@media (max-width: 440px) {
    .topbar-user > span { display: none; }
    .detail-grid { grid-template-columns: 1fr; }
    .login-card { padding: 25px 20px; }
}
