/* CASlink2 - same look as CASlink, one script window instead of the port tabs.
   Sections marked CASlink2 are new; the rest is CASlink's style.css. */

/* === Base Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f23;
    --surface: #1a1a2e;
    --surface-alt: #16162b;
    --border: #333;
    --border-light: #444;
    --text: #ccc;
    --text-muted: #888;
    --primary: #2563eb;
    --primary-hover: #3b7bf7;
    --success: #1c7644;
    --success-light: limegreen;
    --danger: #dc2626;
    --warning: #d97706;
    --disabled-bg: #1c1c34;
    --disabled-text: #555;
    --accent: #0ea5e9;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --input-bg: #0a0a1a;
    --input-border: #444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
}

#app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px;
}

/* === Header === */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #1a1a2e;
    color: white;
    border-radius: var(--radius);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}
.header h1 { font-size: 20px; font-weight: 700; }
.header .version { font-size: 11px; opacity: 0.8; margin-left: 8px; }
.connection-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 12px;
    background: var(--danger);
}
.connection-badge.online { background: var(--success); }

/* === Top Bar === */
.top-bar {
    display: grid;
    grid-template-columns: 200px 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

fieldset.group {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    margin: 0;
    background: var(--surface);
    min-width: 0;
    overflow: hidden;
}
fieldset.group legend {
    display: none;
}
fieldset.group::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 11px;
    color: var(--accent);
    padding: 6px 12px 4px;
    border-bottom: 1px solid var(--border);
}
fieldset.group > *:not(legend) {
    margin: 0;
    padding-left: 12px;
    padding-right: 12px;
}
fieldset.group > *:not(legend):first-of-type {
    padding-top: 8px;
}
fieldset.group > *:not(legend):last-child {
    padding-bottom: 8px;
}

/* Port Settings */
.port-settings .form-row { margin-bottom: 6px; }
.port-settings label { font-size: 12px; display: block; margin-bottom: 2px; }
.port-name { font-size: 11px; color: var(--text-muted); display: block; margin: 4px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Device Info */
.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 8px;
    align-items: center;
}
.info-grid label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.info-grid input { font-size: 11px; padding: 2px 4px; border: 1px solid var(--input-border); border-radius: 3px; background: var(--input-bg); color: var(--text); }

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 8px;
    align-items: center;
}
.settings-grid label { font-size: 12px; white-space: nowrap; }
.settings-grid select, .settings-grid input[type="text"] {
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: var(--input-bg);
    color: var(--text);
}
.checkbox-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 4px; }
.checkbox-row input { margin: 0; }
.checkbox-row label { font-size: 12px; }

/* === Buttons === */
.btn {
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    color: #fff;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 11px; color: #000; background: #aaa; }
.btn-sm:hover { background: #ccc; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); }
.btn-success:hover:not(:disabled) { background: #25a35a; }
.btn-danger { background: var(--danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.2); }
.btn-warning { background: var(--warning); }
.btn-warning:hover:not(:disabled) { filter: brightness(1.2); }
.btn-row { display: flex; gap: 6px; grid-column: 1 / -1; align-items: center; }
.password-label {
    font-size: 12px;
    margin-left: auto;
    white-space: nowrap;
}
.password-input {
    flex: 0 1 140px;
    min-width: 0;
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: var(--input-bg);
    color: var(--text);
}

/* === Action Bar === */
.action-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    flex-wrap: wrap;
}
.action-bar .script-budget { margin-left: auto; }

/* === Status Bar === */
.status-bar {
    display: flex;
    gap: 16px;
    padding: 6px 12px;
    background: var(--surface);
    color: var(--text-muted);
    border-radius: var(--radius);
    font-size: 11px;
    margin-top: 8px;
    border: 1px solid var(--border);
}
.status-bar-link {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    margin-left: auto;
}
.status-bar-link:hover { text-decoration: underline; }
.status-bar-link::before { display: none; }
.status-bar .copyright {
    color: #fff;
    font-weight: 600;
    margin-right: auto;
    padding-left: 4px;
}
.status-bar .copyright::before { display: none; }
/* Variante mit nur einem Element in der Mitte statt Link + Copyright: die beiden auto-Margins
   saugen den freien Platz links und rechts auf und zentrieren es zwischen den Nachbarn. */
.status-bar .powered { margin-left: auto; margin-right: auto; }
.status-bar span::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #475569;
    margin-right: 6px;
    vertical-align: middle;
}
.status-bar-download {
    margin-left: auto;
    padding: 2px 10px;
    font-size: 11px;
    line-height: 1.4;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    color: white;
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.hidden { opacity: 0; transform: translateY(20px); pointer-events: none; }

/* Firmware version mismatch warning */
.fw-warning {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid var(--warning);
    border-left: 4px solid var(--warning);
    border-radius: var(--radius);
    background: rgba(217, 119, 6, 0.12);
    color: var(--text);
    font-size: 12px;
    line-height: 1.4;
}
.fw-warning-icon { color: var(--warning); font-size: 15px; line-height: 1.2; }
.fw-warning a { color: var(--accent); font-weight: 600; }

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    min-width: 320px;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}
.modal-content h3 {
    margin-bottom: 8px;
    color: var(--accent);
    font-size: 14px;
}
.modal-content p {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.modal-content input {
    width: 100%;
    font-size: 13px;
    padding: 6px 8px;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: var(--input-bg);
    color: var(--text);
    margin-bottom: 12px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--primary); }

/* === Responsive === */
@media (max-width: 1100px) {
    .top-bar { grid-template-columns: 1fr 1fr; }
    .port-row { grid-template-columns: 1fr; }
    .sleep-panel { max-width: 100%; }
}
@media (max-width: 700px) {
    .top-bar { grid-template-columns: 1fr; }
}


.script-body { display: flex; flex-direction: column; gap: 8px; }

.script-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}
.script-hint { font-size: 11px; color: var(--text-muted); }
.script-budget { display: flex; gap: 5px; flex-wrap: wrap; }

.budget-chip {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text-muted);
    white-space: nowrap;
}
.budget-chip.near { color: var(--warning); border-color: var(--warning); }
.budget-chip.over { color: #fff; background: var(--danger); border-color: var(--danger); }

/* Weisse Eingabeflaeche, bewusst abgesetzt vom dunklen Rest */
.script-edit-wrap {
    display: flex;
    background: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 190px;
}
.script-gutter {
    flex: 0 0 auto;
    padding: 10px 8px 10px 10px;
    margin: 0;
    background: #f1f3f5;
    border-right: 1px solid #dde1e5;
    color: #98a2ad;
    text-align: right;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    overflow: hidden;
    user-select: none;
    min-width: 32px;
}
.script-input {
    flex: 1 1 auto;
    padding: 10px 12px;
    border: 0;
    outline: none;
    resize: vertical;
    background: #ffffff;
    color: #1a1a2e;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    tab-size: 4;
    min-height: 190px;
    white-space: pre;
    overflow: auto;
}
.script-input::placeholder { color: #b6bec7; }

.script-msg {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 11.5px;
    line-height: 1.5;
    padding: 7px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text-muted);
}
.script-msg.script-ok   { color: var(--success-light); border-color: var(--success); }
.script-msg.script-warn { color: var(--warning); border-color: var(--warning); }
.script-msg.script-err  { color: #ff9a92; border-color: var(--danger); }
/* === Deployment lock === */
/* A configuration opened with the installer password stays fully loaded - the device has
   to receive exactly what the file says - but none of it is rendered. The inputs keep
   their values, they are simply not shown. This locks the user interface, not the data:
   it stops the person operating the tool, not someone who opens the developer tools. */
body.deploy-locked .group.settings,
body.deploy-locked .script-panel,
body.deploy-locked #scriptBudget,
body.deploy-locked #btnReset { display: none; }

.deploy-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--warning);
    border-left: 4px solid var(--warning);
    border-radius: var(--radius);
}
.deploy-banner.hidden { display: none; }
.deploy-banner-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.deploy-banner-text strong { color: var(--text); }
#deployBannerLabel { color: var(--text-muted); overflow-wrap: anywhere; }
.deploy-banner button { margin-left: auto; flex-shrink: 0; }


/* === CASlink2: header === */
.header-left { display: flex; align-items: baseline; gap: 4px; }
.header-device { font-size: 12px; color: var(--text-muted); margin-left: 10px; }

/* === CASlink2: the script window === */
.script-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.script-panel-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--primary);
    flex-wrap: wrap;
}
.script-title { font-weight: 700; font-size: 14px; color: var(--accent); }
.script-summary { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; color: var(--text-muted); }
.script-tools { margin-left: auto; }
.script-tools select, .live-row select, .live-row input[type="text"] {
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: var(--input-bg);
    color: var(--text);
}
.script-hint code { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text); }
.script-panel .script-edit-wrap { min-height: 440px; }
.script-panel .script-input { min-height: 440px; }
.script-gutter .err-line { color: #fff; background: var(--danger); border-radius: 2px; }

/* === CASlink2: live view === */
.live-panel {
    margin-top: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.live-panel summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    cursor: pointer;
    list-style: none;
    flex-wrap: wrap;
}
.live-panel summary::-webkit-details-marker { display: none; }
.live-panel summary::before { content: '\25B8'; color: var(--text-muted); font-size: 11px; }
.live-panel[open] summary::before { content: '\25BE'; }
.live-title { font-weight: 700; font-size: 12px; color: var(--accent); }
.live-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text-muted);
    white-space: nowrap;
}
.chip.on   { color: #fff; background: var(--success); border-color: var(--success); }
.chip.warn { color: #fff; background: var(--warning); border-color: var(--warning); }
.chip.bad  { color: #fff; background: var(--danger); border-color: var(--danger); }
.live-body { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }
.live-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 6px; }
.live-label, .trace-toggle { font-size: 12px; }
.trace-toggle { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.trace-count { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
#testId { width: 9ch; text-transform: uppercase; }
#testData { width: 24ch; text-transform: uppercase; }
#traceFilter { width: 26ch; }
.trace-wrap {
    max-height: 260px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
}
.trace { width: 100%; border-collapse: collapse; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; }
.trace th {
    position: sticky; top: 0;
    background: var(--surface-alt);
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}
.trace td { padding: 2px 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.trace th:not(:last-child), .trace td:not(:last-child) { width: 1%; padding-right: 22px; }
.trace tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
.trace td.bus2 { color: var(--accent); }

/* Status bar entries in CASlink2 */
#statusRates { font-family: ui-monospace, Menlo, Consolas, monospace; }
