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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Left Panel - Resizable */
.left-panel {
    flex: 0 0 320px;
    min-width: 0;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    transition: flex-basis 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
    overflow: hidden;
}

.left-panel.collapsed {
    flex-basis: 0 !important;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}

.left-panel.resizing {
    transition: none;
}

/* Resize Handle */
.resize-handle {
    width: 8px;
    background-color: #e0e0e0;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.resize-handle:hover {
    background-color: #d0d0d0;
}

.resize-handle.dragging {
    background-color: #4CAF50;
}

.panel-toggle {
    position: absolute;
    width: 24px;
    height: 48px;
    background-color: #4CAF50;
    border: none;
    border-radius: 0 4px 4px 0;
    color: white;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    left: 0;
    transition: background-color 0.2s, transform 0.2s;
    z-index: 10;
}

.panel-toggle:hover {
    background-color: #45a049;
}

.left-panel.collapsed ~ .resize-handle .panel-toggle {
    transform: scaleX(-1);
}

.left-panel h1 {
    font-size: 24px;
    color: #333;
    padding: 20px 20px 10px 20px;
    margin: 0;
    text-align: center;
    flex-shrink: 0;
}

/* Sidebar Main Area - Holds tab navigation and content */
.sidebar-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Tab Navigation */
.tab-navigation {
    display: flex;
    background-color: #f5f5f5;
    border-bottom: 2px solid #e0e0e0;
    flex-shrink: 0;
}

.tab-button {
    flex: 1;
    padding: 16px 20px;
    background-color: #e8e8e8;
    border: none;
    border-bottom: 4px solid transparent;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    color: #666;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-button:hover {
    background-color: #d8d8d8;
    color: #333;
}

.tab-button.active {
    background-color: #ffffff;
    color: #4CAF50;
    border-bottom-color: #4CAF50;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Tab Content Container */
.tab-content-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding: 20px;
    background-color: #fafafa;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.program-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin-bottom: 0;
    border-bottom: none;
}

.program-section .section-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Bottom Actions Bar */
.bottom-actions-bar {
    padding: 15px 20px;
    background-color: #f5f5f5;
    border-top: 2px solid #e0e0e0;
    flex-shrink: 0;
}

.bottom-actions-bar .form-group {
    margin-bottom: 10px;
}

.bottom-actions-bar .button-group {
    margin-top: 10px;
}

.section {
    margin-bottom: 20px;
    padding: 16px;
    background-color: #ffffff;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.section:last-child {
    margin-bottom: 0;
}

.section h2 {
    font-size: 15px;
    color: #333;
    margin-bottom: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 13px;
}

.section-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin: -16px -16px 12px -16px;
    background-color: #f8f8f8;
    border-bottom: 2px solid #e8e8e8;
    transition: background-color 0.2s;
}

.section-header:hover {
    background-color: #efefef;
}

.collapse-icon {
    font-size: 18px;
    font-weight: bold;
    color: #888;
    transition: transform 0.3s ease;
}

.section.collapsed .collapse-icon {
    transform: rotate(90deg);
}

.section-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 5000px;
    opacity: 1;
}

.section.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
}

/* Collapsed sections are header-only: drop the padding/margin that would
   otherwise leave an empty strip below the header. */
.section.collapsed {
    padding-bottom: 0;
}

.section.collapsed .section-header {
    margin-bottom: 0;
    border-bottom: none;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    color: #666;
    margin-bottom: 4px;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="url"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #4CAF50;
}

.form-group textarea {
    resize: vertical;
}

/* Calibration helper / error text */
.field-hint {
    display: block;
    font-size: 11px;
    color: #888;
    margin-top: 3px;
}

.field-error {
    display: block;
    font-size: 11px;
    color: #d32f2f;
    margin-top: 3px;
}

.field-error:empty {
    display: none;
}

.form-group input.invalid {
    border-color: #d32f2f;
}

.section-intro {
    font-size: 12px;
    color: #666;
    margin: 0 0 12px;
}

/* Nested "How to Calibrate" help section */
.calibration-help {
    margin-top: 8px;
}

.calibration-help .section-content {
    font-size: 12px;
    color: #555;
}

.calibration-help ol {
    margin: 4px 0 10px;
    padding-left: 18px;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn.icon-btn .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn.icon-btn .icon * {
    stroke: inherit;
}

.btn-primary {
    background-color: #4CAF50;
    color: white;
}

.btn-primary:hover {
    background-color: #45a049;
    border-color: #45a049;
}

.btn-primary .icon {
    stroke: white !important;
}

.btn-success {
    background-color: #4CAF50 !important;
    color: white !important;
}

.btn-success:hover {
    background-color: #45a049 !important;
}

.btn-success .icon,
.btn-success .icon * {
    stroke: white !important;
}

.btn-secondary {
    background-color: #2196F3;
    color: white;
}

.btn-secondary:hover {
    background-color: #0b7dda;
    border-color: #0b7dda;
}

.btn-secondary .icon {
    stroke: white !important;
}

.btn-neutral {
    background-color: #9E9E9E !important;
    color: white !important;
}

.btn-neutral:hover {
    background-color: #757575 !important;
}

.btn-neutral .icon,
.btn-neutral .icon * {
    stroke: white !important;
}

.btn-danger {
    background-color: #f44336;
    color: white;
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger:hover {
    background-color: #da190b;
}

/* Program Blocks */
.program-blocks {
    flex: 1;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 10px;
    background-color: #fafafa;
    margin-bottom: 10px;
}

.program-block {
    background-color: white;
    border: 2px solid #ddd;
    border-radius: 6px;
    padding: 10px 10px 10px 22px; /* extra left padding for wider drag rail */
    margin-bottom: 8px;
    position: relative;
}

.program-block.text-block {
    border-color: #9E9E9E;
    background-color: #fafafa; /* subtle neutral background */
}

.program-block.move-block {
    border-color: #4CAF50;
    background-color: #f7fbf7; /* subtle green-tinted background */
}

.program-block.invalid {
    border-color: #f44336;
    background-color: #ffebee;
}

/* Vertical drag rail on the left side of each block */
.drag-rail {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 16px;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    cursor: grab;
    background: repeating-linear-gradient(
        to right,
        #d0d0d0,
        #d0d0d0 4px,
        #e8e8e8 4px,
        #e8e8e8 8px
    );
}

/* Green-themed drag rail for move blocks */
.program-block.move-block .drag-rail {
    background: repeating-linear-gradient(
        to right,
        #A5D6A7,
        #A5D6A7 4px,
        #C8E6C9 4px,
        #C8E6C9 8px
    );
}

/* Match grabbing cursor while dragging */
.program-block.dragging .drag-rail {
    cursor: grabbing;
}

.program-block.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.block-placeholder {
    background-color: #e3f2fd;
    border: 2px dashed #2196F3;
    border-radius: 6px;
    margin-bottom: 8px;
}

.block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.block-type {
    font-weight: 600;
    font-size: 12px;
    color: #666;
}

.block-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.block-content input,
.block-content textarea {
    width: 100%;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
}

.block-content textarea {
    resize: vertical;
    min-height: 40px;
}

.block-position-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #666;
    margin-top: 4px;
}

.block-position-toggle input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.block-position-info {
    font-size: 10px;
    color: #4CAF50;
    margin-top: 4px;
    padding: 4px 6px;
    background-color: #f1f8f4;
    border-radius: 3px;
    border-left: 2px solid #4CAF50;
}

.block-move-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.block-move-inputs label {
    font-size: 11px;
    color: #666;
    margin-bottom: 2px;
    display: block;
}

/* Right Panel - Flexible */
.right-panel {
    flex: 1;
    min-width: 0;
    background-color: #e8e8e8;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.canvas-description {
    flex-shrink: 0;
    margin-bottom: 15px;
}

.plan-details-row {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.plan-details-row .icon-btn {
    margin-left: auto;
}

.canvas-description .form-group label {
    display: block;
    font-size: 13px;
    color: #666;
    margin-bottom: 6px;
    font-weight: 500;
}

.canvas-description textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
}

.canvas-description textarea:focus {
    outline: none;
    border-color: #4CAF50;
}

/* Plan Controls Bar */
.plan-controls-bar {
    background-color: #ffffff;
    padding: 12px 15px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.plan-date-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.plan-date-group label {
    font-size: 13px;
    color: #666;
    font-weight: 500;
    white-space: nowrap;
}

.plan-date-group input[type="date"] {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}

.plan-date-group input[type="date"]:focus {
    outline: none;
    border-color: #4CAF50;
}

.print-config-group {
    display: flex;
    align-items: center;
}

.print-config-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
}

.print-config-group input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.checkbox-label {
    white-space: nowrap;
}

.plan-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* Icon Buttons */
.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #fff;
    color: #666;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.icon-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.icon-btn:disabled:hover {
    background-color: #fff;
    border-color: #ddd;
    color: #666;
}

.icon-btn:hover {
    background-color: #f5f5f5;
    border-color: #4CAF50;
    color: #4CAF50;
}

.icon-btn .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.icon-btn .btn-text {
    display: inline;
}

/* Hide text on smaller screens when it would wrap */
@media (max-width: 1400px) {
    .plan-controls-bar {
        gap: 10px;
    }
    
    .icon-btn {
        padding: 8px;
    }
    
    .icon-btn .btn-text {
        display: none;
    }
}

/* Even smaller screens - stack controls vertically */
@media (max-width: 1200px) {
    .plan-controls-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .plan-actions {
        margin-left: 0;
        justify-content: flex-start;
    }
    
    .checkbox-label {
        white-space: normal;
    }
}

/* Show text again on larger screens */
@media (min-width: 1600px) {
    .icon-btn .btn-text {
        display: inline;
    }
}

#missionCanvas {
    background-color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: block;
    margin: auto;
    flex-shrink: 0;
}

/* Print Styles */
@media print {
    body {
        background-color: white;
    }

    .container {
        display: none;
    }

    #printTemplate {
        display: block !important;
    }

    .print-content {
        padding: 20px;
    }

    .print-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
        page-break-after: avoid;
        gap: 20px;
    }

    .print-header h1 {
        font-size: 28px;
        margin: 0;
        flex: 1;
        text-align: center;
    }

    .print-header .print-logo {
        max-height: 60px;
        max-width: 150px;
        object-fit: contain;
    }

    .print-header .print-date {
        font-size: 14px;
        color: #666;
        font-style: italic;
        margin: 0;
        text-align: right;
        white-space: nowrap;
    }

    .print-description {
        margin-bottom: 20px;
        padding: 10px;
        background-color: #f9f9f9;
        border-left: 3px solid #4CAF50;
    }

    .print-canvas-container {
        text-align: center;
        margin: 20px 0;
        page-break-inside: avoid;
    }

    #printCanvas {
        max-width: 100%;
        border: 1px solid #ddd;
    }

    .print-watermark {
        margin-top: 20px;
        margin-bottom: 20px;
        padding-top: 15px;
        text-align: center;
        font-size: 12px;
        color: #999;
        border-top: 1px solid #e0e0e0;
        font-style: italic;
    }

    .print-program {
        page-break-before: always;
        padding-top: 20px;
    }

    .print-program h2 {
        font-size: 20px;
        margin-bottom: 15px;
        border-bottom: 2px solid #333;
        padding-bottom: 5px;
    }

    .print-config {
        page-break-before: always;
        padding-top: 20px;
    }

    .print-config h2 {
        font-size: 18px;
        margin-bottom: 10px;
    }

    .print-config table {
        width: 100%;
        border-collapse: collapse;
    }

    .print-config td {
        padding: 5px;
        border: 1px solid #ddd;
    }

    .print-config td:first-child {
        font-weight: 600;
        background-color: #f5f5f5;
        width: 40%;
    }
}

/* Scrollbar Styling */
.tab-content::-webkit-scrollbar,
.program-blocks::-webkit-scrollbar {
    width: 8px;
}

.tab-content::-webkit-scrollbar-track,
.program-blocks::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tab-content::-webkit-scrollbar-thumb,
.program-blocks::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.tab-content::-webkit-scrollbar-thumb:hover,
.program-blocks::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ========== Storage Management Styles ========== */

/* Input with button layout */
.input-with-button {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-button select {
    flex: 1;
    min-width: 0;
}

.input-with-button .btn-small {
    white-space: nowrap;
}

/* Saved programs group in plan controls */
.saved-programs-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.saved-programs-group select {
    max-width: 180px;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    background: white;
}

/* Small button variant */
.btn-small {
    padding: 6px 10px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    transition: background-color 0.2s;
}

.btn-small:hover {
    background-color: #45a049;
}

.btn-small .icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Storage section */
.storage-section .section-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Storage usage bar */
.storage-usage {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.storage-usage label {
    font-weight: 500;
    font-size: 13px;
    color: #555;
}

.storage-usage-container {
    width: 100%;
    height: 12px;
    background-color: #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
}

.storage-usage-bar {
    height: 100%;
    background-color: #4CAF50;
    border-radius: 6px;
    transition: width 0.3s ease, background-color 0.3s ease;
    width: 0;
}

.storage-usage-bar.storage-warning {
    background-color: #ff9800;
}

.storage-usage-bar.storage-critical {
    background-color: #f44336;
}

.storage-usage-text {
    font-size: 12px;
    color: #666;
}

/* Saved items sections */
.saved-items-section {
    border-top: 1px solid #e0e0e0;
    padding-top: 12px;
}

.saved-items-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 8px;
}

.saved-items-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 150px;
    overflow-y: auto;
}

.saved-items-list .empty-list {
    font-size: 12px;
    color: #999;
    font-style: italic;
    padding: 8px 0;
}

.saved-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background-color: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
}

.saved-item-name {
    flex: 1;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.saved-item-date {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
}

.saved-item .btn-icon {
    padding: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #999;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.saved-item .btn-icon:hover {
    color: #f44336;
}

/* Clear all button */
#clearStorageBtn {
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#clearStorageBtn .icon {
    width: 14px;
    height: 14px;
}

/* Transient success toast */
#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #4caf50;
    color: #fff;
    padding: 10px 20px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

#toast.show {
    opacity: 1;
}
