* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f1923;
    color: #e0e0e0;
    min-height: 100vh;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.settings-btn,
.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #607d8b;
    text-decoration: none;
    padding: 6px;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
}

.settings-btn {
    margin-left: auto;
}

.settings-btn:hover,
.back-btn:hover {
    color: #90a4ae;
    background: #1a2733;
}

header h1 {
    font-size: 1.5rem;
    color: #fff;
}

.badge {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.sensor-ok {
    background: #4caf5020;
    color: #4caf50;
    border: 1px solid #4caf5040;
}

.badge.no-sensor {
    background: #ff980020;
    color: #ff9800;
    border: 1px solid #ff980040;
}

.status-panel {
    margin-bottom: 24px;
}

.status-card {
    background: #1a2733;
    border: 1px solid #2a3a4a;
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.3s;
}

.status-card.state-OFF    { border-color: #455a64; }
.status-card.state-FIRING { border-color: #f44336; }

.status-indicator {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 24px;
}

.status-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #455a64;
    transition: background 0.3s, box-shadow 0.3s;
}

.state-OFF .status-icon {
    background: #455a64;
    box-shadow: 0 0 20px #455a6440;
}

.state-FIRING .status-icon {
    background: #f44336;
    box-shadow: 0 0 20px #f4433660;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.status-text h2 {
    font-size: 1.8rem;
    margin-bottom: 4px;
}

.status-text p {
    color: #90a4ae;
    font-size: 0.95rem;
}

.timestamp {
    font-size: 0.8rem !important;
    margin-top: 4px;
}

.sysinfo {
    font-size: 0.72rem;
    color: #78909c;
    margin-top: 6px;
    letter-spacing: 0.02em;
}

.panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 700px) {
    .panels {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: #1a2733;
    border: 1px solid #2a3a4a;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.panel-burn-history {
    padding: 12px 12px 8px;
}

.panel-burn-history canvas {
    display: block;
    width: 100%;
    border-radius: 6px;
}

.panel h3 {
    font-size: 1rem;
    color: #90a4ae;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel h3 select {
    font-size: 0.8rem;
    background: #0f1923;
    color: #e0e0e0;
    border: 1px solid #2a3a4a;
    border-radius: 6px;
    padding: 4px 8px;
    margin-left: auto;
}

.threshold-diagram {
    margin-bottom: 20px;
}

.threshold-bar {
    display: flex;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 6px;
}

.zone {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.zone-off {
    flex: 1;
    background: #455a6440;
    color: #90a4ae;
}

.zone-firing {
    flex: 3;
    background: #f4433630;
    color: #f44336;
}

.threshold-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #607d8b;
    padding: 0 4px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: #90a4ae;
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    background: #0f1923;
    border: 1px solid #2a3a4a;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #42a5f5;
}

.form-group small {
    display: block;
    font-size: 0.75rem;
    color: #607d8b;
    margin-top: 2px;
}

.advanced-settings {
    margin: 16px 0;
    border: 1px solid #2a3a4a;
    border-radius: 6px;
    padding: 12px;
}

.advanced-settings summary {
    cursor: pointer;
    color: #42a5f5;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.btn {
    width: 100%;
    padding: 10px;
    background: #42a5f5;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover {
    background: #1e88e5;
}

.btn-danger {
    background: #c0392b;
}

.btn-danger:hover {
    background: #96281b;
}

.btn-danger:disabled {
    background: #5a1a14;
    cursor: not-allowed;
}

.btn-warning {
    background: #d68910;
}

.btn-warning:hover {
    background: #b7770d;
}

.btn-warning:disabled {
    background: #6e4a08;
    cursor: not-allowed;
}

.btn-secondary {
    background: #546e7a;
    text-decoration: none;
    display: inline-block;
}

.btn-secondary:hover {
    background: #37474f;
}

.system-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pi-buttons-row {
    display: flex;
    gap: 12px;
}

.pi-buttons-row > div {
    flex: 1;
}

.data-button-row > div {
    width: 100%;
}

.data-button-row .btn {
    width: 100%;
}

.panel-divider {
    border: none;
    border-top: 1px solid #1e2a38;
    margin: 20px 0;
}

.shutdown-section h4 {
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    color: #cdd6f4;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-card {
    background: #0f1923;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.stat-card.wide {
    grid-column: 1 / -1;
}

.stat-label {
    font-size: 0.75rem;
    color: #607d8b;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
}

.firing-value {
    color: #ff7043;
}

.distribution-bar {
    display: flex;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
}

.distribution-legend {
    display: flex;
    gap: 12px;
    justify-content: center;
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    text-align: left;
    padding: 8px 12px;
    color: #607d8b;
    border-bottom: 1px solid #2a3a4a;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid #1a2733;
}

.state-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.state-badge.OFF {
    background: #455a6430;
    color: #90a4ae;
}

.state-badge.FIRING {
    background: #f4433620;
    color: #f44336;
}

.chart-subtitle {
    margin: 4px 0 8px;
    font-size: 0.8rem;
    color: #607d8b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bar-tooltip {
    display: none;
    position: absolute;
    background: #1a2733;
    border: 1px solid #2a3a4a;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
    color: #cfd8dc;
    pointer-events: none;
    z-index: 200;
    white-space: nowrap;
    line-height: 1.6;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

canvas {
    width: 100% !important;
    background: #0f1923;
    border-radius: 8px;
}

.deploy-panel {
    border-color: #37474f;
}

.required {
    color: #ef5350;
    margin-left: 2px;
}

.error-hint {
    color: #ef5350 !important;
    display: block;
    margin-top: 4px;
}

.script-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.script-tab {
    flex: 1;
    padding: 9px 12px;
    background: #0f1923;
    border: 1px solid #2a3a4a;
    border-radius: 6px;
    color: #607d8b;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.script-tab:hover {
    border-color: #42a5f5;
    color: #42a5f5;
}

.script-tab.active {
    background: #42a5f520;
    border-color: #42a5f5;
    color: #42a5f5;
}

.deploy-info {
    font-size: 0.85rem;
    color: #607d8b;
    margin-bottom: 16px;
    line-height: 1.5;
}

.deploy-info code {
    background: #0f1923;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.82rem;
    color: #42a5f5;
}

.deploy-form {
    margin-bottom: 16px;
}

.deploy-btn {
    background: #546e7a;
}

.deploy-btn:hover {
    background: #455a64;
}

.deploy-btn.running {
    background: #37474f;
    cursor: not-allowed;
    opacity: 0.7;
}

.deploy-btn.success {
    background: #388e3c;
}

.deploy-btn.failure {
    background: #c62828;
}

.deploy-output-wrap {
    margin-top: 16px;
    border: 1px solid #2a3a4a;
    border-radius: 8px;
    overflow: hidden;
}

.deploy-output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #0f1923;
    font-size: 0.8rem;
    color: #607d8b;
    border-bottom: 1px solid #2a3a4a;
}

.btn-clear {
    background: none;
    border: 1px solid #2a3a4a;
    color: #607d8b;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.btn-clear:hover {
    border-color: #42a5f5;
    color: #42a5f5;
}

.deploy-output {
    background: #060d14;
    color: #b0bec5;
    font-family: "Courier New", monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    padding: 12px;
    margin: 0;
    max-height: 340px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.deploy-output .line-info  { color: #66bb6a; }
.deploy-output .line-warn  { color: #ffa726; }
.deploy-output .line-error { color: #ef5350; }

.badge-running {
    background: #ff980020;
    color: #ff9800;
    border: 1px solid #ff980040;
}

.badge-success {
    background: #4caf5020;
    color: #4caf50;
    border: 1px solid #4caf5040;
}

.badge-failure {
    background: #f4433620;
    color: #f44336;
    border: 1px solid #f4433640;
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 1000;
    animation: slideIn 0.3s;
}

.toast.success {
    background: #4caf50;
    color: #fff;
}

.toast.error {
    background: #f44336;
    color: #fff;
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
