// Tablet page styles

#tablet {
    height: calc(100vh - 60px); // Account for navbar
    display: flex;
    flex-direction: column;
    overflow: hidden; // Prevent any scrolling on the main container
}

.tablet-tabs {
    flex-shrink: 0;
    background-color: $bg-color;
    border-bottom: 2px solid $border-color;

    .tab {
        margin: 0;
        border-bottom: none;
    }

    .tab-item {
        a {
            padding: 0.5rem 1.2rem;
            font-weight: 500;
            color: $body-font-color;

            &:hover {
                color: $primary-color;
            }
        }

        &.active a {
            border-bottom-color: $primary-color;
            color: $primary-color;
        }
    }
}

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

// Terminal Tab specific styles
.tablet-terminal-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tablet-terminal-header {
    flex-shrink: 0;
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.tablet-terminal-input {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    align-items: stretch;

    .form-input {
        flex: 1;
        font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    }

    .btn {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        white-space: nowrap;
    }
}

.tablet-terminal-controls {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;

    .toggle-btn {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        min-width: 5rem;
        padding: 0.4rem 0.6rem;
        background-color: $bg-color;
        border: 1px solid $border-color;
        transition: all 0.2s ease;

        &.active {
            background-color: $primary-color;
            color: $light-color;
            border-color: $primary-color;

            .toggle-label {
                color: $light-color;
            }
        }

        &.paused {
            background-color: $warning-color;
            color: $light-color;
            border-color: $warning-color;

            .toggle-label {
                color: $light-color;
            }
        }

        // Touch-friendly active state
        &:active {
            transform: scale(0.95);
        }

        // For desktop, provide hover
        @media (hover: hover) {
            &:hover:not(.active):not(.paused) {
                background-color: $bg-color-dark;
            }
        }
    }

    .toggle-label {
        font-size: 0.75rem;
        font-weight: 500;
        white-space: nowrap;
    }
}

.tablet-terminal-output {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--bg-color, #fff);
    color: var(--text-color, #000);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    padding: 0.5rem;
    border: 1px solid var(--border-color, #dadee4);
    border-radius: 4px;
    min-height: 0; // Allow flex item to shrink below content size

    pre {
        margin: 0;
        padding: 0;
        white-space: pre-wrap;
        word-wrap: break-word;

        &.echo {
            color: blue;
        }

        &.error {
            color: red;
            font-weight: bolder;
        }

        &.warning {
            color: orange;
            font-weight: bolder;
        }

        &.action {
            color: green;
        }

        .warning {
            color: orange;
            font-weight: bolder;
        }

        .error {
            color: red;
        }

        .info {
            color: blue;
        }
    }
}

// Tab content styles
.tab-content {
    padding: 1rem;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

// Files Tab specific styles
.tablet-files-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tablet-files-toolbar {
    flex-shrink: 0;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
    background-color: $bg-color;
    border-bottom: 1px solid $border-color;
    flex-wrap: wrap;

    .files-toolbar-section {
        display: flex;
        gap: 0.5rem;
        align-items: center;

        &:first-child {
            flex: 1;
        }
    }

    .files-toolbar-sort {
        display: flex;
        gap: 0.5rem;
        align-items: center;
        flex-wrap: wrap;

        .sort-label {
            font-size: 0.85rem;
            font-weight: 500;
            color: $gray-color-dark;
        }

        .btn-group {
            display: flex;
            gap: 0.25rem;

            .btn {
                display: flex;
                align-items: center;
                gap: 0.25rem;
                white-space: nowrap;

                svg {
                    vertical-align: middle;
                }
            }
        }
    }

    .files-toolbar-actions {
        flex: 0;
        flex-shrink: 0;

        .btn {
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 1.2rem;
            min-width: 2rem;
            padding: 0.4rem;
        }
    }

    .btn-group {
        flex-wrap: wrap;

        .btn {
            display: flex;
            align-items: center;
            justify-content: center;
        }
    }
}

.tablet-files-path {
    flex-shrink: 0;
    padding: 0.1rem 1rem;
    background-color: $bg-color-light;
    border: 1px solid $border-color;
    border-radius: 4px;
    margin: 0 0.5rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9rem;
}

.tablet-files-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 0; // Allow flex item to shrink below content size
    background-color: #fff;
    color: #000;

    &.drop-zone--over {
        background-color: rgba($primary-color, 0.1);
        border: 2px dashed $primary-color;
    }
}

.tablet-files-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
}

.tablet-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem;
    background-color: $bg-color-light;
    border: 1px solid $border-color;
    border-radius: 4px;
    transition: all 0.2s ease;
    min-height: 50px;

    &:active {
        transform: scale(0.98);
    }

    @media (hover: hover) {
        &:hover {
            background-color: $bg-color;
            border-color: $primary-color;
        }
    }

    .file-item-name {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        cursor: pointer;
        min-width: 0;

        span {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        svg {
            flex-shrink: 0;
        }
    }

    .file-item-controls {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-shrink: 0;

        .file-item-date {
            font-size: 0.75rem;
            color: $gray-color-dark;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            white-space: nowrap;
        }

        .file-item-size {
            font-size: 0.85rem;
            color: $gray-color-dark;
            min-width: 4rem;
            text-align: right;
        }

        .btn {
            padding: 0.4rem 0.6rem;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 1.2rem;
            min-width: 2rem;

            svg {
                display: block;
            }
        }
    }
}

.tablet-files-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 1rem;
    background-color: $bg-color;
    border-top: 1px solid $border-color;
    font-size: 0.75rem;
    color: $gray-color-dark;
}

// Macros Tab specific styles
.tablet-macros-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    padding: 1rem;
    height: 100%;
    overflow: hidden;
    align-content: start;
}

.tablet-macro-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 120px;
    padding: 1.5rem;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

    &:active {
        transform: scale(0.95);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }

    @media (hover: hover) {
        &:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }
    }

    .macro-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 2rem;

        svg {
            width: 2rem;
            height: 2rem;
        }
    }

    .macro-label {
        text-align: center;
        word-wrap: break-word;
        line-height: 1.3;
    }
}

// Status Bar styles
.tablet-statusbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #2c3e50;
    color: #ecf0f1;
    padding: 0.5rem 1rem;
    border-top: 1px solid #34495e;
    font-size: 0.9rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    gap: 1rem;

    .statusbar-section {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .statusbar-label {
        font-weight: bold;
        color: $link-color;
        padding: 0.25rem 0.75rem;
        background-color: rgba($link-color, 0.1);
        border-radius: 3px;
        min-width: 5.5rem;
        text-align: center;
        display: inline-block;

        &.status-idle {
            background-color: $success-color;
            color: $light-color;
        }

        &.status-error {
            background-color: $error-color;
            color: $light-color;
        }

        &.status-warning {
            background-color: $warning-color;
            color: $light-color;
        }

        &.status-sleep {
            background-color: $gray-color-dark;
            color: $light-color;
        }
    }

    .statusbar-positions {
        flex: 1;
        display: flex;
        gap: 0.95rem;
        justify-content: center;
        flex-wrap: wrap;
        align-items: flex-end;
    }

    .position-headers {
        display: flex;
        align-items: center;
        gap: 0.15rem;
        margin-bottom: 0.1rem;
        margin-right: 0.4rem;
    }

    .position-header-spacer {
        width: auto;
    }

    .position-header-labels {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .position-header-label {
        color: #95a5a6;
        font-size: 0.65rem;
        font-weight: 500;
        line-height: 1.05;
        text-align: right;
        min-width: 3rem;
    }

    .position-group {
        display: flex;
        align-items: center;
        gap: 0.15rem;
        margin-right: 0.4rem;
    }

    .position-label {
        color: #95a5a6;
        font-weight: 500;
        font-size: 0.8rem;
        text-align: left;
    }

    .position-stack {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .position-value {
        color: #ecf0f1;
        min-width: 3rem;
        text-align: right;
        font-size: 0.75rem;
        line-height: 1.05;
    }

    .statusbar-right {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.25rem;
    }

    .connection-group {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .connection-label {
        color: #ecf0f1;
        font-weight: 500;
    }

    .connection-icon {
        display: flex;
        align-items: center;
        color: $success-color;
    }

    .hostname-label {
        color: #95a5a6;
        font-size: 0.85rem;
    }
}

// Control Tab specific styles
.tablet-control-container {
    height: 100%;
    display: flex;
    gap: 0;
}

.tablet-control-sidebar {
    flex-shrink: 0;
    width: 120px;
    background-color: $bg-color;
    border-right: 1px solid $border-color;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
}

.control-subtab-btn {
    padding: 1rem 0.5rem;
    border: none;
    background-color: transparent;
    color: $body-font-color;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    text-align: center;

    &.active {
        background-color: $bg-color-light;
        color: $primary-color;
        border-left-color: $primary-color;
    }

    &:active {
        transform: scale(0.98);
    }

    @media (hover: hover) {
        &:hover:not(.active) {
            background-color: $bg-color-dark;
        }
    }
}

.tablet-control-content {
    flex: 1;
    overflow: hidden;
    padding: 0rem;
    display: flex;
    flex-direction: column;
}

.control-subtab-content {
    padding: 1rem;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

// Jog SubTab specific styles
.jog-subtab-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    gap: 0.5rem;
}

.jog-command-bar {
    flex-shrink: 0;
    background-color: $bg-color;
    border: 1px solid $border-color;
    border-radius: 8px;
    padding: 0.5rem;
    margin: 0 0.5rem 0 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.jog-command-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.jog-command-label {
    font-weight: 600;
    color: $body-font-color;
    min-width: 60px;
}

.jog-command-buttons {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.jog-command-buttons .btn {
    min-width: 3rem;
}

.jog-controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 0 0.5rem;
    flex: 1;
    align-items: stretch;
    min-height: 0; // Allow grid to shrink
}

.jog-control-section {
    background-color: $bg-color-light;
    border: 1px solid $border-color;
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0; // Allow section to shrink
    overflow: hidden;
}

.jog-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid $border-color;
    font-weight: 600;
    font-size: 1rem;
    color: $body-font-color;

    .btn-link {
        font-size: 0.75rem;
        color: $gray-color-dark;
        font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    }
}

.jog-xy-grid {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
    padding: 0.5rem 0;
    flex: 1;
    justify-content: center;
}

.jog-xy-row {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.jog-btn {
    min-width: 55px;
    min-height: 55px;
    border: 2px solid $border-color;
    background-color: $bg-color;
    color: $body-font-color;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;

    &:active {
        transform: scale(0.95);
    }

    @media (hover: hover) {
        &:hover {
            border-color: $primary-color;
            box-shadow: 0 2px 8px rgba($primary-color, 0.2);
        }
    }

    // jog-btn-primary styling is inherited from Spectre's .btn-primary class

    &.jog-btn-diagonal {
        background-color: $bg-color-dark;
        color: $gray-color-dark;
    }

    &.jog-btn-action {
        background-color: $success-color;
        color: $light-color;
        border-color: $success-color;

        @media (hover: hover) {
            &:hover {
                background-color: darken($success-color, 10%);
            }
        }
    }

    &.jog-btn-sm {
        min-width: 45px;
        min-height: 45px;
        font-size: 0.85rem;

        .text-tiny {
            font-size: 0.65rem;
            margin-left: 0.15rem;
        }
    }

    &.jog-btn-z {
        min-width: 90px;
    }
}

.jog-center-spacer {
    min-width: 55px;
    min-height: 55px;
}

.jog-z-controls {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
    padding: 0.5rem 0;
    flex: 1;
    justify-content: center;
}

.jog-distance-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.jog-distance-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: $gray-color-dark;
}

// Additional Axis Panel - Horizontal Layout
.jog-additional-axis-panel {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    margin: 0 0.5rem;
    background-color: $bg-color;
    border: 1px solid $border-color;
    border-radius: 8px;
    flex-wrap: wrap;
}

.jog-axis-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.jog-axis-selector-label {
    font-weight: 500;
    color: $body-font-color;
    min-width: 40px;
    font-size: 0.9rem;
}

.jog-additional-controls-horizontal {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.jog-distance-selector-horizontal {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.jog-axis-position-display {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-weight: 600;
    color: $link-color;
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    background-color: $bg-color-light;
    border: 1px solid $border-color;
    border-radius: 4px;
    text-align: center;
    transition: all 0.2s ease;
    min-width: 70px;

    @media (hover: hover) {
        &:hover {
            color: $success-color;
            border-color: $success-color;
        }
    }

    &:active {
        transform: scale(0.95);
    }
}

// Joystick SubTab styles
.joystick-subtab-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    gap: 0.5rem;
}

.joystick-controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 0.5rem;
    flex: 1;
    align-items: stretch;
    min-height: 0; // Allow grid to shrink
}

.joystick-panel {
    background-color: $bg-color-light;
    border: 1px solid $border-color;
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0; // Allow panel to shrink
    overflow: hidden;
}

.joystick-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid $border-color;
    font-weight: 600;
    font-size: 1rem;
    color: $body-font-color;
}

.joystick-mode-buttons {
    display: flex;
    gap: 0.25rem;

    .btn {
        min-width: 3rem;
    }
}

.joystick-canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    position: relative;

    canvas {
        max-width: 100%;
        max-height: 100%;
        touch-action: none;
        cursor: pointer;
    }
}

.joystick-status-message {
    text-align: center;
    padding: 1rem;
    color: $gray-color-dark;
    font-size: 0.9rem;
    font-style: italic;
}

// Responsive adjustments
@media (max-width: 768px) {
    .tablet-tabs .tab-item a {
        padding: 0.6rem 0.8rem;
        font-size: 0.9rem;
    }

    .tablet-terminal-input {
        flex-direction: column;

        .btn {
            width: 100%;
            justify-content: center;
        }
    }

    .tablet-statusbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.75rem;

        .statusbar-positions {
            width: 100%;
            flex-direction: column;
            gap: 0.5rem;
        }

        .position-group {
            width: 100%;
            justify-content: space-between;
        }
    }
}

// Fullscreen Files Panel styling
.panel {
    &:has(.tablet-files-container) {
        background-color: #fff !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;

        // Override any inherited styles
        .panel-body {
            background-color: #fff !important;
            padding: 0 !important;
        }
    }

    .tablet-files-container {
        // Ensure white background when inside a panel
        height: 100%;
        width: 100%;
        background-color: #fff !important;
        color: #000 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;

        .tablet-files-toolbar {
            background-color: $bg-color !important;
            border-bottom: 1px solid $border-color !important;
        }

        .tablet-files-path {
            background-color: $bg-color-light !important;
            border: 1px solid $border-color !important;
            border-radius: 4px;
            margin: 0 0.5rem;
        }

        .tablet-files-list {
            background-color: #fff !important;
            color: #000 !important;
        }

        .tablet-files-footer {
            background-color: $bg-color-light !important;
            border-top: 1px solid $border-color !important;
        }
    }
}
