: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(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(12, minmax(0, 1fr));
  grid-auto-rows: minmax(120px, 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: 120px;
  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;
  }
}
