* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
    background-color: var(--background-color);
    color: var(--text-color);
    height: 100%;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Ultra-wide mode styles */
.fullscreen-mode .header,
.fullscreen-mode .side-panel {
    display: none;
}

.fullscreen-mode .container {
    padding: 0;
    max-width: 100vw;
    height: 100vh;
}

.fullscreen-mode .main-section {
    height: 100%;
}

.fullscreen-mode .swipe-container {
    height: 100%;
    border-radius: 0;
}

/* Ultra-wide toggle button */
.fullscreen-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    background-color: var(--dark-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.fullscreen-toggle:hover {
    opacity: 1;
    transform: scale(1.1);
}

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

.app-title {
    font-size: 2rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--dark-color);
}

.app-title i {
    color: var(--primary-color);
}

.history-link {
    padding: 8px 16px;
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    transition: background-color 0.3s, transform 0.2s;
}

.history-link:hover {
    background-color: #1c86e3;
    transform: translateY(-2px);
}

.main-section {
    display: flex;
    gap: 24px;
    flex: 1;
    align-items: flex-start;
}

.swipe-container {
    position: relative;
    flex: 1 1 auto;
    height: calc(100vh - 160px); /* maximise vertical space */
    perspective: 1000px;
    border-radius: var(--border-radius);
    background: var(--card-background);
    box-shadow: var(--shadow);
    border-style: solid;
    border-width: 6px;
    border-left-color: var(--danger-color);
    border-right-color: var(--success-color);
    border-top-color: var(--primary-color);
    border-bottom-color: var(--warning-color);
}

.image-card {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}


.image-card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.image-card {
    border-radius: var(--border-radius);
    overflow: hidden;
    background-color: var(--card-background);
    touch-action: none;
    cursor: grab;
    transition: transform 0.5s ease-out, opacity 0.5s ease-out;
}

.loading-indicator, .no-images-message {
    opacity: 0; /* hidden by default */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-weight: bold;
    font-size: 1.2rem;
    text-align: center;
    padding: 20px;
}

.image-card.loading .loading-indicator {
    opacity: 1; /* visible when card has loading class */
}

.image-card.swiping {
    transition: none;
}

.action-hint {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
}

.left-hint { left: 20px; top: 50%; transform: translateY(-50%); }
.right-hint { right: 20px; top: 50%; transform: translateY(-50%); }
.up-hint { top: 20px; left: 50%; transform: translateX(-50%); }
.down-hint { bottom: 20px; left: 50%; transform: translateX(-50%); }

.side-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 20px;
    min-width: 300px;
}

.filter-controls, .action-buttons, .status-area {
    background-color: var(--card-background);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.search-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.search-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    background-color: var(--light-color);
    color: var(--dark-color);
    font-weight: 500;
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(30, 144, 255, 0.2);
}

.search-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0 20px;
}

.keyword-pills-container {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    width: 100%;
    margin-top: 10px;
}

.keyword-pill {
    display: flex;
    align-items: center;
    background-color: var(--primary-color);
    color: white;
    border-radius: 15px;
    padding: 5px 10px;
    font-size: 0.9rem;
}

.keyword-pill .remove-keyword {
    margin-left: 8px;
    border: none;
    background: none;
    color: white;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0;
    line-height: 1;
}

.filter-controls h4, .action-buttons h4, .status-area h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--dark-color);
    font-size: 1.1rem;
}

.filter-buttons {
    display: flex;
    gap: 10px;
}

.action-filters {
    margin-top: 10px;
}

.orientation,
.action-filter {
    width: 24px;
    height: 24px;
}

.filter-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    background-color: var(--light-color);
    color: var(--dark-color);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.filter-btn:hover {
    background-color: #e0e0e0;
    border-color: #ccc;
}

.filter-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    font-size: 1rem;
    color: white;
}

#btn-left { background-color: var(--danger-color); }
#btn-right { background-color: var(--success-color); }
#btn-up { background-color: var(--primary-color); }
#btn-down { background-color: var(--warning-color); }
#btn-history { background-color: var(--success-color); }

.action-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.action-btn.compact {
    background-color: var(--light-color);
    font-size: 0.8rem;
    padding: 6px 8px;
    gap: 4px;
}

/* red reset button */
.action-btn.reset-btn {
    background-color: var(--danger-color);
    color: #fff;
}
.action-btn.reset-btn:hover { filter: brightness(1.1); }


@media (min-width: 600px) {
/* reset confirmation modal */
#reset-modal .modal-content {
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    padding: 30px 25px;
    max-width: 400px;
    margin: auto;
    text-align: center;
}
#reset-modal h2 { margin-bottom: 10px; color: var(--danger-color); }
#reset-modal p { margin-bottom: 20px; }
.reset-modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}
.danger-button {
    background-color: var(--danger-color);
    color: #fff;
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
}
.danger-button:hover { filter: brightness(1.1); }
.cancel-button {
    background-color: #666;
    color: #fff;
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
}
.cancel-button:hover { filter: brightness(1.1); }
} /* close media query */

/* toolbar / button icon size */
.btn-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    vertical-align: middle;
}
@media (min-width: 600px) {
    .btn-icon { margin-right: 4px; }
}

/* toolbar icon images */
.download-btn .count {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--dark-color);
}
.btn-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    vertical-align: middle;
}

@media (min-width: 600px) {
    .btn-icon { margin-right: 4px; }
}

.status-area {
    text-align: left;
}

#last-action {
    font-weight: bold;
    margin-top: 5px;
    margin-bottom: 15px;
}

.swipe-legend {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.9rem;
}

.legend-color {
    display: inline-block;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    margin-right: 8px;
}

.left-color { background-color: var(--danger-color); }
.right-color { background-color: var(--success-color); }
.up-color { background-color: var(--primary-color); }
.down-color { background-color: var(--warning-color); }

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 2000;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

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

.modal-content {
    position: relative;
    width: 90%;
    max-width: 1200px;
    padding: 20px;
}

#fullscreen-image {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--border-radius);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 30px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

.modal-info {
    margin-top: 15px;
    color: white;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    text-align: center;
}

.history-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.selection-item {
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 4px solid transparent; /* default border for action colouring */
}

.selection-item.selected {
    border-width: 12px;
    /* keep existing border-color (set by action) */
    box-shadow: none;
    transform: translateY(-5px);
}

.selection-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.selection-info {
    padding: 15px;
    font-size: 0.9rem;
}

.selection-action { display: none; }

/* Ensure the coloured variants still apply */
.action-left, .action-discard { background-color: var(--danger-color); }
.action-right, .action-keep { background-color: var(--success-color); }
.action-up, .action-favorite { background-color: var(--primary-color); }
.action-down, .action-review { background-color: var(--warning-color); }

/* Reduce icon size so it fits comfortably in the smaller badge */
.selection-action {
    display: none;
}

/* Apply coloured border based on contained action element */
.selection-item:has(.action-discard) { border-color: var(--danger-color); }
.selection-item:has(.action-keep) { border-color: var(--success-color); }
.selection-item:has(.action-favorite) { border-color: var(--primary-color); }
.selection-item:has(.action-review) { border-color: var(--warning-color); }

/* Legacy directional classes retained for compatibility (colours reapplied above) */
.action-left { background-color: var(--danger-color); }
.action-right { background-color: var(--success-color); }
.action-up { background-color: var(--primary-color); }
.action-down { background-color: var(--warning-color); }

/* New semantic action colors */
.action-discard { background-color: var(--danger-color); }
.action-keep { background-color: var(--success-color); }
.action-favorite { background-color: var(--primary-color); }
.action-review { background-color: var(--warning-color); }

.selection-checkbox-container {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 5;
}

.selection-checkbox {
    width: 20px;
    height: 20px;
}

.selection-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    opacity: 0;
    transition: opacity 0.3s;
}

.selection-item:hover .selection-controls {
    opacity: 1;
}

.control-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1rem;
}

@media (min-width: 992px) {
    /* Use full vertical space on desktop */
    .swipe-container {
        min-height: calc(100vh - 180px); /* header + paddings approx */
    }
    .action-btn {
        padding: 10px 20px;
        font-size: 1rem;
    }
    .action-btn .label {
        display: none;
    }
    .action-btn .symbol {
        font-size: 1.2rem;
    }
    .action-btn.left .symbol::before {
        content: "\2190";
    }
    .action-btn.right .symbol::before {
        content: "\2192";
    }
    .action-btn.up .symbol::before {
        content: "\2191";
    }
    .action-btn.down .symbol::before {
        content: "\2193";
    }
}

/* ---------------- MOBILE VIEW TWEAKS ---------------- */
@media (max-width: 767px) {
    /* tighter spacing between panels */
    .side-panel {
        gap: 10px;
    }
    .filter-controls,
    .action-buttons,
    .status-area {
        padding: 10px;
    }
    /* combined action buttons */
    .action-buttons {
        flex-direction: row;
        gap: 0;
    }
    .action-buttons .action-btn {
        flex: 1;
        border-radius: 0;
        padding: 16px 0;
    }
    /* minimal spacing between blocks */
    .side-panel > * + * {
        margin-top: 4px;
        border-top: 1px solid #ccc;
    }
}

/* ---------------- DESKTOP 2x2 ACTION GRID ---------------- */
@media (min-width: 992px) {
    .action-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 10px;
    }
    .action-buttons .action-btn {
        height: 120px;
    }
    .action-buttons .action {
        width: 60px;
        height: 60px;
    }
}

/* ---------------- MOBILE ORIENTATION BUTTONS ---------------- */
@media (max-width: 991px) {
    .orientation-filters {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
    }
    .orientation-filters .filter-btn {
        padding: 15px;
        border: none;
        border-radius: var(--border-radius);
        background-color: var(--light-color);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .orientation-filters .filter-btn .orientation, .action-filter {
        width: 24px;
        height: 24px;
    }
    .orientation-filters .filter-btn:not(.active) {
        background-color: #444;
        opacity: 0.9;
    }
    .orientation-filters .filter-btn.active {
        background-color: var(--primary-color);
        color: #fff;
    }
}

/* ---------------- DESKTOP VIEW ORIENTATION SYMBOLS ---------------- */
@media (min-width: 992px) {
    .filter-btn .text { display:none; }
    .filter-btn::after { content: attr(data-symbol); }
}

/* ---------------- CHANGE ACTION MODAL ---------------- */
#action-modal .modal-content {
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    padding: 30px 20px;
    max-width: 500px;
    margin: auto;
    position: relative;
    text-align: center;
}
#action-modal h2 {
    margin-bottom: 15px;
    color: var(--dark-color);
}
#modal-image-preview {
    max-width: 100%;
    margin-bottom: 20px;
}
#modal-preview-img {
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}
#action-modal .action-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 10px;
}
#action-modal .action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 100px;
    font-size: 0.9rem;
    font-weight: bold;
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
}
#action-modal .action-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}
#action-modal .action-btn[data-action="left"],
#action-modal .action-btn.discard { background-color: var(--danger-color); }
#action-modal .action-btn[data-action="right"],
#action-modal .action-btn.keep { background-color: var(--success-color); }
#action-modal .action-btn[data-action="up"],
#action-modal .action-btn.favorite { background-color: var(--primary-color); }
#action-modal .action-btn[data-action="down"],
#action-modal .action-btn.review { background-color: var(--warning-color); }
#action-modal .close-modal {
    top: 10px;
    right: 15px;
}
/* Prompt textarea */
.prompt-text {
    width: 100%;
    max-height: 200px;
    min-height: 80px;
    resize: vertical;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: var(--border-radius);
    background: #fafafa;
    color: var(--dark-color);
}

/* Orientation icon */
.orientation,
.action-filter {
    width: 24px;
    height: 24px;
}

.action-filters {
    margin-top: 10px;
}

/* Logo styling */
.logo-wide {
    width: 25%;
    height: auto;
    display: block;
}
.logo-half { max-width: 50%; height: auto; display: inline-block; }

/* -------- Global action button tweaks -------- */
.action-btn {
    font-size: 1.2rem;
}
.action { width: 40px; height: 40px; }

/* ---------------- HISTORY PAGE OVERRIDES ---------------- */

/* Hide logo on mobile (<=992px) */
@media (max-width: 992px) {
  .logo-wide {
    display: none;
  }
}

.history-actions .action-btn {
    height: 80px;
    padding: 24px 12px;
    font-size: 1.1rem;
}
.history-actions .action-btn .label { display: inline-block; }

.history-actions {
    display: flex;
    flex-direction: row;
    gap: 10px;
    justify-content: center;
    margin: 12px 0;
}
.history-actions .action-btn {
    flex: 1 1 0;
    padding: 10px;
    font-size: 0.9rem;
}
/* Hide filter section headers on history page (and anywhere) */
.filter-section h4 { display: none; }
/* Add spacing between filter rows */
.filter-section { margin-bottom: 16px; }

@media (max-width: 992px) {
    /* Keep history button row above images on mobile */
    .history-actions { order: 0; }

    .container {
        padding: 10px;
    }
    .main-section {
        flex-direction: column;
    }
    .side-panel {
        position: static;
        width: 100%;
    }
    /* Action buttons placed directly below image viewer and compacted */
    .action-buttons {
        order: 1;                 /* ensure first item in side-panel */
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        gap: 6px;
        padding: 8px 0;
    }

    /* Other panels follow beneath */
    .filter-controls {
        order: 2;
        margin-top: 12px;
    }
    .status-area {
        order: 3;
        margin-top: 12px;
    }

    /* Compact button style */
    .action-btn {
        flex: 1;
        padding: 10px;
        gap: 4px;
        font-size: 0.85rem; /* slightly smaller text */
    }
    /* Keep text labels visible for clarity in mobile view */
    .action-btn .label {
        display: inline;
    }
    .swipe-container {
        min-height: 70vh;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .swipe-legend {
        display: none;
    }
}
