/* Add Font Awesome for the external link icon */
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --background-color: #f0f2f7;
    --background-texture: rgba(185, 193, 202, 0.05);
    --card-background: #ffffff;
    --own-card-background: #e8f4f8;
    --text-color: #2c3e50;
    --border-radius: 8px;
    --accent-color: #95a5a6;
    --link-color: #0066cc;
    --link-hover-color: #0056b3;
    --footer-height: 90px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text-color);
    line-height: 1.6;
    background-color: var(--background-color);
    background-image: 
        radial-gradient(var(--background-texture) 1px, transparent 1px),
        radial-gradient(var(--background-texture) 1px, transparent 1px);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
    background-attachment: fixed;
}

header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.connection-counter {
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    background-color: rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.icon-btn:hover {
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

.primary-btn {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

.primary-btn:hover {
    background-color: #2980b9;
}

.secondary-btn {
    background-color: var(--background-color);
    color: var(--text-color);
    border: 1px solid var(--accent-color);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background-color: var(--accent-color);
    color: white;
}

#operatorGrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.operator-card {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 300px;
    position: relative;
}

.operator-card > *:not(.timestamp) {
    flex: 0 0 auto;
}

.operator-card.own-card {
    background-color: var(--own-card-background);
}

.operator-card h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-color);
}

.operator-card .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.operator-card .tag {
    background-color: var(--accent-color);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.8rem;
}

.operator-card .qso-types {
    color: var(--text-color);
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

.operator-card .qso-type-list {
    list-style-type: none;
    padding-left: 0;
    margin: 0.3rem 0;
}

.operator-card .qso-type-list li {
    margin: 0.2rem 0;
    padding-left: 1rem;
    position: relative;
}

.operator-card .qso-type-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--accent-color);
}

.timestamp {
    margin-top: auto;
    text-align: right;
    color: #666;
    font-size: 0.9em;
    padding-top: 0.5rem;
}

.callsign-link {
    color: var(--link-color);
    text-decoration: underline;
    font-weight: bold;
    transition: color 0.2s;
    position: relative;
    padding-right: 1.2em;
}

.callsign-link::after {
    content: "\f35d";  /* Font Awesome external-link-alt icon */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    font-size: 0.8em;
    margin-left: 0.3em;
    top: 0;
}

.callsign-link:hover {
    color: var(--link-hover-color);
    text-decoration: underline;
}

.card-actions {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
}

.edit-btn,
.delete-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.edit-btn {
    color: #666;
}

.edit-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
    color: #333;
}

.delete-btn {
    color: #ff4444;
}

.delete-btn:hover {
    background-color: rgba(255, 68, 68, 0.1);
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.tag {
    background-color: #ecf0f1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.filter-container {
    display: flex;
    justify-content: center;
    padding: 1rem;
    margin-bottom: 1rem;
}

.band-filter {
    padding: 0.6rem 2rem 0.6rem 1rem;
    border: 2px solid var(--accent-color);
    border-radius: 6px;
    font-size: 1rem;
    background-color: white;
    cursor: pointer;
    min-width: 140px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230d6efd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1em;
    transition: all 0.2s ease;
    color: var(--accent-color);
    font-weight: 500;
}

.band-filter:hover {
    border-color: var(--accent-color);
    background-color: rgba(13, 110, 253, 0.04);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(13, 110, 253, 0.15);
}

.band-filter:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
    transform: translateY(-1px);
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding: 1rem;
}

.modal-content {
    background-color: var(--card-background);
    padding: 2rem;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    margin: 1rem auto;
    position: relative;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

@media (max-height: 700px) {
    .modal {
        align-items: flex-start;
    }
    
    .modal-content {
        margin: 0 auto;
        max-height: 100%;
    }
}

@media (max-width: 480px) {
    .modal-content {
        padding: 1rem;
        width: 95%;
        margin: 0.5rem auto;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
    }

    .wpm-range input {
        padding: 0.4rem;  /* Slightly smaller padding on mobile */
    }
    
    /* Comment dialog specific mobile styling */
    /* Keep the modal hidden by default, only apply these styles when it's visible */
    #commentDialog.modal {
        display: none; /* Keep it hidden by default */
    }
    
    #commentDialog.modal[style*="display: block"] {
        display: block !important; /* Override the inline style but only when it should be shown */
        overflow-y: hidden;
        padding: 0;
    }
    
    #commentDialog .modal-content {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: var(--footer-height);
        width: 100%;
        max-width: 100%;
        height: auto;
        margin: 0;
        padding: 1rem;
        border-radius: 0;
        overflow: hidden;
    }
    
    #commentDialog .comment-list {
        flex: 1 1 auto;
        overflow-y: auto;
        height: calc(100% - 180px); /* Reduced form height calculation to give more space to comments */
        min-height: 200px; /* Increased minimum height */
        border: none;
        padding: 0.5rem;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
        overscroll-behavior: contain; /* Prevent scroll chaining */
        position: relative; /* Create stacking context */
    }
    
    /* Add extra space at the bottom of the comment list for iOS scrolling */
    #commentDialog .comment-list::after {
        content: '';
        display: block;
        height: 40px; /* Extra padding at the bottom */
        width: 100%;
    }
    
    #commentDialog .comment-form {
        flex: 0 0 auto;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: var(--card-background);
        padding: 0.5rem 1rem 1rem;
        z-index: 1;
        border-top: 1px solid #eee;
    }
}

.form-group {
    margin-bottom: 1rem;
}

/* New flex container for callsign and frequency */
.form-group.compact-row {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.form-group.compact-row > div {
    flex: 1;
    min-width: 0; /* Allows proper shrinking */
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Optimize input widths */
#callSign {
    width: 8rem;  /* Enough for 7 chars + some padding */
    text-transform: uppercase;
}

#frequency {
    width: 7rem;  /* Enough for frequency + some padding */
}

.wpm-range {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: nowrap;
}

.wpm-range input {
    width: 4rem;  /* Just enough for 2 digits + arrows */
    padding: 0.5rem;
    text-align: center;
}

.wpm-range span {
    white-space: nowrap;
}

@media (max-width: 480px) {
    .modal-content {
        padding: 1rem;
        width: 95%;
        margin: 0.5rem auto;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
    }

    .form-group.compact-row {
        gap: 0.5rem; /* Slightly less gap on mobile */
    }

    #callSign,
    #frequency {
        padding: 0.4rem; /* Slightly less padding on mobile */
    }
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Hide tags section for now */
.form-group.tags {
    display: none;
}

.instructions {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 1.5rem;
    background-color: #f8f9fa;
    border-radius: var(--border-radius);
    color: var(--text-color);
    line-height: 1.6;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.instructions p {
    margin: 0;
    font-size: 1.1rem;
}

.timestamp-label {
    color: #888;
}

.time-value {
    color: #999;
}

.expiration {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    color: #666;
    font-size: 0.9em;
    margin-top: auto;
    padding-top: 0.5rem;
    margin-bottom: 0.25rem;
}

.refresh-btn {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.refresh-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
    color: #333;
    transform: rotate(180deg);
}

.footer-spacer {
    height: calc(var(--footer-height) + 2rem); /* Add extra padding */
    width: 100%;
}

.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background-color: white;
    border-top: 1px solid #eee;
    z-index: 1000;
}

.footer-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0.5rem;
    height: 100%;
}

.brought-by {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    color: #666;
}

.cwi-logo {
    width: 285px;
    height: 42px;
    object-fit: contain;
}

.written-by {
    font-size: 0.8rem;
    color: #666;
}

.written-by a {
    color: var(--link-color);
    text-decoration: none;
}

.written-by a:hover {
    color: var(--link-hover-color);
    text-decoration: underline;
}

.footer-credit {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    font-size: 0.875rem;
    color: #666;
    z-index: 100;
}

.footer-credit a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-credit a:hover {
    color: #2980b9;
    text-decoration: underline;
}

@media (max-width: 900px) {
    #operatorGrid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    #operatorGrid {
        grid-template-columns: 1fr;
    }
    
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .instructions {
        margin: 1rem;
    }
}

/* Comment styles */
.comment-list {
    max-height: 400px; /* Increased max height for desktop */
    overflow-y: auto;
    margin-bottom: 1rem;
    padding: 0.25rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
}

.comment-empty-state {
    text-align: center;
    color: #6c757d;
    padding: 1rem;
    font-style: italic;
}

.comment-item {
    padding: 0.5rem;
    border-bottom: 1px solid #eee;
    margin-bottom: 0.25rem;
}

.comment-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.comment-callsign {
    font-weight: 600;
    color: #0056b3;
    font-size: 0.95rem;
}

.comment-text {
    color: #212529;
    line-height: 1.3;
    font-size: 0.95rem;
}

.comment-timestamp {
    font-size: 0.8rem;
    color: #6c757d;
}

.comment-form textarea {
    width: 100%;
    min-height: 80px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    font-size: 0.95rem;
}

@media (max-width: 480px) {
    .comment-form textarea {
        min-height: 60px;
        max-height: 80px;
    }
}

.char-count {
    text-align: right;
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: -0.5rem;
    margin-bottom: 0.5rem;
}

.comment-btn {
    position: absolute;
    bottom: 0.75rem;  /* Adjusted to match timestamp spacing */
    left: 0.75rem;    /* Adjusted for consistency */
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #495057;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border-radius: 8px;  /* Less rounded corners */
    font-size: 0.9rem;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.comment-btn:hover {
    background-color: #e9ecef;
    border-color: #ced4da;
    color: #212529;
}

.comment-btn i {
    font-size: 0.9rem;
}

.comment-count {
    font-size: 0.9rem;
    font-weight: 500;
}

.comment-btn:active {
    background-color: #e2e6ea;
    transform: translateY(1px);
}

/* No operators message */
.no-operators-message {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 3rem auto;
    padding: 0 1rem;
    box-sizing: border-box;
    grid-column: 1 / -1; /* Make it span all columns in the grid */
}

/* Admin mode styling */
.admin-delete-btn {
    background-color: #ff5252 !important;
    color: white !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem !important;
    border-radius: 4px;
}

.admin-badge {
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
}

.admin-actions {
    margin-top: 0.5rem;
}

.no-operators-message .message-content {
    background-color: var(--card-background);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 500px;
}

.no-operators-message i {
    font-size: 3rem;
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.no-operators-message p {
    margin: 0.5rem 0;
    font-size: 1.1rem;
}

.no-operators-message p:last-child {
    margin-top: 1rem;
    font-weight: 500;
}
