*,*::before,*::after{box-sizing:border-box}
body{font-family:system-ui,sans-serif;margin:0;color:#222;background:#f6f7f9;line-height:1.5;-webkit-text-size-adjust:100%}
img{max-width:100%;height:auto}

/* Layout */
header{background:#1f3a5f;padding:.75rem 1rem;display:flex;flex-wrap:wrap;gap:.75rem;align-items:center;justify-content:space-between}
header a{color:#fff;text-decoration:none;font-weight:600}
header .btn{background:#fff;color:#1f3a5f}
main{max-width:960px;margin:1.25rem auto;padding:0 1rem}
h1{font-size:clamp(1.4rem,5vw,1.9rem);margin:.2rem 0 .6rem;overflow-wrap:anywhere}
h2{font-size:clamp(1.15rem,4vw,1.4rem)}

/* Forms (16px font stops iOS zooming into fields) */
label{display:block;margin:.8rem 0;font-weight:600}
input,textarea,button{font:inherit;font-size:1rem}
input,textarea{width:100%;padding:.6rem;margin-top:.25rem;border:1px solid #b9bec6;border-radius:4px;background:#fff}
button,.btn{display:inline-flex;align-items:center;justify-content:center;min-height:44px;padding:.5rem 1rem;background:#1f3a5f;color:#fff;border:0;border-radius:4px;cursor:pointer;text-decoration:none}
button.danger{background:#a62b2b}
.search{display:flex;gap:.5rem;margin-bottom:1rem}
.search input{margin:0;flex:1;min-width:0}
.actions{display:flex;flex-wrap:wrap;gap:.6rem;align-items:center;margin:1rem 0}
.actions form{margin:0}
.error{background:#fde8e8;color:#8a1f1f;padding:.6rem .8rem;border-radius:4px}

/* Tables */
table{width:100%;border-collapse:collapse;background:#fff}
th,td{border:1px solid #d6d9de;padding:.5rem .7rem;text-align:left;vertical-align:middle}
th{background:#e9edf2}
td a{overflow-wrap:anywhere}

/* Unit details */
dl{margin:0}
dt{font-weight:700;margin-top:.6rem}
dd{margin:0;overflow-wrap:anywhere}
.unit-img{max-width:100%;max-height:360px;border-radius:4px;border:1px solid #d6d9de;margin:.5rem 0}
.thumb{width:56px;height:56px;object-fit:cover;border-radius:4px;display:block}
.fault-view,.fault-block{background:#fff;border:1px solid #d6d9de;border-radius:4px;padding:.8rem;margin-bottom:.8rem}
.fault-view ol{margin:.4rem 0 0;padding-left:1.3rem}
.fault-view li{overflow-wrap:anywhere}
.fault-block h3{margin:.2rem 0;font-size:1rem}
.remedy-row{display:grid;grid-template-columns:1fr auto;gap:.5rem;margin:.4rem 0;align-items:start}

/* Wider screens: label/value side by side */
@media (min-width:640px){
  dl{display:grid;grid-template-columns:10rem 1fr;gap:.3rem 1rem}
  dt{margin-top:0}
}

/* Phones: stack the unit list into cards, full-width buttons */
@media (max-width:640px){
  main{margin:1rem auto}
  table.units,table.units tbody{display:block}
  table.units tr:first-child{display:none}
  table.units tr{display:block;border:1px solid #d6d9de;border-radius:4px;margin-bottom:.7rem;padding:.4rem .2rem}
  table.units td{display:flex;gap:.6rem;border:0;padding:.25rem .7rem}
  table.units td[data-label]::before{content:attr(data-label);font-weight:600;min-width:6.5rem;color:#555}
  table.units td:empty{display:none}
  .remedy-row{grid-template-columns:1fr}
  .fault-block button,.actions .btn,.actions button{width:100%}
  .actions form{width:100%}
}

/* Login + header user area */
header .right{display:flex;flex-wrap:wrap;gap:.6rem;align-items:center;color:#fff}
header .right form{margin:0}
.login{max-width:360px;margin:2rem auto;background:#fff;border:1px solid #d6d9de;border-radius:4px;padding:1rem 1.2rem}
.login .btn{width:100%}

/* Edit history */
.hist-entry{background:#fff;border:1px solid #d6d9de;border-radius:4px;padding:.7rem .9rem;margin-bottom:.7rem}
.hist-head{display:flex;flex-wrap:wrap;gap:.2rem .8rem;color:#555;font-size:.92rem}
.hist-head .act{font-weight:700;text-transform:capitalize}
.changes{margin:.5rem 0 0;padding-left:1.2rem}
.changes li{overflow-wrap:anywhere;margin:.25rem 0}
.changes ol{margin:.2rem 0 0}
.pre{white-space:pre-wrap}
del{background:#fde8e8;color:#7a1c1c}
ins{background:#e3f4e3;color:#1d5a1d;text-decoration:none}

/* Gallery */
.gallery{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:.7rem}
.gallery figure{margin:0;background:#fff;border:1px solid #d6d9de;border-radius:4px;overflow:hidden}
.gallery img{width:100%;aspect-ratio:4/3;object-fit:cover;display:block}
.gallery figcaption{padding:.35rem .5rem;font-size:.9rem;overflow-wrap:anywhere}
.gallery-edit{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:.7rem;margin-bottom:.8rem}
.g-item{background:#fff;border:1px solid #d6d9de;border-radius:4px;padding:.5rem}
.g-thumb{width:100%;aspect-ratio:4/3;object-fit:cover;border-radius:4px;display:block}
.g-item input[type=text]{margin:.4rem 0}
.chk{font-weight:400;margin:.3rem 0 0}
.chk input{width:auto;margin-right:.3rem}
dialog#lb{border:0;border-radius:6px;padding:.5rem;max-width:min(96vw,1100px);background:#111;color:#fff}
dialog#lb::backdrop{background:rgba(0,0,0,.75)}
#lb-img{max-width:100%;max-height:80vh;display:block;margin:0 auto}
#lb-cap{margin:.4rem 0 0;text-align:center}
.lb-close{position:absolute;top:.3rem;right:.3rem;min-width:40px;min-height:40px;padding:0;background:rgba(0,0,0,.6);font-size:1.4rem}

/* Users */
.notice{background:#e3f4e3;color:#1d5a1d;padding:.6rem .8rem;border-radius:4px}
.user-card{background:#fff;border:1px solid #d6d9de;border-radius:4px;padding:.7rem .9rem;margin-bottom:.7rem}
.user-card form{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center;margin-top:.5rem}
.user-card input{max-width:260px;margin:0}
@media (max-width:640px){.user-card input,.user-card button{max-width:none;width:100%}}

/* Fault images */
.fault-gallery,.fault-imgs{display:flex;flex-wrap:wrap;gap:.5rem;margin:.5rem 0}
.fault-gallery img,.fault-imgs img{width:110px;height:82px;object-fit:cover;border-radius:4px;border:1px solid #d6d9de;display:block}
.fault-imgs .fi{width:110px}

/* Roles */
select{font:inherit;font-size:1rem;padding:.55rem;min-height:44px;border:1px solid #b9bec6;border-radius:4px;background:#fff}
.user-card select{max-width:260px}
.role{display:inline-block;padding:.05rem .5rem;border-radius:999px;font-size:.8rem;font-weight:700;text-transform:uppercase;background:#e9edf2;color:#334}
.role-admin{background:#fde8e8;color:#7a1c1c}
.role-editor{background:#e3f4e3;color:#1d5a1d}
@media (max-width:640px){.user-card select{max-width:none;width:100%}}

/* Home page: centred search bar; footer pinned to the bottom of short pages */
body{min-height:100vh;display:flex;flex-direction:column}
main{flex:1;width:100%}
.search.hero{max-width:640px;margin:15vh auto 0}
footer{padding:1rem;text-align:center;color:#667;font-size:.85rem}

/* Private notes */
.muted{color:#667;margin:.2rem 0 .8rem}
.note-card{background:#fff;border:1px solid #d6d9de;border-left:4px solid #1f3a5f;border-radius:4px;padding:.7rem .9rem;margin-bottom:.7rem}
.note-meta{color:#667;font-size:.85rem;margin:.15rem 0 .5rem}
.note-card .actions{margin:.6rem 0 0}

footer p{margin:.2rem 0}
footer .disclaimer{font-weight:600;color:#444}
