/* FilaBridge Dashboard - Component Styles */

/* Buttons */
.btn {
    background: #28a745;
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
    text-decoration: none;
    display: inline-block;
    margin: 10px 5px;
    transition: all 0.3s ease;
}

.btn:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.btn-secondary {
    background: #6c757d;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
}

/* Amber action button, used by the low-filament acknowledge control. The hover
   rule repeats the base colour on purpose: .btn:hover would otherwise repaint it
   green, and this button has always kept its colour through the hover lift. */
.btn-warning {
    background: #e0a800;
}

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

.btn-small {
    padding: 5px 12px;
    font-size: 12px;
    min-width: 60px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
    overflow: visible;
}

.form-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    color: #fff;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    font-size: 16px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    transition: border-color 0.3s ease;
}

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

.form-group select option {
    background: #1a1a1a;
    color: #fff;
}

.form-group input[type="password"] {
    border-color: #6f42c1;
}

.form-group small {
    color: #ccc;
    font-size: 0.9em;
    margin-top: 5px;
    display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Configuration Sections */
.config-section {
    background: rgba(255,255,255,0.05);
    padding: 25px;
    margin: 20px 0;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    overflow: visible;
}

.config-section h3 {
    margin: 0 0 20px 0;
    color: #fff;
}

.advanced-settings {
    background: rgba(255,255,255,0.05);
    padding: 20px;
    border-radius: 8px;
    margin-top: 15px;
}

.help-text {
    color: #ccc;
    font-style: italic;
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(255,193,7,0.1);
    border-left: 3px solid #ffc107;
    border-radius: 4px;
}

.timeout-settings {
    display: grid;
    gap: 15px;
}

/* Inline "?" badge that reveals a longer explanation of a setting on hover or
   focus. Focus (not just hover) carries it, so it is reachable by keyboard and
   by tapping on touch screens, where hover never fires. */
.setting-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    font-style: normal;
    cursor: help;
    flex-shrink: 0;
}

.setting-tip:hover,
.setting-tip:focus {
    background: rgba(255,255,255,0.3);
    outline: none;
}

.setting-tip .setting-tip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: min(380px, 85vw);
    padding: 10px 12px;
    border-radius: 6px;
    background: #2c3e50;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    color: #f1f1f1;
    font-size: 13px;
    font-weight: normal;
    line-height: 1.5;
    text-align: left;
    white-space: normal;
    z-index: 10;
    transition: opacity 0.15s;
}

.setting-tip:hover .setting-tip-text,
.setting-tip:focus .setting-tip-text {
    visibility: visible;
    opacity: 1;
}

.setting-tip .setting-tip-text strong {
    color: #fff;
}

/* Alert banners - Spoolman connection trouble, low-filament warnings, print
   errors. The same markup is produced server-side (status.html) and rebuilt live
   over the websocket, so both paths must use these classes rather than their own
   inline colours. */
.alert {
    padding: 20px;
    margin: 20px 0;
    border-radius: 8px;
    border: 1px solid transparent;
}

.alert-warning {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

.alert-danger {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

/* Links inside a warning banner inherit the banner's dark amber rather than the
   page link colour, which would vanish against the light background. */
.alert-link {
    color: #856404;
    text-decoration: underline;
    font-weight: bold;
}

/* The toolhead picker on a mapping warning, where a single-filament print says
   which slot it is really running from. It sits inside the amber banner rather
   than in a form, so it carries its own light colours instead of the dark
   .form-group treatment, which would be unreadable there. */
.mapping-warning-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.mapping-slot-select {
    flex: 1 1 320px;
    min-width: 0;
    padding: 10px;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    background: #fff;
    color: #856404;
    font-size: 14px;
}

/* The numbered quick-start box inside the first-run welcome banner. */
.setup-steps {
    background: rgba(255,255,255,0.1);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

/* Compact inputs and panels built inline by settings.html and printers.js, which
   sit outside .form-group and so need their own (denser) treatment. Sizing stays
   with the caller; these carry only the look. */
.inline-input {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #666;
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.inline-panel {
    padding: 15px;
    background: rgba(255,255,255,0.05);
    border-radius: 5px;
}

/* Status Indicators */
.status {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.8em;
}

.status.idle { 
    background: #d4edda; 
    color: #155724; 
}

.status.printing { 
    background: #fff3cd; 
    color: #856404; 
}

.status.offline { 
    background: #f8d7da; 
    color: #721c24; 
}

.status.not_configured { 
    background: #e2e3e5; 
    color: #383d41; 
}

/* Color Swatches */
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid #666;
    flex-shrink: 0;
    background-color: #ccc;
}

/* Toolhead Specific Styles */
.toolhead-mapping-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
    padding: 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 5px;
}

.toolhead-label {
    color: #fff !important;
    min-width: 100px;
    font-weight: bold;
}

/* Let the dropdown shrink below its content width so a long spool name can't
   push the row wider than the card. */
.toolhead-dropdown {
    flex: 1;
    min-width: 0;
}

.edit-spool-btn {
    background: #007bff; /* Fallback color */
    color: white;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.3s ease;
    white-space: nowrap;
    margin-left: 25px;
}

.edit-spool-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    filter: brightness(0.8);
}

.edit-spool-btn.hidden {
    display: none;
}

/* Print History table */
.history-table-wrapper {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

.history-table th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #e0e0e0;
    color: #555;
    white-space: nowrap;
}

.history-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.history-table .history-job {
    white-space: normal;
    word-break: break-word;
    min-width: 150px;
}

.history-table tbody tr:hover {
    background: #f8f8ff;
}

.history-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.9em;
    white-space: nowrap;
}

.history-status-completed {
    background: #e6f6e6;
    color: #2e7d32;
}

.history-status-cancelled {
    background: #fdecea;
    color: #c62828;
}

/* WebSocket connection indicator. websocket.js sets the text and a state class;
   everything visual lives here. */
.ws-status-connected {
    background-color: #28a745;
    color: white;
}

.ws-status-connecting {
    background-color: #ffc107;
    color: black;
}

.ws-status-offline {
    background-color: #dc3545;
    color: white;
}

.ws-status {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    z-index: 1000;
    transition: all 0.3s ease;
}

/* Mobile / narrow viewports */
@media (max-width: 600px) {
    /* Two side-by-side fields don't fit a phone; stack them. */
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    /* Desktop buttons are padded for a mouse; trim so a stack of them doesn't
       dominate the screen, while keeping a comfortable tap target. */
    .btn {
        padding: 12px 20px;
        margin: 8px 4px;
    }

    /* Stack the row: label, then a full-width dropdown, then the edit button
       each on their own line, so a mapped spool's long name can't overflow or
       collide with the ✏️ button. */
    .toolhead-mapping-row {
        flex-wrap: wrap;
        gap: 10px;
    }

    .toolhead-label {
        min-width: 0;
        flex-basis: 100%;
    }

    .toolhead-dropdown {
        flex-basis: 100%;
    }

    .edit-spool-btn {
        margin-left: 0;
    }

    /* Docked top-right, the badge overlaps the centred header title on a
       narrow screen; move it to the bottom corner instead. */
    .ws-status {
        top: auto;
        bottom: 10px;
        padding: 6px 10px;
        font-size: 11px;
    }
}
