:root {
  --ink: #1d2433; --muted: #5d6677; --line: #d9dde5; --bg: #eef1f5;
  --navy: #1f3047; --navy-2: #2c4363; --accent: #2f6fd1;
  --ok: #1f8a4c; --ok-bg: #e3f5ea; --warn: #9a6a00; --warn-bg: #fff3cd;
  --danger: #c0262d; --danger-bg: #fde3e3;
  --fault-bg: #fff8d9; --fault-line: #ecd27a;
  --permit-bg: #fdeaea; --permit-line: #eeb0b0;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif; color: var(--ink); background: var(--bg); font-size: 15px; }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; } h2 { font-size: 17px; margin: 18px 0 10px; } h3 { font-size: 15px; margin: 12px 0 8px; }

/* top bar */
#topbar { display: flex; align-items: center; gap: 18px; background: var(--navy); color: #fff; padding: 0 18px; min-height: 54px; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; } .brand small { font-weight: 400; opacity: .7; font-size: 12px; }
#nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
#nav a { color: #dfe6f1; padding: 16px 11px; display: block; border-bottom: 3px solid transparent; }
#nav a:hover { background: var(--navy-2); text-decoration: none; }
#nav a.active { color: #fff; border-bottom-color: #7fb0ff; background: var(--navy-2); }
#nav a.nav-faults.active { border-bottom-color: #f2cf4a; } #nav a.nav-permits.active { border-bottom-color: #ff7b7b; }
.userbox { font-size: 13px; white-space: nowrap; } .userbox .link { color: #c8d6ee; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
/* module backgrounds required by the spec: logs = white, faults = yellow, permits = red */
.page { border-radius: var(--radius); padding: 20px 22px; min-height: 70vh; border: 1px solid var(--line); background: #fff; }
.page.module-logs { background: #ffffff; }
.page.module-faults { background: var(--fault-bg); border-color: var(--fault-line); }
.page.module-permits { background: var(--permit-bg); border-color: var(--permit-line); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }

/* buttons & forms */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 6px; cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: #9aa6b8; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #255db3; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warn { background: #e0a800; border-color: #e0a800; color: #1d2433; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
button.link { background: none; border: none; padding: 0 4px; color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: #333c4d; }
.req::after { content: " *"; color: var(--danger); }
input, select, textarea { font: inherit; width: 100%; padding: 7px 9px; border: 1px solid #c3c9d4; border-radius: 6px; background: #fff; color: var(--ink); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ff; border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.grid .full { grid-column: 1 / -1; }
.field small { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; padding: 10px 12px; background: rgba(255,255,255,.6); border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0 14px; }
.filters > div { min-width: 150px; }
.checklist { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; }
.checklist .check { margin: 3px 0; font-size: 14px; }

/* tables */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
th, td { padding: 8px 10px; border-bottom: 1px solid #e7eaf0; text-align: right; vertical-align: top; font-size: 14px; }
th { background: #f3f5f9; font-weight: 600; color: #3b4558; white-space: nowrap; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f5f8ff; }
tr.row-grounded td { background: #ffe1e1; } tr.row-grounded:hover td { background: #ffd2d2; }
tr.row-resolved td { color: #7a8394; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.empty { padding: 24px; text-align: center; color: var(--muted); background: #fff; border-radius: var(--radius); }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.b-ready, .b-active, .b-resolved, .b-closed { background: var(--ok-bg); color: var(--ok); border-color: #b5e2c6; }
.b-limited, .b-medium, .b-in_progress, .b-open-log { background: var(--warn-bg); color: var(--warn); border-color: #f1d98a; }
.b-grounded, .b-expired, .b-emergency { background: var(--danger); color: #fff; }
.b-open { background: #ffe9c7; color: #8a4b00; border-color: #f3c98a; }
.b-minor { background: #e8eef9; color: #34527f; }
.b-used, .b-cancelled, .b-inactive { background: #e6e8ec; color: #555e6e; }
.b-info { background: #e8f0ff; color: #2e5aa8; }

/* cards & panels */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .num { font-size: 28px; font-weight: 700; }
.card .sub { color: var(--muted); font-size: 13px; }
.card.red { border-color: #f0a5a5; background: #fff2f2; } .card.red .num { color: var(--danger); }
.card.yellow { border-color: var(--fault-line); background: var(--fault-bg); }
.card.pink { border-color: var(--permit-line); background: var(--permit-bg); }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.module-faults .panel, .module-permits .panel { background: rgba(255,255,255,.85); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; } dl.kv dd { margin: 0; white-space: pre-wrap; }
.alert { padding: 10px 14px; border-radius: 6px; margin: 8px 0; border: 1px solid; }
.alert ul { margin: 4px 0 0; padding-inline-start: 20px; }
.alert-danger { background: var(--danger-bg); border-color: #f0a5a5; color: #8c1c21; }
.alert-warn { background: var(--warn-bg); border-color: #f1d98a; color: #6e4c00; }
.alert-ok { background: var(--ok-bg); border-color: #b5e2c6; color: #17663a; }
.alert-info { background: #eaf2ff; border-color: #b9d0f5; color: #24467e; }
.grounded-banner { background: var(--danger); color: #fff; padding: 10px 14px; border-radius: 6px; font-weight: 700; margin-bottom: 12px; }
.progress { height: 10px; background: #e6e8ec; border-radius: 5px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }
.progress.warn > div { background: #e0a800; } .progress.over > div { background: var(--danger); }
.permit-card { border: 1px solid var(--permit-line); border-right: 5px solid var(--danger); background: #fff; border-radius: 6px; padding: 10px 12px; margin: 8px 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-right: 3px solid var(--line); padding: 4px 12px 10px; position: relative; }
.timeline li::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); position: absolute; right: -6px; top: 9px; }
.timeline .when { color: var(--muted); font-size: 12px; }
.attachments { display: flex; gap: 10px; flex-wrap: wrap; }
.att { width: 150px; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 6px; font-size: 12px; text-align: center; }
.att img { width: 100%; height: 100px; object-fit: cover; border-radius: 4px; cursor: zoom-in; background: #f3f3f3; }
.att .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 4px 0; }
.sig-pad { border: 2px dashed #9aa6b8; border-radius: 6px; background: #fff; touch-action: none; width: 100%; max-width: 520px; height: 160px; display: block; }
.sig-img { max-width: 320px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: embed; }

/* login */
.login-wrap { max-width: 380px; margin: 9vh auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 28px; }
.login-wrap h1 { text-align: center; } .login-wrap .sub { text-align: center; color: var(--muted); margin-top: -8px; margin-bottom: 20px; }
.login-wrap .field { margin-bottom: 12px; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15, 22, 35, .55); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 5vh 12px; overflow-y: auto; }
.modal-box { background: #fff; border-radius: 10px; padding: 22px; width: 100%; max-width: 720px; position: relative; }
.modal-box.wide { max-width: 1000px; }
.modal-x { position: absolute; left: 12px; top: 12px; border: none; font-size: 18px; background: none; }
.modal img.full { max-width: 100%; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.toast.error { background: var(--danger); }

/* configurable tables: toolbar + phone card list (cards hidden on desktop) */
.tbl { margin-bottom: 4px; }
.tbl-bar { display: flex; justify-content: flex-end; margin: 0 0 4px; }
.cols-btn { font-size: 12px; padding: 2px 8px; color: var(--muted); background: rgba(255,255,255,.7); }
tr.totals th { background: #eef1f7; }
.cards-list { display: none; }
.row-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.row-card.clickable { cursor: pointer; }
.row-card.row-grounded { background: #ffe1e1; border-color: #f0a5a5; border-right: 5px solid var(--danger); }
.row-card.row-resolved { color: #7a8394; }
.row-card.totals { background: #eef1f7; }
.rc-head { font-weight: 700; margin-bottom: 6px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.rc-head .k { font-weight: 400; color: var(--muted); font-size: 12px; }
.kv-line { display: flex; gap: 10px; padding: 3px 0; border-top: 1px dashed #eceff4; font-size: 14px; }
.kv-line .k { color: var(--muted); min-width: 92px; flex-shrink: 0; font-size: 13px; }
.kv-line .v { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rc-foot { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.cols-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 12px; }
.cols-admin .col-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid #eceff4; }
.cols-admin .col-row .full { grid-column: 1 / -1; }
.menu-btn { display: none; }

/* ---------- phone ---------- */
@media (max-width: 700px) {
  body { font-size: 16px; }
  #topbar { padding: 0 10px; gap: 8px; min-height: 52px; }
  .brand { flex: 1; font-size: 16px; } .brand small { display: none; }
  .menu-btn { display: block; background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; font-size: 22px; padding: 4px 12px; min-height: 40px; }
  #nav, .userbox { display: none; flex-basis: 100%; }
  #topbar.open #nav { display: flex; flex-direction: column; gap: 0; padding-bottom: 6px; }
  #topbar.open #nav a { padding: 13px 8px; border-bottom: 1px solid var(--navy-2); border-right: 4px solid transparent; }
  #topbar.open #nav a.active { border-bottom-color: var(--navy-2); border-right-color: #7fb0ff; }
  #topbar.open #nav a.nav-faults.active { border-right-color: #f2cf4a; } #topbar.open #nav a.nav-permits.active { border-right-color: #ff7b7b; }
  #topbar.open .userbox { display: block; padding: 8px 4px 12px; white-space: normal; }
  #topbar.open .userbox .link { font-size: 15px; padding: 8px 6px; }
  main { padding: 8px; }
  .page { padding: 12px 10px; }
  h1 { font-size: 19px; }
  .page-head { align-items: stretch; }
  .page-head > .actions, .page-head > .btn, .page-head > button { width: 100%; }
  .actions .btn, .actions button { flex: 1 1 100%; text-align: center; }
  input, select, textarea, button, .btn { min-height: 44px; font-size: 16px; }
  .btn-sm, .cols-btn { min-height: 36px; font-size: 14px; }
  button.link { min-height: 0; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; }
  .grid { grid-template-columns: 1fr; }
  .filters > div { min-width: 100%; }
  .table-wrap { display: none; }
  .cards-list { display: block; }
  .cards { grid-template-columns: 1fr 1fr; }
  .card .num { font-size: 24px; }
  dl.kv { grid-template-columns: 1fr; } dl.kv dd { margin-bottom: 6px; }
  .modal { padding: 0; }
  .modal-box { min-height: 100vh; border-radius: 0; padding: 18px 14px 28px; }
  .modal-x { font-size: 24px; padding: 6px 10px; }
  .sig-pad { max-width: none; }
  .sig-img { max-width: 100%; }
  .att { width: calc(50% - 5px); }
  .cols-admin .col-row { grid-template-columns: 1fr; }
}

@media print {
  .tbl-bar, .cards-list { display: none !important; } .table-wrap { display: block !important; }
  #topbar, .no-print, .filters, .actions { display: none !important; }
  main { padding: 0; max-width: none; } .page { border: none; padding: 0; }
}
