:root {
    --bg-main: #1e1e1e;
    --bg-sidebar: #252525;
    --bg-topbar: #2a2a2a;
    --border-color: #333;
    --text-color: #eee;
    --input-bg: #333;
    --brand-primary: #A67B5B;
    /* Dark Egg */
}

body.light-mode {
    --bg-main: #FAFAFA;
    /* Lighter Background */
    --bg-sidebar: #F9F5EB;
    --bg-topbar: #E8E2D2;
    --border-color: #e0e0e0;
    --text-color: #444;
    --input-bg: #fff;
    --brand-primary: #8B5A2B;
    /* Darker Brown */
}

* {
    box-sizing: border-box;
    font-family: system-ui, sans-serif;
}

body {
    margin: 0;
    background: var(--bg-main);
    color: var(--text-color);
}

/* ---------- TOPBAR LAYOUT ---------- */

.topbar {
    height: 64px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 16px;
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-color);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-center {
    display: flex;
    justify-content: center;
}

.topbar-logo {
    height: 50px;
    object-fit: contain;
}

.topbar-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

/* ---------- ICON BUTTONS ---------- */

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

.drop-hint {
    opacity: 0.7;
    font-size: 14px;
}

/* ---------- APP LAYOUT ---------- */

.app {
    display: flex;
    height: calc(100vh - 64px);
    overflow: hidden;
}

/* ---------- SIDEBAR ---------- */

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar section {
    display: block;
}

.sidebar h3 {
    margin: 0 0 10px 0;
    font-size: 13px;
    text-transform: uppercase;
    opacity: 0.7;
}

/* ---------- CONTROLS ---------- */

.btn-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

button,
select,
input {
    width: 100%;
    padding: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
}

button:hover,
select:hover {
    background: #3a3a3a;
}

/* Light Mode specific overrides for inputs */
body.light-mode select,
body.light-mode input,
body.light-mode button {
    background: #fff;
    color: #444;
    border-color: #ccc;
}

body.light-mode select:hover,
body.light-mode input:hover,
body.light-mode button:hover {
    background: #f0f0f0;
}

/* Ensure options are readable */
option {
    background: var(--bg-sidebar);
    color: var(--text-color);
}

body.light-mode option {
    background: #fff;
    color: #333;
}

button i {
    margin-right: 6px;
    font-size: 16px;
    vertical-align: middle;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

/* ---------- INFO ---------- */

.info {
    font-size: 14px;
    opacity: 0.9;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

/* ---------- FILAMENT PANEL ---------- */

#filament-panel {
    position: static;
    width: 100%;
    padding: 0;
    background: none;
    border: none;
}

#filament-panel label {
    display: block;
    margin-bottom: 12px;
}

.filament-info {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 10px;
}

/* ---------- VIEWER ---------- */

#viewer {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#viewer.dragging {
    outline: 2px dashed var(--brand-primary);
}

#dropOverlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #666;
    font-size: 18px;
    font-weight: 500;
    pointer-events: none;
    z-index: 10;
    opacity: 0.5;
}

/* New Slice Overlay */
#sliceOverlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(0, 0, 0, 0.85);
    /* Slightly darker/more opaque */
    color: white;
    padding: 30px 50px;
    border-radius: 12px;
    z-index: 20;
    display: none;
    /* Hidden by default */
    border: 2px solid var(--brand-primary);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

#sliceOverlay h3 {
    margin: 0 0 10px 0;
    font-size: 20px;
    color: var(--brand-primary);
}

#sliceOverlay p {
    margin: 0;
    font-size: 16px;
    opacity: 0.9;
}

/* Spinner Animation */
.slice-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--brand-primary);
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}


.primary-btn {
    background: var(--brand-primary);
    color: white;
    font-weight: bold;
    margin-top: 10px;
    padding: 12px;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    width: 100%;
    transition: background 0.2s, filter 0.2s;
}

.primary-btn:hover {
    filter: brightness(0.85);
    /* Proper dimming for variable color */
}

.primary-btn:disabled {
    background: #555;
    cursor: not-allowed;
    filter: none;
}

.status-text {
    font-size: 0.9em;
    color: #555;
    margin-top: 8px;
    text-align: center;
    min-height: 20px;
}

body.light-mode .status-text {
    color: #555;
}

body:not(.light-mode) .status-text {
    color: #ccc;
}

/* ---------- TABS ---------- */

.tabs {
    display: flex;
    margin-bottom: 20px;
    background: var(--input-bg);
    border-radius: 4px;
    padding: 2px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-color);
    opacity: 0.7;
    border-radius: 4px;
}

.tab-btn.active {
    background: var(--brand-primary);
    color: white;
    opacity: 1;
    font-weight: bold;
}

.tab-content {
    display: none;
    flex-direction: column;
    gap: 20px;
}

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

/* ---------- NEW CONTROLS ---------- */
.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 14px;
}

.control-row input[type="range"] {
    margin-top: 4px;
    flex: 1;
    margin-left: 10px;
}

.secondary-btn {
    background: #444;
    color: white;
    margin-top: 5px;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

.secondary-btn:hover {
    background: #555;
}

#gizmo-container {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 120px;
    height: 120px;
    z-index: 100;
    pointer-events: none;
}

#slice-progress-container {
    margin-top: 5px;
    width: 100%;
    height: 4px;
    background: #333;
    display: none;
}

#slice-progress-bar {
    height: 100%;
    background: var(--brand-primary);
    width: 0%;
    transition: width 0.3s;
}

/* Welcome Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--bg-sidebar);
    color: var(--text-color);
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.modal-content h2 {
    margin-top: 0;
    color: var(--brand-primary);
}

.modal-content ul {
    text-align: left;
    margin: 20px 0;
    padding-left: 20px;
}

.modal-content li {
    margin-bottom: 8px;
}

.modal-content button {
    margin-top: 20px;
    width: 100%;
    padding: 12px;
    font-size: 16px;

    /* Custom Tooltips */
    [data-tooltip] {
        position: relative;
    }

    [data-tooltip]::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: 110%;
        left: 50%;
        transform: translateX(-50%);
        background-color: #333;
        color: #fff;
        padding: 6px 10px;
        border-radius: 6px;
        font-size: 12px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s, bottom 0.2s;
        z-index: 9999;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }

    [data-tooltip]:hover::after {
        opacity: 1;
        bottom: 120%;
    }

    /* Tooltip Arrow */
    [data-tooltip]::before {
        content: '';
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        border: 6px solid transparent;
        border-top-color: #333;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s, bottom 0.2s;
        z-index: 9999;
    }

    [data-tooltip]:hover::before {
        opacity: 1;
        bottom: 110%;
    }
}

/* ---------- TOAST NOTIFICATIONS ---------- */

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    background: var(--bg-sidebar);
    color: var(--text-color);
    padding: 12px 20px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 250px;
    border: 1px solid var(--border-color);
    border-left-width: 4px;
    animation: toast-in 0.3s ease-out forwards;
}

.toast.success {
    border-left-color: #4CAF50;
}

.toast.error {
    border-left-color: #f44336;
}

.toast.warning {
    border-left-color: #ff9800;
}

.toast.info {
    border-left-color: #2196F3;
}

.toast.fade-out {
    animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ---------- SLICE OPTIONS MODAL (FLOATING RIGHT PANEL) ---------- */

/* Remove dark backdrop, make transparent */
#sliceOptionsModal.modal-overlay {
    background: transparent;
    backdrop-filter: none;
    pointer-events: none;
}

.slice-options-modal {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%) translateX(450px);
    width: 420px;
    max-width: calc(100vw - 320px);
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    pointer-events: all;

    /* Semi-transparent background */
    background: rgba(37, 37, 37, 0.98);
    backdrop-filter: blur(10px);

    /* Shadow for depth */
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);

    /* Slide-in animation */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When modal is shown, slide in from right */
#sliceOptionsModal[style*="display: flex"] .slice-options-modal {
    transform: translateY(-50%) translateX(0);
}

body.light-mode .slice-options-modal {
    background: rgba(249, 245, 235, 0.98);
}

.slice-options-modal .modal-header {
    text-align: center;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.slice-options-modal .modal-header h2 {
    margin: 0 0 5px 0;
    color: #4CAF50;
}

.slice-options-modal .modal-header p {
    margin: 0;
    color: #999;
    font-size: 14px;
}

body.light-mode .slice-options-modal .modal-header p {
    color: #666;
}

.slice-options-modal .modal-body {
    padding: 20px 0;
}

/* Option Sections */
.option-section {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border-left: 4px solid #4CAF50;
}

body.light-mode .option-section {
    background: rgba(0, 0, 0, 0.03);
    border-left-color: #4CAF50;
}

.option-section h3 {
    margin: 0 0 12px 0;
    font-size: 16px;
    color: var(--text-color);
    text-transform: none;
    opacity: 1;
}

/* Checkbox Option */
.checkbox-option {
    display: block;
    cursor: pointer;
    padding: 8px;
}

.checkbox-option input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
}

.option-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 16px;
}

.option-price {
    color: #4CAF50;
    font-weight: bold;
    font-size: 15px;
}

.option-description {
    font-size: 13px;
    color: #999;
    margin-top: 5px;
}

body.light-mode .option-description {
    color: #666;
}

/* Radio Options */
.radio-option {
    display: flex;
    align-items: center;
    padding: 10px;
    margin: 6px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.radio-option:hover {
    background: rgba(76, 175, 80, 0.1);
}

body.light-mode .radio-option {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid #e0e0e0;
}

body.light-mode .radio-option:hover {
    background: #e8f5e9;
}

.radio-option input[type="radio"] {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    cursor: pointer;
}

.radio-option span {
    font-size: 14px;
}

/* Pickup Notice */
.pickup-notice {
    display: flex;
    gap: 12px;
    padding: 15px;
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    margin: 20px 0;
}

.notice-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.notice-content {
    flex: 1;
}

.notice-content strong {
    display: block;
    color: #856404;
    margin-bottom: 5px;
}

.notice-content p {
    margin: 0;
    color: #856404;
    font-size: 13px;
    line-height: 1.5;
}

/* Price Breakdown */
.price-breakdown {
    margin: 20px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

body.light-mode .price-breakdown {
    background: rgba(0, 0, 0, 0.03);
}

.price-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}

.price-addon {
    color: #4CAF50;
}

.price-divider {
    height: 1px;
    background: var(--border-color);
    margin: 10px 0;
}

.price-total {
    font-size: 18px;
    color: var(--text-color);
}

/* Modal Footer */
.modal-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-top: 15px;
    border-top: 2px solid var(--border-color);
}

.btn-secondary {
    flex: 1;
    padding: 12px 20px;
    background: #666;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #555;
}

.btn-primary {
    flex: 2;
    padding: 12px 20px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background 0.2s;
}

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

/* Responsive - on small screens, revert to centered modal */
@media (max-width: 900px) {
    #sliceOptionsModal.modal-overlay {
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(5px);
        pointer-events: all;
    }

    .slice-options-modal {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: 90%;
        max-width: 500px;
        margin: auto;
    }

    #sliceOptionsModal[style*="display: flex"] .slice-options-modal {
        transform: none;
    }

    .modal-footer {
        flex-direction: column;
    }

    .btn-secondary,
    .btn-primary {
        flex: 1;
    }
}

/* Slide-in animation keyframes */
@keyframes slideInRight {
    from {
        transform: translateY(-50%) translateX(450px);
        opacity: 0;
    }

    to {
        transform: translateY(-50%) translateX(0);
        opacity: 1;
    }
}