:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --text: #17201a;
  --muted: #5d6b62;
  --border: #d9e0db;
  --accent: #15803d;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --topbar: #14532d;
  --topbar-ink: #ecfdf3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --surface: #18201b;
    --text: #e6ece8;
    --muted: #9aa8a0;
    --border: #2b362f;
    --accent: #22c55e;
    --accent-ink: #062b14;
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
    --topbar: #0b2716;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2 { font-size: 1.1rem; }
input, select, button { font: inherit; color: inherit; }
input, select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
button { cursor: pointer; border-radius: 8px; padding: 8px 12px; border: 1px solid var(--border); background: var(--surface); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 4px 8px; font-size: .85rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.hint { color: var(--muted); font-size: .9rem; }
.plain { list-style: none; margin: 0; padding: 0; }
label { display: flex; flex-direction: column; gap: 4px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }

.topbar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 12px; padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px; background: var(--topbar); color: var(--topbar-ink); flex-wrap: wrap; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.topbar nav button, .topbar > button { background: transparent; color: inherit; border-color: transparent; white-space: nowrap; }
.topbar nav button.active { background: rgba(255,255,255,.15); }

main { padding: 16px; }
.view { display: flex; flex-direction: column; gap: 12px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar h2 { margin-right: auto; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row input, .form-row select { flex: 1 1 140px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: .9rem; }
.chip { border-radius: 999px; padding: 3px 10px; font-size: .85rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.off { color: var(--muted); }
.badge.warn { color: var(--warn); }
.badge.danger { color: var(--danger); }

.view-map { display: grid; grid-template-columns: 1fr 280px; gap: 12px; height: calc(100vh - 90px); }
#map { border-radius: 12px; border: 1px solid var(--border); min-height: 360px; height: 100%; }
.map-side { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.map-side li { padding: 8px; border-radius: 8px; cursor: pointer; }
.map-side li:hover, .map-side li.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
@media (max-width: 760px) {
  main { padding: 12px; }
  .view-map { grid-template-columns: 1fr; height: auto; }
  #map { height: 60vh; }
}

.usage-player { margin-bottom: 14px; }
.usage-player h3 { margin: 0 0 8px; font-size: 1rem; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 200px) 1fr auto; gap: 10px; align-items: center; padding: 4px 0; }
.bar { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.over > span { background: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 2000; max-width: calc(100% - 32px); }
@media (max-width: 760px) {
  .topbar nav { order: 3; flex-basis: 100%; }
  .topbar > button { margin-left: auto; }
}
/* Na telefonu (Poco) řádky tabulek jako karty */
@media (max-width: 760px) {
  table thead { display: none; }
  table tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table tr:last-child { border-bottom: none; }
  table td { display: block; border: none; padding: 2px 0; }
  td .actions { justify-content: flex-start; margin-top: 6px; }
}

/* Aplikace v telefonech (jako Family Link) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button { border: none; border-radius: 0; background: transparent; padding: 6px 14px; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.app-list { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.app-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.app-row:last-child { border-bottom: none; }
.app-row.blocked .app-icon, .app-row.blocked .app-name { opacity: .55; }
.app-icon { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; background: var(--bg); display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.app-name { min-width: 0; }
.app-name b, .app-name .muted { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-limit { display: flex; flex-direction: row; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.app-limit input { width: 70px; padding: 5px 8px; }
.app-empty { padding: 16px; color: var(--muted); }
.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--danger); opacity: .75; transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--ok); opacity: 1; }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 10px; }
details.card .form-row { margin-bottom: 10px; }
@media (max-width: 760px) {
  .app-row { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .app-row .switch { grid-column: 3; grid-row: 1; }
  .app-limit { grid-column: 2 / -1; grid-row: 2; }
}
select.small { padding: 4px 8px; font-size: .85rem; }

/* Žebříček nejpoužívanějších aplikací */
.top-title { margin: 0 0 6px; font-size: 1rem; }
.top-row { display: grid; grid-template-columns: 28px 40px minmax(0, 1fr) 150px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.top-row:last-child { border-bottom: none; }
.top-rank { color: var(--muted); font-weight: 700; text-align: right; }
.top-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.top-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-sub { font-size: .85rem; margin-top: 4px; }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 40px; }
.spark i { flex: 1; min-width: 2px; background: var(--accent); border-radius: 2px 2px 0 0; }
.spark i.zero { background: var(--border); }
@media (max-width: 760px) {
  .top-row { grid-template-columns: 22px 40px minmax(0, 1fr); }
  .spark { grid-column: 3; height: 28px; }
}

/* Úkoly a skupiny aplikací */
.sub-list { display: flex; flex-direction: column; gap: 10px; }
.sub-card { display: flex; flex-direction: column; gap: 10px; }
.sub-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.sub-head .muted { display: block; font-size: .9rem; }
.sub-shots { display: flex; gap: 10px; flex-wrap: wrap; }
.sub-shots figure { margin: 0; display: flex; flex-direction: column; gap: 4px; align-items: center; min-width: 90px; }
.sub-shots img { height: 200px; max-width: 100%; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); cursor: zoom-in; object-fit: contain; }
.sub-shots figcaption { color: var(--muted); font-size: .85rem; }
.sub-card .sub-points { width: 80px; flex: none; }
.sub-card label.inline { flex: none; }
.group-form { display: flex; flex-direction: column; gap: 10px; }
.pick-list { max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 12px; }
.pick { padding: 4px 0; min-width: 0; }
.pick span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick input { flex: none; }
.lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* Potvrzovací okno */
.ask { position: fixed; inset: 0; z-index: 2500; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 16px; }
.ask-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.ask-card p { margin: 0; }
.ask-buttons { display: flex; justify-content: flex-end; gap: 8px; }
.app-uninstall { margin-top: 4px; }
.app-unset { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; font-size: .85rem; }
@media (max-width: 760px) { .app-unset { grid-column: 2 / -1; grid-row: 3; justify-content: flex-start; } }

/* nastavení velitele */
label.check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: normal; }
label.check input { width: auto; }
#commander-fields { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#commander-fields:disabled { opacity: .5; }
#commander-fields .legend { font-weight: 600; margin-top: 8px; padding: 0; }
#commander-perms { display: flex; flex-direction: column; gap: 6px; }
#commander-form { max-height: calc(100vh - 32px); overflow-y: auto; }
