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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    min-height: 100vh;
    position: relative;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: -1;
}

body.pull-mode-active::before {
    opacity: 1;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: -1;
}

body.move-mode-active::after {
    opacity: 1;
}

.container {
    margin: 10px;
    max-width: 100%;
    width: 100%;
}

h1 {
    color: white;
    text-align: center;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    padding: 0 100px 0 20px;
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

h1 span {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.help-button {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid white;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    text-shadow: none;
    margin-left: 15px;
}

.help-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.controls {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.controls button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: #667eea;
    color: white;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.controls button:hover {
    background: #5568d3;
}

.controls button.secondary {
    background: #6c757d;
}

.controls button.secondary:hover {
    background: #5a6268;
}

.controls button.active {
    background: #28a745;
}

.controls button.active:hover {
    background: #218838;
}


.controls input[type="file"] {
    display: none;
}

.controls label {
    padding: 10px 20px;
    border-radius: 8px;
    background: #6c757d;
    color: white;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.controls label:hover {
    background: #5a6268;
}

.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 30px;
    margin-bottom: 30px;
}

.page {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.page:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0,0,0,0.4);
}

.page-header {
    text-align: center;
    margin-bottom: 15px;
    font-weight: 600;
    color: #333;
    font-size: 18px;
}

.page-value {
    position: absolute;
    bottom: 12px;
    right: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
    background: #e8e6fa;
    border: 1px solid #667eea;
    border-radius: 6px;
    padding: 4px 8px;
}

.cards-grid {
    display: grid;
    gap: 8px;
}

.card {
    border-radius: 8px;
    border: 2px solid #ddd;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    background: #fff;
    min-height: 100px;
    cursor: pointer;
}

.card:hover {
    transform: translateY(-2px);
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    z-index: 10;
}

.card.pulling {
    animation: pullCard 0.5s ease-out forwards;
    pointer-events: none;
}

@keyframes pullCard {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(-100px);
        opacity: 0;
    }
}

.card.pull-progress {
    border-color: #dc3545;
    position: relative;
}

.pull-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: #dc3545;
    transition: width 0.1s linear;
    border-radius: 0 0 6px 6px;
}

.card.recently-added {
    border-left: 4px solid #28a745;
    background: linear-gradient(to right, rgba(40, 167, 69, 0.08), #fff);
}

.card.draggable-card {
    cursor: move;
}

.card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.card.drag-over {
    border-color: #667eea;
    border-width: 3px;
    background: rgba(102, 126, 234, 0.1);
}

.card.empty.drop-target {
    border-style: solid;
    border-color: #667eea;
}

.card.empty {
    background: #f0f0f0;
    border: 2px dashed #ccc;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    color: #999;
    font-size: 14px;
}

.card-empty-label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-index {
    background: rgba(102, 126, 234, 0.9);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 6px;
    text-align:center;
}

.card.empty .card-index {
    background: rgba(153, 153, 153, 0.7);
    flex-shrink: 0;
}

.card-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 4px;
}

.card-number {
    font-size: 12px;
    color: #666;
}

.card-condition {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

.card-value {
    font-size: 13px;
    font-weight: 600;
    color: #667eea;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #eee;
}

.card-entered {
    font-size: 11px;
    color: #888;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #eee;
    cursor: default;
}

.stats {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.stat-item {
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
}
.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #667eea;
}
.stat-label {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

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

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-height:50%;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #333;
}

.modal-content label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #666;
}

.modal-content input {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 14px;
}

.modal-content input:focus {
    outline: none;
    border-color: #667eea;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.modal-buttons button.primary {
    background: #667eea;
    color: white;
}

.modal-buttons button.primary:hover {
    background: #5568d3;
}

.modal-buttons button.secondary {
    background: #6c757d;
    color: white;
}

.modal-buttons button.secondary:hover {
    background: #5a6268;
}

.modal-buttons button.danger {
    background: #dc3545;
    color: white;
}

.modal-buttons button.danger:hover {
    background: #c82333;
}

.modal-buttons {
    justify-content: space-between;
}

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

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

/* Utility classes */
.hidden {
    display: none;
}

/* Page size controls */
.page-size-label {
    display: flex;
    align-items: center;
    gap: 5px;
}

.page-size-text {
    font-size: 14px;
}

.page-size-select {
    border: 2px solid #ddd;
    border-radius: 6px;
}


/* Modal content variants */
.modal-content-large {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content-medium {
    max-width: 600px;
}

/* Sort modal styles */
.sort-section {
    margin-bottom: 20px;
}

.sort-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
}

.sort-select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.sort-preview-info {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.sort-preview-swaps {
    margin-bottom: 20px;
}

/* Bulk insert modal styles */
.bulk-insert-description {
    margin-bottom: 15px;
    color: #666;
    font-size: 14px;
}

.bulk-insert-textarea {
    width: 100%;
    min-height: 200px;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: monospace;
    resize: vertical;
}

.bulk-insert-status {
    margin-top: 10px;
    padding: 10px;
    border-radius: 8px;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    body {
        padding: 10px;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .container {
        margin: 5px;
        max-width: 100vw;
        width: 100%;
        box-sizing: border-box;
    }

    h1 {
        font-size: 20px;
        margin-bottom: 15px;
        padding: 0 90px 0 10px;
    }

    .help-button {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    #renameBinderBtn {
        right: 50px;
    }

    .controls {
        padding: 15px;
        gap: 8px;
        margin-bottom: 20px;
    }

    .controls button,
    .controls label {
        padding: 12px 16px;
        font-size: 13px;
        min-height: 44px;
        flex: 1 1 auto;
        min-width: calc(50% - 4px);
    }

    .page-size-label {
        flex-direction: column;
        align-items: stretch;
        min-width: calc(50% - 4px);
    }

    .page-size-text {
        margin-bottom: 5px;
    }

    .page-size-select {
        width: 100%;
        padding: 12px;
        font-size: 13px;
        min-height: 44px;
    }

    .pages-grid {
        grid-template-columns: 1fr;
        gap: 20px;
        margin-bottom: 20px;
    }

    .page {
        padding: 15px;
    }

    .page-header {
        font-size: 16px;
        margin-bottom: 12px;
    }

    .page-value {
        font-size: 12px;
        bottom: 8px;
        right: 8px;
    }

    .card {
        min-height: 80px;
    }

    .card-info {
        padding: 10px;
    }

    .card-name {
        font-size: 13px;
    }

    .card-number {
        font-size: 11px;
    }

    .card-condition {
        font-size: 10px;
    }

    .card-value {
        font-size: 12px;
    }

    .card-entered {
        font-size: 10px;
        margin-top: 4px;
        padding-top: 4px;
    }

    .card-index {
        font-size: 10px;
        padding: 2px 5px;
    }

    .cards-grid {
        gap: 6px;
    }

    .stats {
        padding: 15px;
        margin-bottom: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 11px;
    }

    .modal-content {
        width: 95%;
        max-width: 95%;
        padding: 20px;
        margin: 10px;
        max-height: 90vh;
    }

    .modal-content-large {
        max-width: 95%;
        max-height: 90vh;
    }

    .modal-content-medium {
        max-width: 95%;
    }

    .modal-content h2 {
        font-size: 18px;
        margin-bottom: 15px;
    }

    #bulkInsertModal .modal-content {
        padding: 15px;
    }

    #bulkInsertModal .modal-content h2 {
        margin-bottom: 10px;
    }

    .modal-content input,
    .modal-content textarea,
    .sort-select {
        padding: 12px;
        font-size: 16px;
        min-height: 44px;
    }

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

    .modal-buttons .left,
    .modal-buttons .right {
        width: 100%;
        flex-direction: column;
    }

    .modal-buttons button {
        width: 100%;
        padding: 14px;
        font-size: 16px;
        min-height: 44px;
    }

    .bulk-insert-description {
        margin-bottom: 10px;
        font-size: 13px;
        line-height: 1.4;
    }

    .bulk-insert-description br {
        display: none;
    }

    .bulk-insert-description strong {
        display: block;
        margin-top: 4px;
    }

    #bulkInsertModal label {
        display: none;
    }

    .bulk-insert-textarea {
        min-height: 200px;
        font-size: 16px;
        margin-top: 0;
    }

    .bulk-insert-status {
        margin-top: 8px;
        padding: 8px;
        font-size: 14px;
    }

    .sort-preview-info {
        padding: 12px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .container {
        margin: 0;
    }

    h1 {
        font-size: 18px;
        margin-bottom: 10px;
        padding: 0 85px 0 5px;
    }

    #renameBinderBtn {
        right: 45px;
    }

    .controls {
        padding: 12px;
        gap: 6px;
    }

    .controls button,
    .controls label {
        min-width: 100%;
        font-size: 12px;
        padding: 10px 12px;
    }

    .page-size-label {
        min-width: 100%;
    }

    .page {
        padding: 12px;
    }

    .card {
        min-height: 70px;
    }

    .cards-grid {
        gap: 5px;
    }

    .card-info {
        padding: 8px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        padding: 15px;
        margin: 5px;
    }
}