/* ----- RESET & BASE ----- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
    background: #fbe9e7;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* ----- CANDY WRAPPER ----- */
.candy-wrapper {
    width: 100%;
    max-width: min(1200px, 95vw);
    margin: 0 auto;
}

/* ----- MAIN BUTTON PANEL (used in driver/retailer dashboards) ----- */
.button-panel {
    background: rgba(255, 240, 245, 0.7);
    backdrop-filter: blur(6px);
    border-radius: 60px 20px 60px 20px;
    border: 3px solid white;
    box-shadow: 0 20px 30px rgba(0,0,0,0.2);
    padding: clamp(1rem, 5vw, 2.5rem);
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* ----- TITLES ----- */
.candy-title {
    font-size: clamp(1.8rem, 6vw, 2.5rem);
    font-weight: 600;
    color: #4b2e1b;
    text-shadow: 1px 1px 0 #ffb6c1;
    text-align: center;
    margin-bottom: 0.5rem;
}

.candy-subtitle {
    font-family: 'Comic Sans MS', cursive;
    color: #6b3e26;
    margin-bottom: 0.8rem;
    font-size: clamp(1.2rem, 5vw, 1.5rem);
    text-align: center;
}

/* ----- BUTTONS ----- */
.candy-btn {
    background: linear-gradient(145deg, #ffd966, #ffb347);
    border: none;
    border-radius: 50px;
    padding: 0.6rem 1.5rem;
    font-size: clamp(1rem, 4vw, 1.2rem);
    font-weight: bold;
    color: #4b2e1b;
    border-bottom: 5px solid #c96b2e;
    box-shadow: 0 8px 0 #a0522d;
    cursor: pointer;
    transition: 0.1s;
}
.candy-btn:active {
    transform: translateY(5px);
    box-shadow: 0 3px 0 #a0522d;
}

.candy-btn-small {
    background: #ffb347;
    border: none;
    border-radius: 40px;
    padding: 0.5rem 1rem;
    color: white;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 0 #c96b2e;
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    transition: 0.1s;
}
.candy-btn-small:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #c96b2e;
}
.candy-btn-small.active {
    background: #ff6f91;
    box-shadow: 0 3px 0 #c71585;
}

/* ----- INPUTS ----- */
.candy-input {
    background: #fff9f0;
    border: 3px solid #ff85a2;
    border-radius: 50px;
    padding: 12px 20px;
    font-size: 1rem;
    outline: none;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1), 0 5px 0 #d64f6b;
}

/* ----- POSTCODE SEARCH SECTION ----- */
.candy-postcode-search {
    background: rgba(255, 240, 245, 0.9);
    border-radius: 40px;
    padding: clamp(1rem, 4vw, 1.5rem);
    margin: 1rem 0;
    border: 2px solid white;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.postcode-input-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.candy-error {
    color: #d64f6b;
    font-weight: bold;
    margin-top: 8px;
    text-align: center;
}
.location-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 15px 0;
}

/* ----- MAP ----- */
#map {
    height: 400px;
    width: 100%;
    border-radius: 20px;
    border: 3px solid white;
    margin-top: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

/* ----- SHOP INFO (golden box) ----- */
.candy-shop-info {
    background: rgba(255,215,0,0.3);
    border-radius: 40px;
    padding: 10px 20px;
    margin: 10px 0;
    font-weight: bold;
    border: 2px solid gold;
    color: #8b4513;
    text-align: center;
}

/* ----- DRIVER LIST (on retailer side) ----- */
.candy-driver-list {
    background: rgba(255, 240, 245, 0.9);
    border-radius: 30px;
    padding: clamp(1rem, 4vw, 1.5rem);
    margin-top: 20px;
    border: 2px solid white;
}
.candy-list {
    list-style: none;
    padding: 0;
}
.candy-list li {
    background: linear-gradient(145deg, #fff0f5, #ffe4e1);
    margin: 10px 0;
    padding: 12px 20px;
    border-radius: 50px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    box-shadow: 0 5px 0 #d291bc;
    border: 1px solid white;
}
.driver-coords {
    font-size: 0.8rem;
    color: #555;
    margin-left: auto;
}
.ping-btn {
    background: #ffb347;
    border: none;
    border-radius: 40px;
    padding: 5px 15px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 0 #c96b2e;
    transition: 0.1s;
}
.ping-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #c96b2e;
}
.candy-list li.selected-driver {
    background: linear-gradient(145deg, #ffb3ba, #ff6f91);
    border: 3px solid #ff1493;
    font-weight: bold;
    box-shadow: 0 5px 0 #c71585;
}

/* ----- RETAILER LIST (on driver side, nearby shops) ----- */
.candy-retailer-list-container {
    background: rgba(255, 240, 245, 0.9);
    border-radius: 30px;
    padding: 15px;
    margin: 15px 0;
    border: 2px solid white;
}
.candy-retailer-list-container h4 {
    margin: 0 0 10px 0;
    cursor: pointer;
    user-select: none;
    font-size: 1.1rem;
}
.retailer-list {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9rem;
}
.retailer-list.collapsed {
    max-height: 0;
    overflow: hidden;
}
.retailer-item {
    background: rgba(255,255,255,0.5);
    border-radius: 15px;
    padding: 8px 12px;
    margin: 5px 0;
    border-left: 5px solid;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.retailer-item.online { border-left-color: #4CAF50; background: #e8f5e8; }
.retailer-item.offline { border-left-color: #9e9e9e; background: #f5f5f5; }
.retailer-item .name { font-weight: bold; }
.retailer-item .distance { font-size: 0.8rem; color: #666; }

/* ----- OFFER HISTORY SECTIONS ----- */
.candy-history-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
    width: 100%;
}
.history-section {
    background: rgba(255, 240, 245, 0.9);
    border-radius: 30px;
    padding: 15px;
    border: 2px solid white;
}
.history-section h4 {
    margin: 0 0 10px 0;
    cursor: pointer;
    user-select: none;
    font-size: 1.1rem;
}
.history-list {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9rem;
    transition: max-height 0.2s;
}
.history-list.collapsed {
    max-height: 0;
    overflow: hidden;
}
.history-item {
    background: rgba(255,255,255,0.5);
    border-radius: 15px;
    padding: 8px 12px;
    margin: 5px 0;
    border-left: 5px solid;
}
.history-item.accepted { border-left-color: #4CAF50; background: #e8f5e8; }
.history-item.countered { border-left-color: #FFC107; background: #fff3cd; }
.history-item.rejected { border-left-color: #f44336; background: #ffebee; }
.history-item small { display: block; color: #666; }

/* ----- EXPANDABLE ACCEPTED OFFERS (driver side) ----- */
.history-item.accepted {
    cursor: pointer;
}
.history-item.accepted .history-summary {
    /* summary styling */
}
.history-item.accepted .history-details {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #aaa;
    font-size: 0.9rem;
}
.history-item.accepted.expanded {
    background: rgba(255,215,0,0.1);
}
.history-item.accepted .history-details a {
    color: #0066cc;
    text-decoration: none;
    font-weight: bold;
}
.history-item.accepted .history-details a:hover {
    text-decoration: underline;
}

/* ----- OFFER CARD (fixed overlay) ----- */
.offer-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(3px);
}
.candy-offer-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    background: rgba(255, 240, 245, 0.98);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    border: 4px solid #ff85a2;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    padding: 20px;
    text-align: center;
    display: none;
    z-index: 1000;
}
.candy-offer-card h3 {
    color: #6b3e26;
    margin-bottom: 10px;
}
.candy-offer-card p {
    margin: 5px 0;
    font-size: 1.1rem;
}
.retailer-address {
    background: rgba(255,215,0,0.2);
    border-radius: 20px;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid gold;
}
.retailer-address a {
    color: #0066cc;
    text-decoration: none;
    font-weight: bold;
}
.offer-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 15px 0;
}
.offer-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ----- MODAL (candy themed) ----- */
.candy-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s;
}
.candy-modal.show {
    opacity: 1;
    visibility: visible;
}
.candy-modal-content {
    background: rgba(255, 240, 245, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 60px 20px 60px 20px;
    border: 3px solid white;
    box-shadow: 0 20px 30px rgba(0,0,0,0.3);
    padding: 30px 25px;
    max-width: 350px;
    width: 90%;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.2s ease;
}
.candy-modal.show .candy-modal-content {
    transform: scale(1);
}
.candy-modal h3 {
    font-family: 'Comic Sans MS', cursive;
    font-size: 1.8rem;
    color: #6b3e26;
    margin-bottom: 15px;
    text-shadow: 2px 2px 0 #ffb6c1;
}
.candy-modal p {
    font-size: 1.1rem;
    color: #5a2e1a;
    margin: 10px 0;
    line-height: 1.4;
    white-space: pre-wrap;
}
.candy-modal input,
.candy-modal textarea {
    width: 100%;
    padding: 12px 15px;
    border: 3px solid #ff85a2;
    border-radius: 50px;
    background: #fff9f0;
    font-size: 1rem;
    margin: 10px 0;
    box-sizing: border-box;
}
.candy-modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}
.candy-modal-btn {
    background: linear-gradient(145deg, #ffd966, #ffb347);
    border: none;
    border-radius: 50px;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    color: #4b2e1b;
    border-bottom: 4px solid #c96b2e;
    box-shadow: 0 5px 0 #a0522d;
    cursor: pointer;
    transition: 0.1s;
    min-width: 80px;
}
.candy-modal-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #a0522d;
}
.candy-modal-btn.accept {
    background: linear-gradient(145deg, #a5d6a5, #66bb6a);
    border-bottom-color: #2e7d32;
    box-shadow: 0 5px 0 #1b5e20;
    color: white;
}
.candy-modal-btn.reject {
    background: linear-gradient(145deg, #ef9a9a, #ef5350);
    border-bottom-color: #b71c1c;
    box-shadow: 0 5px 0 #8b0000;
    color: white;
}
.candy-modal-btn.counter {
    background: linear-gradient(145deg, #ffe082, #ffb74d);
    border-bottom-color: #bf360c;
    box-shadow: 0 5px 0 #b26a00;
}

/* ----- TOAST NOTIFICATIONS ----- */
.candy-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.candy-toast {
    background: rgba(255, 240, 245, 0.95);
    backdrop-filter: blur(5px);
    border: 3px solid white;
    border-radius: 50px 20px 50px 20px;
    padding: 12px 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    color: #4b2e1b;
    font-weight: bold;
    font-size: 1rem;
    max-width: 300px;
    pointer-events: auto;
    animation: slideIn 0.3s ease;
}
.candy-toast.sticky {
    cursor: pointer;
    background: rgba(255, 240, 245, 0.98);
    border: 3px solid #ff85a2;
}
.candy-toast .close-btn {
    float: right;
    font-weight: bold;
    margin-left: 10px;
    cursor: pointer;
    color: #6b3e26;
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.candy-toast.fade-out {
    animation: fadeOut 0.3s ease forwards;
}
@keyframes fadeOut {
    to { transform: translateX(100%); opacity: 0; }
}
.toast-success {
    background: rgba(165, 214, 167, 0.95);
}
.toast-error {
    background: rgba(239, 154, 154, 0.95);
}
.toast-info {
    background: rgba(255, 240, 245, 0.95);
}

/* ----- SCREEN INFO (bottom right corner) ----- */
.screen-info {
    position: fixed;
    bottom: 10px;
    right: 16px;
    background: rgba(255, 240, 245, 0.9);
    backdrop-filter: blur(6px);
    color: #6b3e26;
    font-size: 0.9rem;
    padding: 6px 16px;
    border-radius: 40px;
    border: 2px solid white;
    box-shadow: 0 5px 10px rgba(0,0,0,0.2);
    z-index: 999;
    font-weight: bold;
}

/* ----- DEBUG PANEL (only shown when ?debug=1) ----- */
#debugPanel {
    position: fixed;
    bottom: 10px;
    left: 10px;
    right: 10px;
    background: rgba(0,0,0,0.85);
    color: #0f0;
    font-family: monospace;
    font-size: 11px;
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
    z-index: 10000;
    border-radius: 12px;
    border: 2px solid #ff85a2;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

/* ----- RESPONSIVE FINE-TUNING ----- */
@media (max-width: 600px) {
    .candy-list li {
        flex-direction: column;
        align-items: flex-start;
    }
    .driver-coords {
        margin-left: 0;
    }
    .ping-btn {
        align-self: flex-end;
    }
    .postcode-input-group {
        flex-direction: column;
    }
    .candy-input {
        width: 100%;
    }
}