:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #e3e7ee;
  --accent: #2f6fed;
  --accent-dark: #2358c4;
  --ok: #1b7f3b;
  --warn: #c62828;
  --bar: #d9e4fb;
  --bar-fill: #4f86f7;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}
.hidden { display: none !important; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 16px;
}
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login h1 { margin: 0; font-size: 22px; }
.sub { color: var(--muted); margin: 2px 0 8px; font-size: 13px; }
.msg { color: var(--warn); font-size: 13px; min-height: 1.2em; margin: 0; }
input[type=password], input[type=text], input[type=number], input[type=time], input:not([type]), select {
  font: inherit;
  font-size: 16px; /* unter 16px zoomt iOS beim Tippen hinein */
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
button {
  font: inherit;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--accent-dark); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }

header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; flex: 1; }
header select { max-width: 45vw; }
.devstate { padding: 8px 16px 0; color: var(--muted); font-size: 13px; }
.devstate .on { color: var(--ok); font-weight: 600; }
.devstate .off { color: var(--warn); font-weight: 600; }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; }
.tabs button { border: none; background: transparent; padding: 8px 10px; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.periods { display: flex; gap: 6px; padding: 10px 16px 0; flex-wrap: wrap; }
.periods button { padding: 6px 12px; font-size: 13px; }
.periods button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.total { font-size: 15px; margin-bottom: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
td.r, th.r { text-align: right; white-space: nowrap; }
.bar { height: 8px; background: var(--bar); border-radius: 5px; overflow: hidden; margin: 4px 0 2px; max-width: 260px; }
.bar > i { display: block; height: 100%; background: var(--bar-fill); }
.lim-ok { color: var(--ok); }
.lim-over { color: var(--warn); font-weight: 600; }
.lim-blocked { color: var(--warn); font-size: 12px; }
.empty { color: var(--muted); font-style: italic; }
.appname { font-weight: 600; }
.appexe { color: var(--muted); font-size: 11px; display: block; max-width: 48vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hist { display: flex; align-items: flex-end; gap: 4px; height: 190px; padding-top: 18px; }
.hist .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.hist .v { font-size: 10px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.hist .b { width: 70%; background: var(--bar-fill); border-radius: 4px 4px 0 0; min-height: 2px; }
.hist .d { font-size: 10px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.hist .col.today .b { background: var(--accent-dark); }

.power td { font-size: 14px; }
.power .live { color: var(--ok); font-weight: 600; }

.limits input[type=number] { width: 90px; text-align: right; }
.addrow { display: flex; gap: 6px; margin: 10px 0; }
.addrow input { flex: 1; }
label.check { display: block; margin: 8px 0; }
label.check input { margin-right: 6px; }
.sched td input[type=time] { width: 110px; }

.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: #fff; border-top: 1px solid var(--line);
}
.savebar span { flex: 1; color: var(--muted); font-size: 13px; }
.savebar span.ok { color: var(--ok); }
.savebar span.err { color: var(--warn); }

.wd-short { display: none; }
.muted { color: var(--muted); }
button.icon { padding: 7px 10px; font-size: 18px; line-height: 1; }

/* Sperren / Freigeben */
.globalbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.gb-text { flex: 1; min-width: 140px; }
.gb-text span { display: block; font-size: 13px; }
.gb-btns { display: flex; gap: 6px; }
button.act { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
button.act.lock { border-color: #f0b4b4; background: #fff3f3; }
button.act.unlock { border-color: #b7dfc2; background: #f0faf3; }
button.act.clear { padding: 6px 9px; }
button.act.small { padding: 4px 7px; font-size: 14px; }
/* App-Karten in der Übersicht: großer Name, Zeiten darunter, große Knöpfe rechts */
.applist { display: flex; flex-direction: column; gap: 10px; margin: 0 16px 12px; }
.approw { display: block; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.appmain { min-width: 0; cursor: pointer; }
.applist { --appname-size: 28px; }
.approw .appname { font-size: var(--appname-size); font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; }
.appmeta, .state-lock, .state-unlock { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.approw .appname::before { content: "▸ "; color: var(--muted); font-size: 16px; }
.approw.open .appname::before { content: "▾ "; }
.approw .bar { margin: 8px 0 6px; max-width: none; }
.appmeta { font-size: 16px; line-height: 1.5; }
/* bis zu drei Knöpfe nebeneinander, immer in Dritteln – auch wenn nur zwei da sind */
.appbtns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.appbtns button.act { font-size: 16px; padding: 12px 6px; min-width: 0; width: 100%; font-weight: 600; white-space: nowrap; }
.state-lock { color: var(--warn); font-size: 14px; display: block; margin-top: 2px; }
.state-unlock { color: var(--ok); font-size: 14px; display: block; margin-top: 2px; }
.details { background: #f8f9fc; padding: 10px 10px 12px; margin: 12px -14px -12px; border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; }
.details ul { margin: 0 0 10px; padding-left: 0; list-style: none; }
.details li { display: flex; gap: 8px; justify-content: space-between; font-size: 13px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.details li span:first-child { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.apps { table-layout: fixed; }
table.apps th:nth-child(2) { width: 88px; }
table.apps th:nth-child(3) { width: 104px; }
table.apps td { overflow: hidden; }
.details li span:last-child { white-space: nowrap; color: var(--muted); }
.details a { color: var(--accent); text-decoration: none; }
.details a:hover { text-decoration: underline; }
.rename { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rename input { flex: 1; min-width: 140px; }
.rename small { width: 100%; color: var(--muted); }

/* Dauer-Abfrage */
.sheet { position: fixed; inset: 0; background: rgba(20, 28, 40, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet-box { background: #fff; border-radius: 16px 16px 0 0; padding: 18px 16px 24px; width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 8px; }
.sheet-box button { width: 100%; padding: 12px; }
@media (min-width: 561px) { .sheet { align-items: center; } .sheet-box { border-radius: 16px; } }
.pwcard form { display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.pwbtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.msg.ok { color: var(--ok); }

@media (max-width: 560px) {
  body { font-size: 14px; }
  .card { margin: 10px 8px; padding: 12px 10px; }
  .applist { margin: 0 8px 10px; gap: 8px; }
  .approw { padding: 10px 10px; }
  .details { margin: 10px -10px -10px; }
  header { padding: 10px 8px; gap: 6px; }
  .brand { font-size: 16px; }
  header select { max-width: 40vw; padding: 7px 6px; }
  header button { padding: 7px 10px; font-size: 13px; }
  .tabs { padding: 4px 4px 0; gap: 0; }
  .tabs button { flex: 1; padding: 8px 2px; font-size: 13px; text-align: center; }
  .periods { padding: 8px 8px 0; gap: 4px; }
  .periods button { flex: 1; padding: 6px 4px; font-size: 13px; text-align: center; }
  .devstate, .savebar { padding-left: 8px; padding-right: 8px; }
  th, td { padding: 7px 4px; }
  .applist { --appname-size: 24px; }
  .appmeta { font-size: 15px; }
  .appbtns button.act { padding: 11px 4px; font-size: 15px; }
  .appexe { display: none; }
  .hist { height: 160px; gap: 2px; }
  .hist .v { display: none; }
  .hist .d { font-size: 9px; }
  .limits input[type=number] { width: 72px; padding: 7px 6px; }
  .sched td input[type=time] { width: 92px; padding: 6px 4px; }
  .wd-long { display: none; }
  .wd-short { display: inline; }
  .savebar button { padding: 9px 16px; }
}
