:root {
  --bg: #0c0f14;
  --bg-elevated: #121722;
  --bg2: #121722;
  --panel: #121722;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.15);
  --warn: #fbbf24;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
/* U iframeu: bez min-height:100% inače iframe raste u beskonačnost */
html.ecmo-embedded,
html.ecmo-embedded body {
  overflow: hidden !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}
/* 100vh u iframeu prati visinu iframea → beskonačni rast */
html.ecmo-embedded main,
html.ecmo-embedded .panel {
  min-height: 0 !important;
}
html.ecmo-embedded .app-header {
  display: none !important;
}
html.ecmo-embedded body {
  background: transparent !important;
}
html.ecmo-embedded .analitika-window {
  margin: 0;
}
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(94, 234, 212, 0.12), transparent),
    radial-gradient(800px 400px at 100% 0%, rgba(99, 102, 241, 0.1), transparent),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  background: rgba(12, 15, 20, 0.92); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; flex-direction: column; gap: 4px; }
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.02em; font-weight: 700; }
.brand span { color: var(--muted); font-size: 0.88rem; max-width: 56ch; }
.header-actions { display: flex; gap: 0.65rem; flex-wrap: wrap; align-items: center; }
.user-bar {
  display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
  padding: 0.35rem 0.55rem; border: 1px solid var(--border); border-radius: 10px;
  background: rgba(255,255,255,0.03);
}
.user-status { font-size: 0.8rem; color: var(--muted); max-width: 18ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-status.logged { color: var(--ok); }
.user-input {
  width: 150px; max-width: 28vw; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.35rem 0.55rem; font: inherit; font-size: 0.85rem;
}
.report-signature {
  margin-top: 1.25rem; padding-top: 1rem; border-top: 1px dashed var(--border);
  display: grid; gap: 0.25rem;
}
.report-signature .muted { color: var(--muted); font-size: 0.85rem; margin: 0; }
.report-signature p { margin: 0; }

.tabs {
  display: flex; gap: 0.55rem; padding: 0.75rem 1rem 0; flex-wrap: wrap;
  max-width: none; margin: 0; width: 100%;
}
.tab {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
}
.tab:hover { border-color: rgba(94, 234, 212, 0.35); }
.tab[aria-selected="true"] {
  background: var(--accent-dim);
  border-color: rgba(94, 234, 212, 0.45);
  color: var(--accent);
}

/* Jedan „prozor“ kao Pregled — cijela aplikacija u istoj kartici */
.analitika-window {
  margin: 0 1rem 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.analitika-window > .tabs {
  padding: 0.9rem 1.2rem 0.75rem;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(94, 234, 212, 0.06), transparent);
  border-bottom: 1px solid var(--border);
}
.analitika-window > .tabs .tab {
  background: rgba(12, 15, 20, 0.55);
}
.analitika-window > .tabs .tab[aria-selected="true"] {
  background: var(--accent-dim);
}
.analitika-window > main {
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: none;
  min-height: 0;
}
.analitika-window .panel {
  background: transparent;
  border: 0;
  box-shadow: none;
  margin: 0;
  border-radius: 0;
  min-height: 0;
  padding: 1.15rem 1.25rem 1.45rem;
}
.analitika-window .footer-note {
  margin: 0;
  padding: 0 1.25rem 1.25rem;
}

main {
  padding: 0.65rem 1rem 1.5rem;
  max-width: none;
  margin: 0;
  width: 100%;
  min-height: calc(100vh - 120px);
}
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.35rem;
  margin-top: 0.5rem;
  box-shadow: var(--shadow);
  min-height: calc(100vh - 140px);
}
.panel h2 { margin: 0 0 0.35rem; font-size: 1.25rem; font-weight: 700; }
.panel h3 { margin: 1.1rem 0 0.55rem; font-size: 1.02rem; font-weight: 650; }
.lead { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.92rem; max-width: none; }

/* —— Gumbi kao u ECmo —— */
.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
  background: linear-gradient(135deg, #2dd4bf, #14b8a6);
  color: #042f2e;
  border-color: rgba(255, 255, 255, 0.2);
}
.btn:hover {
  filter: brightness(1.05);
  color: #042f2e;
  border-color: rgba(255, 255, 255, 0.2);
}
.btn:active { transform: scale(0.98); }
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-ok,
.btn-warn {
  background: linear-gradient(135deg, #2dd4bf, #14b8a6);
  color: #042f2e;
  border-color: rgba(255, 255, 255, 0.2);
}
.btn-primary:hover,
.btn-secondary:hover,
.btn-ghost:hover,
.btn-ok:hover,
.btn-warn:hover {
  filter: brightness(1.05);
  color: #042f2e;
}

.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { display: grid; gap: 1rem; grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { display: grid; gap: 1rem; grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-cost {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  margin-top: 0.5rem;
}
@media (max-width: 1100px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  main, .tabs, .app-header { padding-left: 1rem; padding-right: 1rem; }
}
@media (max-width: 640px) {
  .grid-4 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span {
  font-size: 0.75rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.field input, .field select, .field textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 0.65rem 0.75rem; font: inherit; min-height: 2.6rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: rgba(94, 234, 212, 0.45);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.field textarea { min-height: 100px; resize: vertical; }

.kpis {
  display: grid; gap: 0.85rem;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  margin: 0.9rem 0 1.2rem;
}
.kpi {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  min-height: 5.2rem;
}
.kpi-label {
  display: block; color: var(--muted); font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.35rem;
}
.kpi-value {
  display: block; font-family: var(--mono); font-size: 1.35rem; font-weight: 700;
  letter-spacing: -0.02em; color: var(--accent);
}
.kpi-unit { color: var(--muted); font-size: 0.78rem; font-weight: 500; }
.kpi.warn { border-color: rgba(251, 191, 36, 0.45); }
.kpi.danger { border-color: rgba(248, 113, 113, 0.45); }
.kpi .kpi-value.muted { color: var(--text); }

.scoreboard {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0.5rem 0 1.25rem;
}
.score-tile {
  background: linear-gradient(160deg, rgba(94, 234, 212, 0.1), rgba(12, 15, 20, 0.4));
  border: 1px solid rgba(94, 234, 212, 0.22);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  min-height: 7.5rem;
}
.score-tile h4 {
  margin: 0 0 0.55rem; font-size: 0.78rem; font-weight: 650;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.score-tile .big {
  font-family: var(--mono); font-size: 1.55rem; font-weight: 700; color: var(--accent);
}
.score-tile .sub { margin-top: 0.45rem; color: var(--muted); font-size: 0.85rem; }
.score-tile.ok { border-color: rgba(74, 222, 128, 0.35); }
.score-tile.warn { border-color: rgba(251, 191, 36, 0.4); }
.score-tile.bad { border-color: rgba(248, 113, 113, 0.4); }
@media (max-width: 1100px) {
  .scoreboard { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .scoreboard { grid-template-columns: 1fr; }
}

.utility-tiles {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 1.25rem;
}
.utility-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
}
.utility-tile .name { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.utility-tile .val { font-family: var(--mono); font-size: 1.25rem; font-weight: 700; margin-top: 0.35rem; }
.utility-tile .bar {
  margin-top: 0.75rem; height: 6px; border-radius: 999px; background: rgba(255,255,255,0.06); overflow: hidden;
}
.utility-tile .bar > span { display: block; height: 100%; border-radius: 999px; }
@media (max-width: 900px) {
  .utility-tiles { grid-template-columns: 1fr; }
}

.table-wrap {
  overflow: auto; border: 1px solid var(--border); border-radius: 12px;
  max-height: calc(100vh - 220px); background: rgba(0,0,0,0.18);
  flex: 1;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th {
  background: #0a0e16; color: var(--muted); font-weight: 650;
  position: sticky; top: 0; z-index: 1;
}
tr:hover td { background: var(--accent-dim); }
tr.clickable { cursor: pointer; }

.actions { display: flex; gap: 0.65rem; flex-wrap: wrap; margin-top: 1.1rem; align-items: center; }
.msg { margin-top: 0.55rem; color: var(--accent); font-size: 0.9rem; min-height: 1.2em; }
.msg.err { color: var(--danger); }

.chart-box {
  background: rgba(8, 12, 18, 0.65); border: 1px solid var(--border); border-radius: 12px;
  padding: 0.85rem;
  height: 400px;
  max-height: 400px;
  position: relative;
  overflow: hidden;
}
.chart-box.tall {
  height: 400px;
  max-height: 400px;
}
.chart-box h3 { margin: 0 0 0.55rem; font-size: 0.92rem; line-height: 1.2; }
.chart-box .chart-frame {
  position: relative;
  height: calc(100% - 1.7rem);
  width: 100%;
  overflow: hidden;
}
.chart-box canvas {
  display: block !important;
}

/* Puni prozor: tablica + graf jedan pored drugog */
.view-split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
}
.view-split .table-wrap {
  max-height: calc(100vh - 280px);
  min-height: 360px;
}
.view-split .chart-box {
  height: 400px;
  max-height: 400px;
  min-height: 400px;
  position: sticky;
  top: 72px;
}
@media (max-width: 1200px) {
  .view-split {
    grid-template-columns: 1fr;
  }
  .view-split .table-wrap {
    max-height: min(55vh, 520px);
  }
  .view-split .chart-box {
    height: 380px;
    max-height: 380px;
    position: static;
  }
}

.badge {
  display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.74rem;
  background: var(--accent-dim); border: 1px solid rgba(94, 234, 212, 0.25); color: var(--accent);
}
.badge-ok { color: var(--ok); border-color: rgba(74, 222, 128, 0.35); background: rgba(74, 222, 128, 0.1); }
.badge-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.1); }
.badge-danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.1); }
.badge-ecmo { color: var(--accent); }

.alarm-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.65rem; }
.alarm-list li {
  padding: 0.85rem 1rem; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg);
}
.alarm-list li.warn { border-color: rgba(251, 191, 36, 0.4); }
.alarm-list li.danger { border-color: rgba(248, 113, 113, 0.4); }

.filters {
  display: flex; flex-wrap: wrap; gap: 0.85rem; align-items: end;
  padding: 1rem; background: var(--bg); border-radius: 12px; border: 1px solid var(--border);
  margin-bottom: 1.1rem;
}
.filters .field { min-width: 140px; }

.goal-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 1rem; background: var(--bg);
  min-height: 7.5rem;
}
.goal-card strong { display: block; margin-bottom: 0.35rem; }
.goal-card small { color: var(--muted); }

.section-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.1rem 0.5rem;
  background: rgba(0,0,0,0.16); margin-top: 1rem;
}
.section-card h4 {
  margin: 0 0 0.75rem; font-size: 0.8rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650;
}

.status-bar {
  display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center;
  margin-bottom: 1rem;
}

.action-status-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; font: inherit; max-width: 140px;
}
.hidden { display: none !important; }
.footer-note { margin-top: 1.6rem; color: var(--muted); font-size: 0.82rem; text-align: center; }

#isgePreview {
  margin-top: 1rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; overflow: auto; font-size: 0.86rem;
  max-height: calc(100vh - 260px); min-height: 50vh;
}

@media print {
  .app-header, .tabs, .header-actions, .actions, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { border: none; background: #fff; box-shadow: none; }
}
