:root {
  --bg: #060b14;
  --panel: #111827;
  --panel2: #172554;
  --text: #f8fbff;
  --muted: #b8c7da;
  --line: rgba(255,255,255,.10);
  --accent: #7dd3fc;
  --green: #34c759;
  --red: #ff453a;
  --orange: #d9902f;
  --white: #ffffff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(125,211,252,.16) 0%, transparent 26%),
    radial-gradient(circle at top right, rgba(96,165,250,.14) 0%, transparent 24%),
    linear-gradient(180deg, #0b1220 0%, #060b14 100%);
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; }
button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, white 8%), color-mix(in srgb, var(--accent) 86%, black 14%));
  color: #04111d;
  box-shadow: 0 10px 30px rgba(0,0,0,.20), inset 0 1px 0 rgba(255,255,255,.22);
  font-weight: 700;
  transition: transform .08s ease, filter .08s ease, opacity .08s ease;
}
button:active { transform: translateY(1px) scale(.99); filter: brightness(.88); }
button.secondary { background: rgba(255,255,255,.08); color: var(--text); border: 1px solid rgba(255,255,255,.10); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: inset 0 1px 0 rgba(255,255,255,.06); }
button.danger { background: var(--red); color: var(--white); }
button.good { background: var(--green); color: var(--white); }
button:disabled { opacity: .55; cursor: not-allowed; }
input, textarea, select {
  width: 100%;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input[type="color"] { height: 44px; padding: 5px; }
select option { color: #111; }
textarea { min-height: 88px; resize: vertical; }
label { display: block; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.hint, .muted { color: var(--muted); font-size: 13px; }

.app-shell { max-width: 1280px; margin: 0 auto; padding: 20px; }
.topbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 18px; position: sticky; top: 0; z-index: 10; background: linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg) 90%, transparent)); padding: 10px 0; }
.topbar h1 { margin: 0; font-size: 24px; }
.topbar small { color: var(--muted); }
.top-actions { margin: 0; }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 22px 60px rgba(0,0,0,.30), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.login-card { max-width: 440px; margin: 9vh auto; }
.login-card h1 { margin-top: 0; }
.role-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.role-tabs button { background: #213b58; color: var(--text); }
.role-tabs button.active { background: var(--accent); color: #03101d; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.menu-tile { text-align: left; min-height: 110px; background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04)); color: var(--text); border: 1px solid rgba(255,255,255,.08); border-radius: 22px; box-shadow: 0 18px 40px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.05); }
.menu-tile p { color: var(--muted); }
.section-title { margin: 24px 0 12px; color: var(--text); border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.message { margin: 12px 0; padding: 12px; border-radius: 12px; background: rgba(94,199,255,.12); border: 1px solid rgba(94,199,255,.25); }
.error { background: rgba(217,75,75,.14); border-color: rgba(217,75,75,.35); }

.people-box { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: rgba(255,255,255,.04); }
.people-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; margin-bottom: 12px; }
.check-row { display: flex; gap: 8px; align-items: center; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--text); margin: 0; }
.check-row input { width: auto; min-width: 18px; height: 18px; }
.people-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }

.history-row { display: grid; grid-template-columns: 160px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.history-row:last-child { border-bottom: 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.detail-row { grid-template-columns: 280px 1fr 1px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.editor-card { padding-bottom: 90px; }
.style-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.editor-field { display: grid; grid-template-columns: 34px minmax(180px,1.2fr) minmax(120px,.8fr) 115px 130px 120px 120px 120px 120px auto; gap: 10px; align-items: end; padding: 12px 0; border-bottom: 1px solid var(--line); }
.editor-field:last-child { border-bottom: 0; }
.drag-handle { display:flex; align-items:center; justify-content:center; width:34px; height:42px; border-radius:10px; background:rgba(255,255,255,.08); border:1px solid var(--line); cursor:grab; user-select:none; font-weight:800; color:var(--muted); }
.editor-field.dragging { opacity: .45; }
.editor-field.drag-over { background: rgba(94,199,255,.08); outline: 1px dashed var(--accent); }
.dashboard-visible { align-self: end; min-height: 42px; }
.sticky-actions { position: sticky; bottom: 10px; z-index: 9; background: color-mix(in srgb, var(--panel) 88%, black 12%); border: 1px solid var(--line); padding: 10px; border-radius: 14px; }

.scroll-top { position: fixed; right: 18px; bottom: 18px; z-index: 50; width: 48px; height: 48px; border-radius: 50%; padding: 0; box-shadow: 0 8px 30px rgba(0,0,0,.35); }

.tv-page { padding: 14px; height: 100vh; overflow: hidden; display: flex; flex-direction: column; background:
    radial-gradient(circle at top left, rgba(125,211,252,.12) 0%, transparent 22%),
    radial-gradient(circle at top right, rgba(96,165,250,.10) 0%, transparent 20%),
    linear-gradient(180deg, #08111f 0%, #050913 100%); }
.tv-page-rows { gap: 8px; }
.tv-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 10px; flex: 0 0 auto; }
.tv-header h1 { margin: 0; font-size: clamp(26px, 2.7vw, 48px); letter-spacing: -.03em; font-weight: 800; }
.tv-right { display: flex; align-items: center; gap: 12px; }
.tv-rows { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: repeat(var(--tv-row-count, 6), minmax(0, 1fr)); gap: 8px; }
.tv-section { min-height: 0; display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px; align-items: stretch; }
.tv-section-label { background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.05)); border: 1px solid rgba(255,255,255,.10); border-radius: 22px; padding: 12px; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 800; color: var(--text); font-size: clamp(14px, 1vw, 22px); line-height: 1.1; box-shadow: 0 16px 36px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.08); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.tv-section.summary-row .tv-section-label { background: linear-gradient(180deg, rgba(125,211,252,.28), rgba(125,211,252,.16)); }
.tv-section-grid { min-height: 0; display: grid; grid-template-columns: repeat(var(--section-cols, 4), minmax(0, 1fr)); gap: 8px; }
.summary-row .tv-section-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile { background: var(--field-bg, linear-gradient(180deg, rgba(255,255,255,.09), rgba(255,255,255,.05))); border: 1px solid rgba(255,255,255,.10); border-radius: 22px; padding: 11px 12px; min-height: 0; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; box-shadow: 0 16px 36px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.07); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.tile .label { color: var(--field-label, var(--muted)); font-size: clamp(11px, .82vw, 14px); line-height: 1.12; font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .value { font-weight: 800; font-size: clamp(20px, 1.75vw, 34px); line-height: 1.0; letter-spacing: -.03em; word-break: break-word; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.tile.status.good { background: linear-gradient(180deg, rgba(52,199,89,.55), rgba(52,199,89,.30)); }
.tile.status.bad { background: linear-gradient(180deg, rgba(255,69,58,.55), rgba(255,69,58,.28)); }
.tile.status.neutral { background: linear-gradient(180deg, rgba(148,163,184,.26), rgba(148,163,184,.12)); }
.tile.text-block .value { font-size: clamp(14px, 1.02vw, 20px); font-weight: 600; white-space: pre-wrap; -webkit-line-clamp: 4; }
.tile.wide { grid-column: 1 / -1; }
.refresh-note { color: var(--muted); font-size: 13px; margin-top: 4px; }

@media (max-width: 1100px) {
  .editor-field { grid-template-columns: 34px 1fr 1fr; }
  .editor-field > div, .editor-field > label { min-width: 0; }
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  .editor-field { grid-template-columns: 1fr; }
  .drag-handle { width: 100%; }
  .tv-rows { display: block; overflow: auto; }
  .tv-section { grid-template-columns: 1fr; margin-bottom: 10px; }
  .tv-section-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .tile.wide { grid-column: span 2; }
  .people-actions { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}


/* V7 custom TV canvas */
.tv-page-custom { gap: 10px; }
.dashboard-canvas {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--tv-cols, 24), minmax(0, 1fr));
  grid-template-rows: repeat(var(--tv-rows, 12), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
  align-content: stretch;
}
.dashboard-custom-tile { min-height: 0; }
.dashboard-custom-tile .tile-section {
  color: color-mix(in srgb, var(--muted) 72%, transparent);
  font-size: clamp(9px, .65vw, 12px);
  margin-top: 3px;
}
.dashboard-custom-tile.text-block .value { -webkit-line-clamp: 6; }

/* V7 layout editor */
.layout-canvas {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(var(--tv-cols, 24), minmax(0, 1fr));
  grid-auto-rows: minmax(96px, auto);
  gap: 12px;
  padding: 14px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.035);
}
.layout-item {
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.045));
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  padding: 12px;
  min-height: 96px;
  overflow: hidden;
  cursor: grab;
  box-shadow: 0 14px 34px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.06);
}
.layout-item.dragging { opacity: .45; }
.layout-item.drag-over { outline: 2px dashed var(--accent); background: rgba(125,211,252,.12); }
.layout-item-head { display: flex; flex-direction: column; gap: 4px; }
.layout-item-head strong { font-size: 15px; line-height: 1.15; }
.layout-item-head small, .layout-size { color: var(--muted); font-size: 12px; }
.layout-size { margin-top: 8px; }
.layout-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}
.layout-controls button {
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 12px;
}

@media (max-width: 900px) {
  .dashboard-canvas,
  .layout-canvas {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: auto;
  }
}


/* V8 XLS export */
.export-card { margin-bottom: 16px; }
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
.export-action { display: flex; align-items: end; }
.history-row { grid-template-columns: 160px 1fr minmax(420px, auto); }

@media (max-width: 900px) {
  .export-grid { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr; }
}


/* V9 charts */
.chart-card h3 { margin-top: 18px; }
.chart-section-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.chart-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  align-items: end;
}
.chart-result { margin-top: 16px; }
.chart-result.hidden { display: none; }
.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.chart-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 55%;
}
.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.chart-legend i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}
#chartCanvas {
  width: 100%;
  max-height: 520px;
  background: white;
  border-radius: 18px;
  border: 1px solid var(--line);
}
.chart-table-wrap {
  margin-top: 14px;
  max-height: 280px;
  overflow: auto;
}
.chart-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.chart-data-table th,
.chart-data-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}
.chart-data-table th {
  color: var(--text);
  background: rgba(255,255,255,.06);
  position: sticky;
  top: 0;
}
.chart-data-table td { color: var(--muted); }

@media (max-width: 900px) {
  .chart-head { flex-direction: column; }
  .chart-legend { max-width: 100%; justify-content: flex-start; }
}


/* V10 chart field dropdown */
.chart-dropdown {
  margin: 8px 0 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.045);
  overflow: hidden;
}
.chart-dropdown summary {
  padding: 13px 14px;
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  list-style: none;
}
.chart-dropdown summary::-webkit-details-marker { display: none; }
.chart-dropdown summary::after {
  content: '▾';
  float: right;
  color: var(--muted);
}
.chart-dropdown[open] summary::after { content: '▴'; }
.chart-field-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.chart-field-list .check-row span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chart-field-list .check-row small {
  color: var(--muted);
  font-size: 12px;
}


/* V11 TV layout rows */
.layout-row-settings {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.045);
}
.row-counter {
  display: inline-grid;
  grid-template-columns: auto 70px auto;
  gap: 10px;
  align-items: center;
}
.row-counter strong {
  text-align: center;
  font-size: 24px;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.08);
}

/* V11 chart period controls */
.chart-config-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}


/* V12: TV layout editor now mirrors final TV dashboard grid */
.layout-canvas.tv-layout-preview {
  display: grid;
  grid-template-columns: repeat(var(--tv-cols, 24), minmax(0, 1fr));
  grid-template-rows: repeat(var(--tv-rows, 12), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 14px;
  height: min(72vh, 760px);
  min-height: 520px;
  overflow: hidden;
  align-content: stretch;
  padding: 14px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at top left, rgba(125,211,252,.10) 0%, transparent 22%),
    linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.015));
}

.layout-canvas.tv-layout-preview .layout-item {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--field-bg, linear-gradient(180deg, rgba(255,255,255,.09), rgba(255,255,255,.05)));
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 22px;
  padding: 10px;
  overflow: hidden;
  box-shadow: 0 16px 36px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.07);
}

.layout-item-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
}
.layout-item-main > div {
  min-width: 0;
}
.layout-item-main strong {
  display: block;
  color: var(--text);
  font-size: clamp(11px, .75vw, 15px);
  line-height: 1.08;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layout-item-main small {
  display: block;
  color: var(--muted);
  font-size: clamp(9px, .6vw, 12px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layout-canvas.tv-layout-preview .layout-size {
  margin: 0;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}
.layout-canvas.tv-layout-preview .layout-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-top: 8px;
}
.layout-canvas.tv-layout-preview .layout-controls button {
  padding: 5px 3px;
  border-radius: 9px;
  font-size: 11px;
  min-width: 0;
}

/* keep final dashboard consistent with the same row logic */
.dashboard-canvas {
  grid-template-rows: repeat(var(--tv-rows, 12), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}
.dashboard-custom-tile {
  height: 100%;
}
.dashboard-custom-tile .value {
  font-size: clamp(14px, 1.4vw, 30px);
}
.dashboard-custom-tile .label {
  font-size: clamp(10px, .78vw, 14px);
}

@media (max-width: 900px) {
  .layout-canvas.tv-layout-preview {
    height: auto;
    min-height: 0;
    overflow: auto;
  }
}


/* V13 free-position TV layout */
.dashboard-canvas,
.layout-canvas.tv-layout-preview {
  grid-auto-flow: unset !important;
}

.dashboard-spacer {
  background: transparent;
  border: 0;
  pointer-events: none;
}

.layout-canvas.tv-layout-preview .layout-space-item {
  background: repeating-linear-gradient(
    135deg,
    rgba(125,211,252,.12),
    rgba(125,211,252,.12) 8px,
    rgba(255,255,255,.04) 8px,
    rgba(255,255,255,.04) 16px
  );
  border: 1px dashed rgba(125,211,252,.45);
}

.layout-canvas.tv-layout-preview .layout-space-item strong {
  color: var(--accent);
}

.layout-move-controls {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

.layout-move-controls .danger {
  grid-column: 1 / -1;
}

.row-counter {
  grid-template-columns: auto 70px auto auto;
}


/* V14 migration/fix: better layout editor readability */
.layout-canvas.tv-layout-preview .layout-item {
  isolation: isolate;
}
.layout-canvas.tv-layout-preview .layout-item:hover {
  z-index: 5;
}
.layout-canvas.tv-layout-preview .layout-controls {
  opacity: .92;
}
.layout-canvas.tv-layout-preview .layout-controls button {
  font-size: 10px;
  padding: 4px 2px;
}


/* V15 drag/drop layout editor */
.layout-canvas.tv-layout-preview {
  position: relative;
}

.layout-cell {
  min-height: 0;
  border: 1px dashed rgba(255,255,255,.055);
  border-radius: 12px;
  z-index: 0;
  pointer-events: auto;
}

.layout-cell.drop-hover {
  background: rgba(125,211,252,.22);
  border-color: rgba(125,211,252,.8);
}

.layout-canvas.tv-layout-preview .layout-item {
  z-index: 2;
  cursor: grab;
}

.layout-canvas.tv-layout-preview .layout-item:active {
  cursor: grabbing;
}

.layout-canvas.tv-layout-preview .layout-item.dragging {
  opacity: .45;
  outline: 2px solid var(--accent);
}

.add-spacer-main {
  min-width: 230px;
}


/* V16 adaptive labels for small TV layout tiles */
.dashboard-custom-tile,
.layout-canvas.tv-layout-preview .layout-item {
  --adaptive-label-size: clamp(10px, .78vw, 14px);
  --adaptive-value-size: clamp(14px, 1.4vw, 30px);
}

.dashboard-custom-tile[data-w="1"],
.layout-canvas.tv-layout-preview .layout-item[data-w="1"] {
  --adaptive-label-size: 9px;
  --adaptive-value-size: 14px;
}

.dashboard-custom-tile[data-w="2"],
.layout-canvas.tv-layout-preview .layout-item[data-w="2"] {
  --adaptive-label-size: 10px;
  --adaptive-value-size: 15px;
}

.dashboard-custom-tile[data-w="3"],
.layout-canvas.tv-layout-preview .layout-item[data-w="3"] {
  --adaptive-label-size: 11px;
  --adaptive-value-size: 18px;
}

.dashboard-custom-tile[data-h="1"],
.layout-canvas.tv-layout-preview .layout-item[data-h="1"] {
  --adaptive-value-size: 13px;
}

.dashboard-custom-tile .label {
  font-size: var(--adaptive-label-size) !important;
  line-height: 1.05 !important;
  white-space: normal !important;
  -webkit-line-clamp: 3 !important;
}

.dashboard-custom-tile .value {
  font-size: var(--adaptive-value-size) !important;
  line-height: 1 !important;
}

/* Editor layout: show readable names even in small boxes */
.layout-canvas.tv-layout-preview .layout-item-main strong {
  font-size: var(--adaptive-label-size) !important;
  line-height: 1.05 !important;
  white-space: normal !important;
  overflow: hidden !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  text-overflow: clip !important;
}

.layout-canvas.tv-layout-preview .layout-item-main small {
  font-size: 9px !important;
  line-height: 1.05 !important;
  white-space: normal !important;
  overflow: hidden !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 1 !important;
  -webkit-box-orient: vertical !important;
}

.layout-canvas.tv-layout-preview .layout-size {
  font-size: 9px !important;
  opacity: .85;
}

/* Smaller controls in tight tiles */
.layout-canvas.tv-layout-preview .layout-controls {
  gap: 3px !important;
  margin-top: 4px !important;
}

.layout-canvas.tv-layout-preview .layout-controls button {
  font-size: 9px !important;
  padding: 3px 2px !important;
  border-radius: 7px !important;
  min-height: 20px;
}

.layout-canvas.tv-layout-preview .layout-item[data-w="1"] .layout-controls,
.layout-canvas.tv-layout-preview .layout-item[data-w="2"] .layout-controls {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

.layout-canvas.tv-layout-preview .layout-item[data-h="1"] .layout-controls {
  display: none !important;
}

.layout-canvas.tv-layout-preview .layout-item[data-h="1"]:hover .layout-controls {
  display: grid !important;
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  z-index: 20;
  background: rgba(15,23,42,.88);
  border-radius: 10px;
  padding: 4px;
}

/* Give text more room in tiny editor tiles */
.layout-canvas.tv-layout-preview .layout-item {
  position: relative;
}

.layout-canvas.tv-layout-preview .layout-item-main {
  min-height: 0;
  gap: 4px;
}

.layout-canvas.tv-layout-preview .layout-item[data-w="1"] .layout-size,
.layout-canvas.tv-layout-preview .layout-item[data-w="2"] .layout-size {
  display: none;
}

/* Final dashboard: make tiny values/labels readable rather than clipped */
.dashboard-custom-tile[data-h="1"] {
  padding-top: 7px;
  padding-bottom: 7px;
}

.dashboard-custom-tile[data-h="1"] .tile-section {
  display: none;
}

.dashboard-custom-tile[data-w="1"] .tile-section,
.dashboard-custom-tile[data-w="2"] .tile-section {
  display: none;
}



/* V17 preview close button */
.preview-mode .tv-header {
  background: linear-gradient(180deg, rgba(0,0,0,.42), rgba(0,0,0,.12));
  border-radius: 18px;
  padding: 10px 12px;
}
.preview-close {
  background: rgba(255,255,255,.14) !important;
  border: 1px solid rgba(255,255,255,.22) !important;
}


/* V18 theme presets */
.theme-preset-box {
  display: grid;
  grid-template-columns: minmax(220px, 320px) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.045);
}
.theme-preset-action {
  display: flex;
  align-items: end;
}

@media (max-width: 900px) {
  .theme-preset-box {
    grid-template-columns: 1fr;
  }
}


/* V19: 24-column fine dashboard grid */
.dashboard-canvas,
.layout-canvas.tv-layout-preview {
  grid-template-columns: repeat(var(--tv-cols, 24), minmax(0, 1fr)) !important;
}

.layout-canvas.tv-layout-preview .layout-cell {
  border-radius: 8px;
}

.layout-canvas.tv-layout-preview .layout-item-main strong {
  font-size: clamp(9px, .62vw, 13px) !important;
}

.layout-canvas.tv-layout-preview .layout-item-main small,
.layout-canvas.tv-layout-preview .layout-size {
  font-size: 8px !important;
}

.layout-canvas.tv-layout-preview .layout-controls button {
  font-size: 8px !important;
  padding: 2px 1px !important;
  min-height: 18px;
}



/* V20: skutečný světlý režim */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel2: #f8fafc;
  --text: #0f172a;
  --muted: #334155;
  --line: rgba(15,23,42,.14);
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
}

:root[data-theme="light"] body {
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.08) 0%, transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #f6f8fb 100%);
}

:root[data-theme="light"] .app-shell {
  color: var(--text);
}

:root[data-theme="light"] .topbar {
  background: rgba(255,255,255,.92);
  color: var(--text);
  border-bottom: 1px solid rgba(15,23,42,.08);
  box-shadow: 0 8px 24px rgba(15,23,42,.08);
}

:root[data-theme="light"] .topbar h1,
:root[data-theme="light"] h1,
:root[data-theme="light"] h2,
:root[data-theme="light"] h3,
:root[data-theme="light"] strong {
  color: #0f172a;
}

:root[data-theme="light"] .topbar small,
:root[data-theme="light"] .muted,
:root[data-theme="light"] .hint,
:root[data-theme="light"] label,
:root[data-theme="light"] .tile-section {
  color: #334155 !important;
}

:root[data-theme="light"] .card,
:root[data-theme="light"] .editor-card,
:root[data-theme="light"] .layout-row-settings,
:root[data-theme="light"] .theme-preset-box,
:root[data-theme="light"] .people-box {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid rgba(15,23,42,.12);
  box-shadow: 0 18px 40px rgba(15,23,42,.08);
}

:root[data-theme="light"] input,
:root[data-theme="light"] textarea,
:root[data-theme="light"] select {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid rgba(15,23,42,.18);
}

:root[data-theme="light"] input::placeholder,
:root[data-theme="light"] textarea::placeholder {
  color: #64748b;
}

:root[data-theme="light"] select option {
  color: #0f172a;
  background: #ffffff;
}

:root[data-theme="light"] input[type="color"] {
  background: #f8fafc;
}

:root[data-theme="light"] button {
  color: #ffffff;
}

:root[data-theme="light"] button.secondary {
  background: #eef2f7;
  color: #0f172a;
  border: 1px solid rgba(15,23,42,.14);
  box-shadow: none;
}

:root[data-theme="light"] button.danger {
  background: #dc2626;
  color: #ffffff;
}

:root[data-theme="light"] .sticky-actions {
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(15,23,42,.12);
  box-shadow: 0 14px 34px rgba(15,23,42,.10);
}

:root[data-theme="light"] .message {
  background: #e0f2fe;
  color: #0f172a;
  border: 1px solid #7dd3fc;
}

:root[data-theme="light"] .error {
  background: #fee2e2;
  color: #7f1d1d;
  border-color: #fecaca;
}

:root[data-theme="light"] .menu-tile,
:root[data-theme="light"] .check-row,
:root[data-theme="light"] .history-row,
:root[data-theme="light"] .editor-field {
  background: #ffffff;
  color: #0f172a;
  border-color: rgba(15,23,42,.12);
}

:root[data-theme="light"] .menu-tile p {
  color: #334155;
}

:root[data-theme="light"] .section-title {
  color: #0f172a;
  border-bottom-color: rgba(15,23,42,.14);
}

/* světlý TV dashboard */
:root[data-theme="light"] .tv-page {
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.08) 0%, transparent 24%),
    linear-gradient(180deg, #ffffff 0%, #eef3f8 100%);
  color: #0f172a;
}

:root[data-theme="light"] .tv-header {
  color: #0f172a;
}

:root[data-theme="light"] .tv-header h1 {
  color: #0f172a;
}

:root[data-theme="light"] .refresh-note {
  color: #475569;
}

:root[data-theme="light"] .tile,
:root[data-theme="light"] .dashboard-custom-tile {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid rgba(15,23,42,.12);
  box-shadow: 0 12px 30px rgba(15,23,42,.10);
}

:root[data-theme="light"] .tile .label,
:root[data-theme="light"] .dashboard-custom-tile .label {
  color: #334155 !important;
}

:root[data-theme="light"] .tile .value,
:root[data-theme="light"] .dashboard-custom-tile .value {
  color: #0f172a;
}

:root[data-theme="light"] .tile.status.good {
  background: linear-gradient(180deg, #dcfce7, #bbf7d0);
  color: #052e16;
}

:root[data-theme="light"] .tile.status.bad {
  background: linear-gradient(180deg, #fee2e2, #fecaca);
  color: #7f1d1d;
}

:root[data-theme="light"] .tile.status.neutral {
  background: linear-gradient(180deg, #f1f5f9, #e2e8f0);
  color: #0f172a;
}

/* světlý layout editor */
:root[data-theme="light"] .layout-canvas.tv-layout-preview {
  background: #f8fafc;
  border: 1px solid rgba(15,23,42,.14);
}

:root[data-theme="light"] .layout-canvas.tv-layout-preview .layout-item {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid rgba(15,23,42,.14);
  box-shadow: 0 12px 24px rgba(15,23,42,.08);
}

:root[data-theme="light"] .layout-canvas.tv-layout-preview .layout-item-main strong {
  color: #0f172a !important;
}

:root[data-theme="light"] .layout-canvas.tv-layout-preview .layout-item-main small,
:root[data-theme="light"] .layout-canvas.tv-layout-preview .layout-size {
  color: #475569 !important;
}

:root[data-theme="light"] .layout-cell {
  border-color: rgba(15,23,42,.08);
}

:root[data-theme="light"] .layout-cell.drop-hover {
  background: rgba(37,99,235,.14);
  border-color: rgba(37,99,235,.55);
}

:root[data-theme="light"] .layout-canvas.tv-layout-preview .layout-space-item {
  background: repeating-linear-gradient(
    135deg,
    rgba(37,99,235,.10),
    rgba(37,99,235,.10) 8px,
    rgba(15,23,42,.03) 8px,
    rgba(15,23,42,.03) 16px
  );
  border: 1px dashed rgba(37,99,235,.45);
}

:root[data-theme="light"] .chart-data-table th {
  background: #e2e8f0;
  color: #0f172a;
}

:root[data-theme="light"] .chart-data-table td {
  color: #334155;
}
