/* ─────────────────────────────────────────────────────────────────────────
   CloudBuilder Control Panel – Styles
   Theme: ruhige Operations-Konsole
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Farben */
  --bg:        #101316;
  --base:      #151a1f;
  --mantle:    #0c0f12;
  --surface0:  #232a31;
  --surface1:  #33404a;
  --overlay0:  #7a8793;
  --text:      #e5edf3;
  --subtext0:  #a9b6c1;
  --subtext1:  #c6d1da;
  --blue:      #5fb3ff;
  --blue-dim:  #4199e8;
  --green:     #63d489;
  --yellow:    #f3c96b;
  --red:       #ff6b81;
  --teal:      #4fd1c5;
  --peach:     #f59e6c;

  /* Layout */
  --sidebar-w: 260px;
  --term-h:    290px;
  --radius:    6px;
  --radius-sm: 4px;

  /* Schriften */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
}

/* ── Basis ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

button:disabled,
select:disabled,
input:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* ── App-Layout ─────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--base);
  border-right: 1px solid var(--surface0);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .2s ease;
}

#sidebar.collapsed { width: 52px; overflow: hidden; }
#sidebar.collapsed .logo,
#sidebar.collapsed #btn-new span,
#sidebar.collapsed .inst-name,
#sidebar.collapsed .inst-systems { display: none; }
#sidebar.collapsed #btn-collapse { transform: rotate(180deg); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid var(--surface0);
  min-height: 52px;
  flex-shrink: 0;
}

.logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: 0;
}

.sidebar-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--surface0);
  flex-shrink: 0;
}

/* Instance-Liste */
#instance-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.inst-item {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 2px;
  transition: background .12s, border-color .12s;
}
.inst-item:hover  { background: var(--surface0); }
.inst-item.active { background: var(--surface0); border-color: var(--blue); }

.inst-name    { font-size: 13px; font-weight: 500; }
.inst-systems { font-size: 11px; color: var(--overlay0); margin-top: 2px; }

.placeholder { color: var(--overlay0); padding: 16px 10px; font-size: 13px; text-align: center; }

/* ── Workspace ──────────────────────────────────────────────────────────── */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

/* ── Leerzustand ─────────────────────────────────────────────────────────── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  color: var(--overlay0);
  text-align: center;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--surface1);
  border-radius: 8px;
  color: var(--blue);
  font-weight: 800;
  letter-spacing: 0;
}
#empty-state h2 { font-size: 18px; color: var(--subtext0); font-weight: 600; }
#empty-state p  { font-size: 13px; line-height: 1.7; }

/* ── Instance-Detail ─────────────────────────────────────────────────────── */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--surface0);
}

.detail-header h1 { font-size: 22px; font-weight: 700; }
.detail-controls  { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.view-switch {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
}

.view-tab {
  min-width: 78px;
  padding: 5px 9px;
  background: transparent;
  border: 0;
  border-radius: 3px;
  color: var(--subtext0);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.view-tab.active {
  background: var(--surface0);
  color: var(--text);
}

.muted { font-size: 12px; color: var(--overlay0); display: block; margin-top: 2px; }

.path-line {
  display: block;
  max-width: min(820px, 58vw);
  margin-top: 6px;
  color: var(--subtext0);
  font-family: var(--mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
}
.muted-pill { color: var(--subtext0); background: var(--surface0); }
.ok-pill { color: var(--green); background: rgba(99, 212, 137, .09); border-color: rgba(99, 212, 137, .45); }
.running-pill { color: var(--yellow); background: rgba(243, 201, 107, .09); border-color: rgba(243, 201, 107, .45); }
.error-pill { color: var(--red); background: rgba(255, 107, 129, .09); border-color: rgba(255, 107, 129, .45); }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}
.summary-strip > div {
  min-width: 0;
  padding: 10px 12px;
  background: var(--base);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
}
.summary-label {
  display: block;
  color: var(--overlay0);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.summary-strip strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.summary-wide {
  grid-column: 1 / -1;
}

/* ── Aktions-Grid ────────────────────────────────────────────────────────── */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 32px;
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .12s;
  min-height: 84px;
}
.action-card:hover { background: var(--surface1); border-color: var(--blue); transform: translateY(-2px); }
.action-card:active { transform: translateY(0); }
.action-card.running { border-color: var(--yellow); background: rgba(249,226,175,.07); }
.action-card:disabled { opacity: .4; cursor: default; transform: none; }

.action-icon { font-size: 22px; line-height: 1; }

.run-options {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin: -18px 0 28px;
  background: var(--base);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
}

.check-option,
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--subtext0);
  font-size: 12px;
}

.check-option input {
  width: 15px;
  height: 15px;
  accent-color: var(--blue);
}

.inline-field input {
  width: 150px;
  min-width: 0;
  padding: 5px 8px;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
}

/* ── Systeme ─────────────────────────────────────────────────────────────── */
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--overlay0);
  margin-bottom: 10px;
}

.sys-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface0);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
.sys-name { font-size: 13px; font-weight: 500; }
.sys-badge {
  font-size: 11px;
  color: var(--subtext0);
  background: var(--mantle);
  padding: 2px 7px;
  border-radius: 10px;
}

/* ── Container ───────────────────────────────────────────────────────────── */
.containers-section {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--surface0);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.containers-list {
  display: grid;
  gap: 6px;
}

.container-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 78px;
  padding: 10px 12px;
  background: var(--surface0);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.container-row.pending {
  border-color: var(--yellow);
}

.container-main {
  min-width: 0;
}

.container-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.container-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.container-meta,
.container-status,
.container-ports {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--subtext0);
  font-size: 11px;
}

.container-meta {
  margin-top: 3px;
  font-family: var(--mono);
}

.container-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.container-btn {
  min-width: 52px;
  text-align: center;
}

.container-btn.danger {
  color: var(--red);
  border-color: rgba(255, 107, 129, .45);
}

/* ── Runtime-Infos ───────────────────────────────────────────────────────── */
.runtime-section {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--surface0);
}

.runtime-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.runtime-block {
  min-width: 0;
  background: var(--base);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.runtime-title {
  margin-bottom: 8px;
  color: var(--subtext1);
  font-size: 12px;
  font-weight: 700;
}

.link-list,
.command-list {
  display: grid;
  gap: 6px;
}

.runtime-item {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--subtext0);
  font-size: 12px;
}

.runtime-item a {
  color: var(--blue);
  text-decoration: none;
}

.runtime-item a:hover {
  text-decoration: underline;
}

.command-item code {
  color: var(--subtext1);
  font-family: var(--mono);
  font-size: 11px;
}

/* ── Allgemein-Ansicht ──────────────────────────────────────────────────── */
.general-section {
  margin-top: 20px;
}

.platform-overview {
  display: grid;
  gap: 10px;
}

.platform-card {
  min-width: 0;
  background: var(--base);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
  overflow: hidden;
}

.overview-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(110px, .6fr) minmax(150px, 1fr) minmax(150px, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 8px 12px;
}

.platform-row {
  grid-template-columns: minmax(180px, 1.2fr) minmax(110px, .6fr) minmax(260px, 2fr);
  background: var(--surface0);
}

.machine-row,
.application-row {
  border-top: 1px solid rgba(122, 135, 147, .14);
  padding-left: 28px;
}

.application-row {
  background: rgba(79, 209, 197, .035);
}

.overview-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--subtext1);
  font-weight: 600;
}

.platform-name {
  color: var(--text);
}

.platform-url,
.overview-actions {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-url a {
  color: var(--blue);
  text-decoration: none;
}

.platform-url a:hover {
  text-decoration: underline;
}

.copy-link {
  max-width: 100%;
  padding: 3px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  color: var(--blue);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.copy-link:hover,
.copy-link.copied {
  background: var(--surface0);
  border-color: var(--blue);
}

.copy-missing {
  color: var(--overlay0);
  font-size: 12px;
}

/* ── Terminal ────────────────────────────────────────────────────────────── */
#terminal {
  height: var(--term-h);
  background: var(--base);
  border-top: 1px solid var(--surface0);
  display: flex;
  flex-direction: column;
  transition: height .2s ease;
  flex-shrink: 0;
}
#terminal.collapsed { height: 40px; }

#term-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  min-height: 40px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--surface0);
}
.term-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.term-title {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--overlay0);
}
.term-path {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--subtext0);
  font-family: var(--mono);
  font-size: 11px;
}
.term-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

#run-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--overlay0);
  transition: background .2s;
}
#run-indicator.running { background: var(--yellow); animation: pulse 1s ease-in-out infinite; }
#run-indicator.ok      { background: var(--green); }
#run-indicator.error   { background: var(--red); }

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.3; } }

#output {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-all;
}

.out-info    { color: var(--teal); }
.out-success { color: var(--green); }
.out-warning { color: var(--yellow); }
.out-error   { color: var(--red); }
.out-default { color: var(--subtext1); }

/* ── Schaltflächen ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}

.btn-primary { background: var(--blue); color: var(--mantle); }
.btn-primary:hover { background: var(--blue-dim); }

.btn-ghost {
  background: transparent;
  color: var(--subtext0);
  border-color: var(--surface1);
}
.btn-ghost:hover { background: var(--surface0); color: var(--text); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  color: var(--subtext0);
  font-size: 14px;
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}
.icon-btn:hover { background: var(--surface0); color: var(--text); }

.sm-btn {
  padding: 3px 8px;
  background: transparent;
  border: 1px solid var(--surface0);
  border-radius: 4px;
  color: var(--subtext0);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: all .12s;
}
.sm-btn:hover { background: var(--surface0); }

select {
  padding: 6px 10px;
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  min-width: 100px;
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--base);
  border: 1px solid var(--surface0);
  border-radius: var(--radius);
  width: min(460px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--surface0);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 20px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--subtext1);
}
.field input,
.field select {
  padding: 8px 10px;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  transition: border-color .12s;
}
.field input:focus,
.field select:focus { outline: none; border-color: var(--blue); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--surface0);
}

/* ── Hilfklassen ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface0); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface1); }

/* ── Responsiv ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar {
    position: fixed;
    height: 100%;
    z-index: 50;
    transform: translateX(0);
    transition: transform .2s ease, width .2s ease;
  }
  #sidebar.mobile-hidden { transform: translateX(-100%); }

  .action-grid { grid-template-columns: repeat(3, 1fr); }
  .path-line { max-width: 100%; }
  .detail-header { flex-direction: column; gap: 12px; }
  .detail-controls { width: 100%; justify-content: flex-start; }
  .view-switch { width: 100%; }
  .view-tab { flex: 1; min-width: 0; }
  .summary-strip { grid-template-columns: 1fr; }
  .run-options { align-items: stretch; flex-direction: column; }
  .inline-field { align-items: stretch; flex-direction: column; }
  .inline-field input { width: 100%; }
  .container-row { grid-template-columns: 1fr; }
  .container-actions { justify-content: flex-start; }
  .runtime-grid { grid-template-columns: 1fr; }
  .overview-row,
  .platform-row {
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: stretch;
  }
  .machine-row,
  .application-row {
    padding-left: 12px;
  }
  .overview-actions,
  .platform-url {
    white-space: normal;
  }
  .copy-link {
    width: 100%;
    text-align: left;
  }
  :root { --term-h: 220px; }

  #main { padding: 16px; }
}

@media (min-width: 641px) {
  #btn-collapse { display: inline-flex; }
}

/* ── hosting.json Editor ─────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 6px 0;
  border-top: 1px solid var(--surface0);
  margin-top: 24px;
  user-select: none;
}
.section-header:hover .section-title { color: var(--blue); }
.section-header .section-title { margin-bottom: 0; }
.section-toggle {
  font-size: 10px;
  color: var(--overlay0);
  transition: transform .2s;
}
.section-toggle.open { transform: rotate(90deg); }

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 6px;
}

.btn-save-hosting {
  background: var(--surface0);
  color: var(--green);
  border-color: var(--green);
}
.btn-save-hosting:hover { background: rgba(166,227,161,.12); }

.editor-status {
  font-size: 11px;
  color: var(--overlay0);
  flex: 1;
}
.editor-status.saved  { color: var(--green); }
.editor-status.error  { color: var(--red); }
.editor-status.dirty  { color: var(--yellow); }

.json-editor {
  display: block;
  width: 100%;
  min-height: 280px;
  max-height: 500px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--mantle);
  color: var(--text);
  border: 1px solid var(--surface0);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  resize: vertical;
  tab-size: 2;
  transition: border-color .12s;
}
.json-editor:focus { outline: none; border-color: var(--blue); }
.json-editor.invalid { border-color: var(--red); }
