/* Leda - klassisk, lugn design: mörkblå rubrikrad, ljusgrå bakgrund, vita paneler med tunn ram. */
:root {
  --navy: #1d3557; --navy2: #274872; --gold: #f1c40f;
  --bg: #eef1f5; --panel: #ffffff; --line: #cfd6e0; --line2: #e4e8ee;
  --text: #1f2933; --muted: #5f6b7a;
  --green: #1e8449; --greenbg: #e3f4e9; --red: #b03a2e; --redbg: #fbe7e5; --amber: #9a6700; --amberbg: #fff4d6; --blue: #1f5fa8; --bluebg: #e6effa;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", Tahoma, Arial, sans-serif; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; color: var(--navy); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.warn { color: var(--red); background: var(--redbg); border: 1px solid #efc2bd; padding: 6px 10px; border-radius: 3px; }
.info { color: var(--green); background: var(--greenbg); border: 1px solid #bfe3cb; padding: 6px 10px; border-radius: 3px; }

/* rubrikrad */
.top { background: linear-gradient(#24416a, var(--navy)); color: #fff; display: flex; align-items: center; justify-content: space-between;
       padding: 8px 18px; border-bottom: 3px solid var(--gold); gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { display: block; border-radius: 6px; }
.bname { display: block; font-weight: 700; letter-spacing: .18em; font-size: 17px; }
.bsub { display: block; font-size: 12px; color: #c9d4e5; }
.topright { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.who small { color: #c9d4e5; margin-left: 4px; }
.toplink { color: #fff; }
.demo { background: var(--gold); color: #1d1d1d; font-weight: 700; font-size: 11px; padding: 1px 7px; border-radius: 3px; letter-spacing: .08em; }
.langsw { font-size: 13px; }
.top .langsw a { color: #fff; }
.langsw b { text-decoration: underline; }

/* paneler + layout */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(20, 30, 50, .05); }
.layout { display: grid; grid-template-columns: 320px 1fr; gap: 14px; padding: 14px; max-width: 1400px; margin: 0 auto; align-items: start; }
.mainarea { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
#sitecard { display: flex; flex-direction: column; gap: 14px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
  /* Mobil: vald plats först, sökningen under. */
  .layout.hassite .mainarea { order: -1; }
  .results { max-height: 320px; }
  .cols { grid-template-columns: 1fr; }
}

/* sök */
.searchpanel input { width: 100%; padding: 8px 10px; border: 1px solid #aab4c3; border-radius: 3px; font: inherit; }
.searchpanel input:focus, .reason input:focus, .dlgbox input:focus, select:focus { outline: 2px solid #9cc0ea; border-color: var(--blue); }
.results { list-style: none; margin: 10px 0 0; padding: 0; max-height: calc(100vh - 190px); overflow-y: auto; }
.results li { border-bottom: 1px solid var(--line2); }
.results button { all: unset; display: block; width: 100%; padding: 8px 6px; cursor: pointer; box-sizing: border-box; }
.results button:hover, .results button:focus-visible { background: #f0f5fc; }
.results li.sel button { background: var(--bluebg); box-shadow: inset 3px 0 0 var(--blue); }
.results b { display: block; }
.results small { color: var(--muted); display: block; }
.results .none { padding: 10px 6px; color: var(--muted); }

/* platskort */
.sitehead { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.gw { font-size: 13px; padding: 3px 10px; border-radius: 12px; border: 1px solid; white-space: nowrap; }
.gw.on { color: var(--green); background: var(--greenbg); border-color: #bfe3cb; }
.gw.off { color: var(--red); background: var(--redbg); border-color: #efc2bd; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px 16px; margin: 14px 0; padding: 10px 12px; background: #f7f9fb; border: 1px solid var(--line2); border-radius: 3px; }
.meta dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.meta dd { margin: 0; font-weight: 600; }
.reason { display: block; margin-bottom: 12px; }
.reason span { display: block; font-weight: 600; margin-bottom: 4px; }
.reason input { width: 100%; padding: 8px 10px; border: 1px solid #aab4c3; border-radius: 3px; font: inherit; }
.reason input.need { border-color: var(--red); background: #fff8f7; }

table { border-collapse: collapse; width: 100%; }
.doors th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 2px solid var(--line); padding: 6px 8px; background: #f7f9fb; }
.doors td { padding: 8px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.doors .dname { font-weight: 600; }
.doors .acts { text-align: right; }
.doors td.acts { white-space: nowrap; }
.doors td.acts > * { margin-left: 4px; }
/* Fasta bredder: knapparna står i rak linje oavsett om dörren är öppen eller stängd ("Lås" / "Lås nu"). */
.doors td.acts select { width: 86px; }
.doors td.acts .btn { min-width: 74px; }
/* Läge: mjukt grönt = öppen, mjukt rött = stängd (låst). Tonar in när läget ändras. */
.state { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12.5px; font-weight: 600; border: 1px solid; }
.doors .state::before { content: "● "; }
.state.closed { color: #b5524a; background: #fbeeec; border-color: #f0d0cb; }
.state.open { color: #2f7d4f; background: #e8f5ec; border-color: #c5e4cf; }
.doors .state { min-width: 150px; text-align: center; }
.doors tr.isopen td:first-child { box-shadow: inset 4px 0 0 #7cc495; }
.doors tr.isclosed td:first-child { box-shadow: inset 4px 0 0 #e59a92; }
.doors .state.chg { animation: statefade .9s ease-out; }
.doors tr.chg td:first-child { transition: box-shadow .9s ease-out; }
@keyframes statefade { from { background: #fff; border-color: var(--line); color: var(--muted); } }
@media (max-width: 640px) {
  .doors thead { display: none; }
  .doors tr { display: block; border-bottom: 1px solid var(--line2); padding: 6px 0; }
  .doors td { display: block; border: 0; padding: 3px 0; }
  .doors td.acts { text-align: left; white-space: normal; }
  .doors td.acts > * { margin: 3px 4px 3px 0; }
}

/* knappar - klassiska med lätt gradient */
.btn { font: inherit; font-size: 13px; padding: 5px 12px; border: 1px solid #9aa6b6; border-radius: 3px; cursor: pointer;
       background: linear-gradient(#ffffff, #e9edf2); color: var(--text); }
.btn:hover { background: linear-gradient(#ffffff, #dde3ea); }
.btn:active { background: #d6dde6; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(#2e5b94, var(--navy)); color: #fff; border-color: #16294a; }
.btn.primary:hover { background: linear-gradient(#3567a6, #203d63); }
.btn.danger { background: linear-gradient(#c8473a, #a3342a); color: #fff; border-color: #7f261e; }
.btn.danger:hover { background: linear-gradient(#d4554a, #b03a2e); }
select { font: inherit; font-size: 13px; padding: 4px 4px; border: 1px solid #9aa6b6; border-radius: 3px; background: #fff; }
.allrow { margin-top: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* listor */
.list td { padding: 6px 4px; border-bottom: 1px solid var(--line2); vertical-align: top; font-size: 13px; }
.list td.t { white-space: nowrap; color: var(--muted); width: 1%; font-variant-numeric: tabular-nums; }
.list td.s { white-space: nowrap; width: 1%; text-align: right; }
.list small { color: var(--muted); display: block; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid; white-space: nowrap; }
.b-waiting { color: var(--amber); background: var(--amberbg); border-color: #f0d68a; }
.b-sent { color: var(--blue); background: var(--bluebg); border-color: #bcd2ee; }
.b-confirmed { color: var(--green); background: var(--greenbg); border-color: #bfe3cb; }
.b-noreply, .b-stale, .b-rejected { color: var(--red); background: var(--redbg); border-color: #efc2bd; }
.empty { color: var(--muted); font-size: 13px; }

/* teknisk vy */
.tech summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.tech[open] summary { margin-bottom: 8px; }
.demobtns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.demobtns .lbl { font-size: 12px; color: var(--muted); margin-right: 4px; }
.mqtt { list-style: none; margin: 0; padding: 8px; background: #101820; color: #d6e2ee; border-radius: 3px; font: 12px/1.45 Consolas, "Courier New", monospace;
        max-height: 360px; overflow: auto; }
.mqtt li { padding: 2px 0; border-bottom: 1px solid #1e2a36; word-break: break-all; }
.mqtt .ts { color: #7f93a8; }
.mqtt .out { color: #f1c40f; }
.mqtt .in { color: #5fd38d; }
.mqtt .note { color: #9fc3ff; }
.mqtt .bad { color: #ff8a80; }

/* dialog + toast */
.dlg { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.dlgbox { background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--red); border-radius: 4px; padding: 18px 20px; width: 100%; max-width: 420px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.dlgbox label { display: block; margin: 10px 0; font-weight: 600; }
.dlgbox label input[type=password] { display: block; width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid #aab4c3; border-radius: 3px; font: inherit; }
.dlgbox label select { display: block; margin-top: 4px; }
.dlgbox .chk { font-weight: normal; }
.dlgbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 9px 16px; border-radius: 4px;
         box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 20; max-width: calc(100% - 32px); }
.toast.err { background: var(--red); }

/* inloggning */
.loginwrap { display: flex; justify-content: center; padding: 40px 16px; }
.loginpanel { max-width: 460px; width: 100%; }
.loginpanel h1 { margin-bottom: 10px; }
.msbtn { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 8px; padding: 10px 14px; border: 1px solid #8c8c8c;
         background: #fff; color: #5e5e5e; text-decoration: none; font-weight: 600; font-size: 15px; border-radius: 2px; }
.msbtn:hover { background: #f3f3f3; }
.demobox { margin-top: 18px; font-size: 13px; background: var(--amberbg); border: 1px solid #f0d68a; padding: 10px 12px; border-radius: 3px; line-height: 1.7; }

/* simulerad Microsoft-inloggning */
.ssobody { background: #f2f2f2; }
.ssowrap { display: flex; justify-content: center; padding: 50px 16px; }
.ssopanel { background: #fff; width: 100%; max-width: 440px; padding: 30px 34px; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.ssohead { display: flex; align-items: center; gap: 8px; color: #5e5e5e; font-size: 14px; margin-bottom: 14px; }
.ssopanel h1 { font-size: 22px; margin-bottom: 8px; }
.acct { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 8px; border: 0; border-bottom: 1px solid #eee; background: #fff; font: inherit; cursor: pointer; }
.acct:hover { background: #f2f2f2; }
.acct small { display: block; color: #666; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.ssopanel .langsw a { color: var(--blue); }

/* simulerat larmsystem (ser medvetet annorlunda ut) */
.arcbody { background: #d9dde3; font-family: Tahoma, Verdana, sans-serif; font-size: 13px; }
.arctop { background: linear-gradient(#5a6b7d, #3e4b59); color: #fff; padding: 8px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.arctop a { color: #fff; }
.arcname { font-weight: 700; }
.arcname small { font-weight: normal; color: #d5dde6; margin-left: 8px; }
.arcmain { padding: 14px; max-width: 1200px; margin: 0 auto; }
.arcmain .note { background: #fffbe6; border: 1px solid #d8c77a; padding: 8px 12px; margin-bottom: 12px; line-height: 1.6; }
.arctable { background: #fff; border: 1px solid #9aa4b0; }
.arctable th { background: linear-gradient(#f4f6f8, #dfe4ea); text-align: left; padding: 5px 8px; border-bottom: 1px solid #9aa4b0; font-size: 12px; }
.arctable td { padding: 5px 8px; border-bottom: 1px solid #e2e6eb; }
.arctable tr:nth-child(even) td { background: #f6f8fa; }
.arctable .ok { color: var(--green); } .arctable .bad { color: var(--red); }
.arclink { font-weight: 700; white-space: nowrap; }
.arcjson { margin-top: 12px; }
.arcjson pre { background: #fff; border: 1px solid #9aa4b0; padding: 10px; overflow: auto; max-height: 400px; font-size: 12px; }
@media (max-width: 700px) {
  .arctable thead { display: none; }
  .arctable tr { display: block; border-bottom: 1px solid #9aa4b0; }
  .arctable td { display: block; border: 0; }
}

/* lägenhetsdörrar + befäl */
.apthead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.apthead h2 { margin: 0; }
.apthead h2 .muted { text-transform: none; letter-spacing: 0; font-weight: normal; }
.befal { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; font-weight: 600; padding: 4px 6px 4px 12px;
         border-radius: 14px; border: 1px solid #f0d68a; background: var(--amberbg); color: var(--amber); }
.befal.ok { border-color: #bfe3cb; background: var(--greenbg); color: var(--green); }
.befal .btn { font-weight: normal; }
.aptq { width: 100%; max-width: 340px; padding: 7px 10px; border: 1px solid #aab4c3; border-radius: 3px; font: inherit; margin: 6px 0 8px; }
.aptq:focus { outline: 2px solid #9cc0ea; border-color: var(--blue); }
.apts .dname { font-variant-numeric: tabular-nums; width: 70px; }
.befwhat { font-weight: 600; margin: 4px 0; }
.dlgbox label input[type=email] { display: block; width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid #aab4c3; border-radius: 3px; font: inherit; }
.dlgbox .demobox { margin: 6px 0; }
