body, html {
    margin: 0;
    display: flex;
    flex-direction: column;
    font-family: var(--font-family);
    font-weight: var(--font-weight-normal);
    position: relative;
    background-color: var(--bg-light);
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    width: 100vw;
    height: 100vh;
    flex-grow: 1;
}

@media (min-width: 1200px) {
    .grid-container {
        width: 90vw;
        height: 90vh;
        max-width: 1600px;
        max-height: 900px;
        flex-grow: 0;
        box-shadow: var(--shadow-elevated);
        border-radius: var(--radius-large);
    }
}

.grid-item {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: var(--spacing-sm);
    box-sizing: border-box;
    overflow: hidden;
    border-radius: var(--radius-medium);
}

.grid-item:nth-child(1) {
    justify-content: center;
}

#ascii-title {
    text-align: center;
    margin-bottom: 0;
    flex-shrink: 0;
    transform: scale(0.8);
    transform-origin: center;
}

#videoPreview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    aspect-ratio: 16 / 9;
    border: 2px dotted var(--text-primary);
}

#camera-list-container.grid-item {
    justify-content: flex-start;
    align-items: flex-start;
}

#cameraList {
    list-style-type: none;
    padding: 0;
    margin: 0;
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
}

.camera-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px dotted var(--text-primary);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    box-sizing: border-box;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
    cursor: pointer;
}

.camera-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.camera-item:last-child {
    margin-bottom: 0;
}

.camera-item.selected {
    border-color: #3b82f6;
    background-color: rgba(59, 130, 246, 0.1);
}

.camera-text-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-right: var(--spacing-sm);
}

.camera-text-content span {
    margin-bottom: var(--spacing-xs);
}

.camera-text-content span:last-child {
    margin-bottom: 0;
}

.camera-video-preview {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.camera-display-section, .settings-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    padding-top: 0px;
}

.settings-section {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--text-secondary) var(--background-secondary);
}

.settings-section::-webkit-scrollbar {
    width: 8px;
}

.settings-section::-webkit-scrollbar-track {
    background: var(--background-secondary);
    border-radius: var(--radius-sm);
}

.settings-section::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--background-secondary);
}

.settings-section::-webkit-scrollbar-thumb:hover {
    background: var(--text-primary);
}

.camera-header {
    display: flex;
    align-items: center;
}

.camera-status {
    font-size: var(--font-size-sm);
    margin-left: var(--spacing-md);
    margin-right: var(--spacing-sm);
    display: inline-block;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: var(--spacing-lg) var(--spacing-lg);
    width: 100%;
    place-items: stretch;
}

.info-item {
    padding: var(--spacing-xl) var(--spacing-2xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    text-align: center;
    width: 100%;
    height: 100%;
    min-height: 120px;
    background-color: var(--color-white);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-light);
    transition: var(--transition-medium);
}

.info-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: var(--spacing-lg) var(--spacing-lg);
    width: 100%;
}

.settings-item {
    padding: var(--spacing-sm) var(--spacing-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 160px;
    min-height: 80px;
    box-sizing: border-box;
    background-color: var(--color-white);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-light);
    transition: var(--transition-medium);
}

.settings-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.settings-dropdown {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 25px;
    border: 2px dotted var(--text-primary);
    background-color: var(--color-white);
    color: var(--text-primary);
    font-family: var(--font-family);
    cursor: pointer;
    border-radius: 0;
    margin: 10px 0;
    padding: 0 var(--spacing-sm);
    box-sizing: border-box;
    background-repeat: no-repeat;
    background-position: right .7em top 50%;
    background-size: .65em auto;
}

.camera-prediction-time {
    font-style: italic;
}

.info-value {
    margin-bottom: var(--spacing-xs);
}

.success-status {
    color: var(--color-success);
}

.info-label {
    font-style: italic;
}

.start-stop-btn {
    padding: var(--spacing-lg) var(--spacing-xl);
    border: 2px dotted var(--text-primary);
    cursor: pointer;
    margin: var(--spacing-md);
    background: transparent;
    transition: var(--transition-fast);
    font-family: var(--font-family);
    width: calc(100% - 2 * var(--spacing-md));
    box-sizing: border-box;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    position: relative;
}

.start-stop-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.start-stop-btn:hover {
    background: var(--text-primary);
    color: var(--color-white);
}

.start-stop-btn.primary {
    background: var(--text-primary);
    color: var(--color-white);
    border-color: var(--text-primary);
}

.start-stop-btn.primary:hover {
    background: #444;
    border-color: #444;
}

.start-stop-btn.secondary {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}

.start-stop-btn.secondary:hover {
    background: var(--text-secondary);
    color: var(--color-white);
}

.start-stop-btn.danger {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.start-stop-btn.danger:hover {
    background: var(--color-danger);
    color: var(--color-white);
}

.button-group {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
    justify-content: center;
}

.button-group .start-stop-btn {
    flex: 1;
    margin: 0;
    min-width: 120px;
}

.notification-popup {
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    max-width: 350px;
    width: auto;
    z-index: 1000;
    display: none;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-elevated);
    overflow: hidden;
    transition: var(--transition-slow);
    animation: slideIn var(--transition-duration-slow) forwards;
}

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

#notificationsContainer {
    padding: var(--spacing-sm);
}

.alert-item {
    background-color: var(--color-white);
    border-radius: var(--radius-xs);
    padding: var(--spacing-sm) !important;
    margin-bottom: var(--spacing-sm) !important;
    animation: fadeIn 0.4s;
    transition: var(--transition-fast);
}

.alert-item:hover {
    box-shadow: var(--shadow-medium);
    transform: translateY(-2px);
}

.alert-item p {
    margin: 0 0 var(--spacing-xs) 0;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.alert-item img {
    border-radius: var(--radius-xs);
    width: 100%;
    margin-bottom: var(--spacing-sm);
}

.alert-item button {
    background-color: var(--bg-light);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    margin-right: var(--spacing-xs);
    cursor: pointer;
    font-size: var(--font-size-xs);
    transition: var(--transition-fast);
}

.alert-item button:hover {
    background-color: var(--border-light);
}

.alert-item .suspend-print-btn {
    background-color: var(--color-danger);
    color: var(--color-white);
    border-color: var(--color-danger);
}

.alert-item .suspend-print-btn:hover {
    background-color: var(--color-danger-dark);
    border-color: var(--color-danger-dark);
}

.alert-item .suspend-print-btn.disabled {
    background-color: #cccccc;
    color: #666666;
    border-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

.alert-item .suspend-print-btn.disabled:hover {
    background-color: #cccccc;
    border-color: #cccccc;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.settings-button {
    position: fixed;
    bottom: var(--spacing-md);
    right: var(--spacing-md);
    padding: var(--spacing-lg) var(--spacing-xl);
    background-color: var(--background-secondary);
    color: var(--text-primary);
    border: 2px dotted var(--text-primary);
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: var(--font-size-base);
    font-weight: 500;
    box-shadow: var(--shadow-medium);
    transition: var(--transition-slow);
    z-index: 100;
    min-width: 100px;
    text-align: center;
}

.settings-button:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    background-color: var(--text-primary);
    color: var(--background-secondary);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 25px;
    background: transparent;
    margin: 10px 0;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 25px;
    cursor: pointer;
    background: var(--color-white);
    border: 2px solid var(--text-primary);
    border-radius: 0;
    box-sizing: border-box;
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 25px;
    cursor: pointer;
    background: var(--color-white);
    border: 2px solid var(--text-primary);
    border-radius: 0;
    box-sizing: border-box;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 21px;
    width: 10px;
    background: transparent;
    cursor: pointer;
    margin-top: 0px;
    box-sizing: border-box;
    position: relative;
    z-index: 3;
}

input[type="range"]::-moz-range-thumb {
    height: 21px;
    width: 10px;
    background: transparent;
    cursor: pointer;
    box-sizing: border-box;
    position: relative;
    z-index: 3;
}

#brightness::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #FFD700 var(--value, 50%), #ffffff var(--value, 50%));
}

#brightness::-moz-range-track {
    background: linear-gradient(to right, #FFD700 var(--value, 50%), #ffffff var(--value, 50%));
}

#contrast::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #555555 var(--value, 50%), #ffffff var(--value, 50%));
}

#contrast::-moz-range-track {
    background: linear-gradient(to right, #555555 var(--value, 50%), #ffffff var(--value, 50%));
}

#sensitivity::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #ADD8E6 var(--value, 50%), #ffffff var(--value, 50%));
}

#sensitivity::-moz-range-track {
    background: linear-gradient(to right, #ADD8E6 var(--value, 50%), #ffffff var(--value, 50%));
}

.notification-control {
    width: 100%;
    margin: var(--spacing-sm) 0;
}

#notificationBtn {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 25px;
    cursor: pointer;
    background: var(--color-white);
    border: 2px solid var(--text-primary);
    border-radius: 0;
    box-sizing: border-box;
    position: relative;
    margin: var(--spacing-sm) 0;
    padding: 0;
    transition: var(--transition-slow);
}

#notificationBtn.enabled {
    background: var(--color-success);
    border-color: var(--color-success);
}

#notificationBtn.disabled {
    background: var(--color-danger);
    border-color: var(--color-danger);
}

#notificationBtn::before {
    content: "Off";
    position: absolute;
    left: var(--spacing-sm);
    top: 2px;
    font-size: var(--font-size-sm);
    color: var(--color-white);
    z-index: 2;
}

#notificationBtn::after {
    content: "On";
    position: absolute;
    right: var(--spacing-sm);
    top: 2px;
    font-size: var(--font-size-sm);
    color: var(--color-white);
    z-index: 2;
}

#focus::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #DDDDDD var(--value, 50%), #ffffff var(--value, 50%));
}

#focus::-moz-range-track {
    background: linear-gradient(to right, #DDDDDD var(--value, 50%), #ffffff var(--value, 50%));
}

#countdown_time::-webkit-slider-runnable-track,
#majority_vote_threshold::-webkit-slider-runnable-track,
#majority_vote_window::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #DDDDDD var(--value, 50%), #ffffff var(--value, 50%));
}

#countdown_time::-moz-range-track,
#majority_vote_threshold::-moz-range-track,
#majority_vote_window::-moz-range-track {
    background: linear-gradient(to right, #DDDDDD var(--value, 50%), #ffffff var(--value, 50%));
}

@media (max-width: 768px) {
    .grid-container {
        display: flex;
        flex-direction: column;
        width: 100vw;
        min-height: 100vh;
        overflow-y: auto;
    }

    .grid-item {
        width: 100%;
        padding-left: 2%;
        padding-right: 2%;
        overflow: visible;
    }

    .grid-item:nth-child(1) {
        order: 1;
        height: auto;
        max-height: 10vh;
        margin-bottom: var(--spacing-4xl);
    }

    .grid-item:nth-child(1) .camera-header {
        display: none;
    }

    #camera-list-container.grid-item {
        order: 2;
        height: 20vh;
        max-height: 20vh;
        overflow-y: auto;
        flex-shrink: 0;
        flex-grow: 0;
    }

    .grid-item:nth-child(2) {
        order: 3;
        height: 25vh;
        flex-shrink: 0;
        flex-grow: 0;
    }

    .grid-item:nth-child(4) {
        order: 4;
        flex-grow: 0;
        height: auto;
        max-height: 45vh;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .camera-display-section {
        flex-grow: 0;
        height: auto;
        max-height: 45vh;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .info-grid {
        gap: var(--spacing-sm);
        flex-grow: 0;
        max-height: 28vh;
        margin-bottom: var(--spacing-sm);
    }
}

@media (max-width: 539px) {
    .settings-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: repeat(2, auto);
        max-height: 30vh;
        overflow-y: auto;
    }
}

@media (min-width: 540px) and (max-width: 768px) {
    .settings-grid {
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: repeat(3, auto);
        max-height: 22vh;
        overflow-y: auto;
        gap: 50px var(--spacing-sm);
    }
}

@media (max-width: 380px) {
    body, html {
        font-size: 10px;
    }

    .camera-status {
        font-size: var(--font-size-xs);
    }

    .start-stop-btn {
        font-size: var(--font-size-xs);
    }

    .info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        gap: var(--spacing-xs) var(--spacing-xs);
        width: 100%;
        place-items: center;
        max-height: 26vh;
        overflow-y: auto;
    }

    .settings-grid {
        display: grid;
        grid-template-columns: repeat(1, 1fr);
        grid-template-rows: repeat(8, 1fr);
        gap: var(--spacing-xs) var(--spacing-xs);
        width: 100%;
        max-height: 26vh;
        overflow-y: auto;
    }

    .settings-item, .info-item {
        padding: var(--spacing-xs) var(--spacing-xs);
        min-height: 35px;
        min-width: 70px;
    }

    .settings-item {
        padding: var(--spacing-xs) var(--spacing-xs);
        margin-top: var(--spacing-md);
        min-height: 35px;
        min-width: 70px;
        background-color: transparent;
        box-shadow: none;
        border: none;
    }
}

@media (min-width: 769px) {
  .camera-display-section {
    align-items: flex-end;
    justify-content: flex-start;
    padding-right: var(--spacing-md);
    padding-top: 0px;
  }

  .settings-section {
    align-items: flex-end;
    justify-content: flex-start;
    padding-right: var(--spacing-md);
    padding-top: 0px;
    overflow-y: auto;
    overflow-x: hidden;
  }
}

.setup-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.setup-modal {
    background-color: var(--background-primary);
    border: 2px dotted var(--text-primary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    position: relative;
    overflow-y: auto;
    box-shadow: var(--shadow-elevated);
}

.setup-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.setup-modal-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0;
}

.setup-modal-close {
    background: transparent;
    border: 2px dotted var(--text-primary);
    color: var(--text-primary);
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    font-family: var(--font-family);
}

.setup-modal-close:hover {
    background: var(--text-primary);
    color: var(--color-white);
}

.setup-modal-content {
    color: var(--text-primary);
}

.setup-modal-content p {
    margin-bottom: var(--spacing-md);
    line-height: 1.6;
}

.setup-section {
    margin-bottom: var(--spacing-xl);
}

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

.setup-section-title {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0 0 var(--spacing-md) 0;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: var(--spacing-xs);
}

.feed-settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-lg);
    margin-top: var(--spacing-md);
}

.feed-setting-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-md);
    background-color: var(--color-white);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-light);
    transition: var(--transition-medium);
    min-height: 80px;
    box-sizing: border-box;
}

.feed-setting-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.feed-setting-item label {
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-sm);
    text-align: center;
    font-weight: 500;
}

.feed-setting-item input[type="range"] {
    width: 100%;
}

#streamMaxFps::-webkit-slider-runnable-track,
#streamTunnelFps::-webkit-slider-runnable-track,
#streamJpegQuality::-webkit-slider-runnable-track,
#streamMaxWidth::-webkit-slider-runnable-track,
#detectionsPerSecond::-webkit-slider-runnable-track,
#detectionInterval::-webkit-slider-runnable-track,
#printerStatPollingRate::-webkit-slider-runnable-track,
#minSseDispatchDelay::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #ADD8E6 var(--value, 50%), #ffffff var(--value, 50%));
}

#streamMaxFps::-moz-range-track,
#streamTunnelFps::-moz-range-track,
#streamJpegQuality::-moz-range-track,
#streamMaxWidth::-moz-range-track,
#detectionsPerSecond::-moz-range-track,
#detectionInterval::-moz-range-track,
#printerStatPollingRate::-moz-range-track,
#minSseDispatchDelay::-moz-range-track {
    background: linear-gradient(to right, #ADD8E6 var(--value, 50%), #ffffff var(--value, 50%));
}

@media (max-width: 600px) {
    .feed-settings-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }
    
    .setup-modal {
        padding: var(--spacing-lg);
        max-height: 90vh;
    }
}

.printer-control {
    width: 100%;
    margin: var(--spacing-sm) 0;
}

.printer-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    border: 1px solid var(--text-secondary);
    border-radius: var(--radius-small);
    background-color: var(--bg-light);
}

.printer-details h4 {
    margin: 0 0 var(--spacing-xs) 0;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.printer-details p {
    margin: 0 0 var(--spacing-xs) 0;
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
}

.printer-stats {
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--text-tertiary);
}

.printer-stats p {
    margin: 0 0 var(--spacing-xs) 0;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.printer-actions {
    display: flex;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
}

.printer-btn {
    flex: 1;
    min-width: 60px;
    padding: var(--spacing-xs);
    border: 1px solid var(--text-primary);
    background: var(--color-white);
    color: var(--text-primary);
    font-size: var(--font-size-xs);
    cursor: pointer;
    border-radius: var(--radius-small);
    transition: var(--transition-fast);
}

.printer-btn:hover {
    background: var(--text-primary);
    color: var(--color-white);
}

.printer-btn.danger {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.printer-btn.danger:hover {
    background: var(--color-danger);
    color: var(--color-white);
}

.no-printer-info {
    text-align: center;
    padding: var(--spacing-sm);
    color: var(--text-secondary);
}

.no-printer-info p {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: var(--font-size-xs);
}