/* ========================================
   RESET & BASE
   ======================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    font-size: 14px;
    color: #333;
    background-color: #F0F2F5;
}

/* ========================================
   APP LAYOUT
   ======================================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    width: 300px;
    min-width: 300px;
    height: 100vh;
    background-color: #FFFFFF;
    border-right: 1px solid #DDD;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 0;
}

.sidebar-title {
    font-size: 20px;
    font-weight: 700;
    padding: 20px 16px;
    border-bottom: 1px solid #EEE;
    color: #2C3E50;
}

/* ========================================
   ACCORDION
   ======================================== */
.accordion {
    border-bottom: 1px solid #EEE;
}

.accordion-header {
    width: 100%;
    padding: 14px 16px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 600;
    color: #2C3E50;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.accordion-header:hover {
    background-color: #F5F7FA;
}

.accordion-header span {
    font-size: 10px;
    display: inline-block;
    transition: transform 0.2s;
    width: 12px;
}

.accordion-header.active span {
    transform: rotate(0deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 16px;
}

.accordion-content.open {
    max-height: 1000px;
    padding: 0 16px 16px 16px;
}

/* ========================================
   FORM CONTROLS
   ======================================== */
.accordion-content label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #555;
    margin-bottom: 12px;
}

.accordion-content select,
.accordion-content input[type="color"] {
    width: 100%;
    margin-top: 4px;
    padding: 6px 8px;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    background-color: #FAFAFA;
    cursor: pointer;
}

.accordion-content select:hover,
.accordion-content input[type="color"]:hover {
    border-color: #AAA;
}

.accordion-content select:focus,
.accordion-content input[type="color"]:focus {
    outline: none;
    border-color: #3498DB;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.accordion-content input[type="color"] {
    height: 36px;
    padding: 2px 4px;
}

/* Slider + Number Input Row */
.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.input-row input[type="range"] {
    flex: 1;
    cursor: pointer;
    accent-color: #3498DB;
}

.input-row input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
    color: #333;
    background-color: #FAFAFA;
}

.input-row input[type="number"]:focus {
    outline: none;
    border-color: #3498DB;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

/* Toggle / Checkbox */
.toggle-label {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    flex-direction: row !important;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3498DB;
}

/* ========================================
   SIDEBAR BUTTONS
   ======================================== */
.sidebar-buttons {
    padding: 16px;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-top: 1px solid #EEE;
}

.btn {
    padding: 12px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: #2C3E50;
    color: #FFFFFF;
}

.btn-primary:hover {
    background-color: #34495E;
}

.btn-secondary {
    background-color: #FFFFFF;
    color: #2C3E50;
    border: 1px solid #DDD;
}

.btn-secondary:hover {
    background-color: #F5F7FA;
}

.btn-nav {
    background-color: #FFFFFF;
    color: #2C3E50;
    border: 1px solid #DDD;
    padding: 8px 16px;
    font-size: 18px;
}

.btn-nav:hover {
    background-color: #F5F7FA;
}

.btn-nav:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================================
   PREVIEW AREA
   ======================================== */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
    background-color: #F0F2F5;
}

.preview-header {
    margin-bottom: 16px;
}

/* Loading & Error States */
.loading {
    font-size: 16px;
    color: #777;
    text-align: center;
    padding: 40px;
}

.loading::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

.error {
    font-size: 14px;
    color: #E74C3C;
    text-align: center;
    padding: 20px;
    background-color: #FDEDEC;
    border: 1px solid #F5C6CB;
    border-radius: 6px;
    max-width: 500px;
}

/* Preview Container */
.preview-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* Page Preview — the white "page" */
.page-preview {
    background-color: #FFFFFF;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    border-radius: 2px;
    position: relative;
    /* Aspect ratio matches 11" x 8.5" landscape */
    width: 770px;
    height: 595px;
    overflow: hidden;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 16px;
}

#page-indicator {
    font-size: 14px;
    font-weight: 500;
    color: #555;
    min-width: 120px;
    text-align: center;
}

/* ========================================
   CARD PREVIEW (rendered inside page)
   ======================================== */
.card-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    /* We'll position cards absolutely for precise placement */
}

.card {
    position: absolute;
    background-color: #FFFFFF;
    border: 1px solid #E0E0E0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-banner {
    width: 100%;
    display: flex;
    align-items: center;
    background-color: #2C3E50;
    color: #FFFFFF;
    font-weight: bold;
}

.card-description {
    flex: 1;
    color: #000000;
    overflow: hidden;
    word-wrap: break-word;
}

.card-separator {
    height: 1px;
    background-color: #CCCCCC;
}

.card-category {
    color: #666666;
    word-wrap: break-word;
}

/* Crop marks */
.crop-mark {
    position: absolute;
    background-color: #000000;
}

.crop-mark-h {
    height: 0.5px;
}

.crop-mark-v {
    width: 0.5px;
}

/* ========================================
   SCROLLBAR STYLING (sidebar)
   ======================================== */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: #CCC;
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background-color: #AAA;
}

/* ========================================
   RESPONSIVE — smaller screens
   ======================================== */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        height: auto;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid #DDD;
    }

    .preview-area {
        padding: 16px;
    }

    .page-preview {
        width: 100%;
        height: auto;
        aspect-ratio: 11 / 8.5;
    }
}
/* ========================================
   COLOR GROUPS BUTTON
   ======================================== */
.btn-color-groups {
    width: 100%;
    padding: 8px 12px;
    background-color: #F5F7FA;
    color: #2C3E50;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 4px;
    transition: background-color 0.2s;
}

.btn-color-groups:hover {
    background-color: #E8ECF1;
}

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

.modal {
    background-color: #FFFFFF;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Modal Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #EEE;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: #2C3E50;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #333;
}

/* Modal Body */
.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Modal Footer */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #EEE;
}

/* ========================================
   GROUPS SECTION
   ======================================== */
.groups-section {
    margin-bottom: 24px;
}

.groups-section h3,
.table-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #2C3E50;
    margin-bottom: 12px;
}

.groups-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

/* Individual Group Row */
.group-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background-color: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
}

.group-color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid #DDD;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    position: relative;
}

.group-color-swatch input[type="color"] {
    position: absolute;
    top: -4px;
    left: -4px;
    width: 36px;
    height: 36px;
    border: none;
    cursor: pointer;
    padding: 0;
}

.group-name-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    background-color: #FFFFFF;
}

.group-name-input:focus {
    outline: none;
    border-color: #3498DB;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.group-count {
    font-size: 11px;
    color: #999;
    min-width: 50px;
    text-align: right;
}

.group-delete-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: #CCC;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

.group-delete-btn:hover {
    color: #E74C3C;
}

.btn-add-group {
    padding: 8px 16px;
    background-color: #FFFFFF;
    color: #3498DB;
    border: 1px dashed #3498DB;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-add-group:hover {
    background-color: #EBF5FB;
}

/* ========================================
   EMOTION TABLE SECTION
   ======================================== */
.table-section {
    margin-top: 8px;
}

.table-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.emotion-search {
    padding: 8px 12px;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 13px;
    color: #333;
    width: 220px;
    background-color: #FAFAFA;
}

.emotion-search:focus {
    outline: none;
    border-color: #3498DB;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.sort-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #777;
}

.btn-sort {
    padding: 4px 10px;
    background-color: #F5F7FA;
    color: #555;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-sort:hover {
    background-color: #E8ECF1;
}

.btn-sort.active {
    background-color: #2C3E50;
    color: #FFFFFF;
    border-color: #2C3E50;
}

/* Table */
.table-wrapper {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
}

.emotion-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.emotion-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.emotion-table th {
    background-color: #F9FAFB;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 1px solid #E5E7EB;
    font-size: 12px;
}

.emotion-table th:first-child {
    width: 40px;
    text-align: center;
}

.emotion-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #F0F0F0;
    color: #333;
}

.emotion-table td:first-child {
    text-align: center;
}

.emotion-table tbody tr:hover {
    background-color: #F5F7FA;
}

.emotion-table tbody tr:last-child td {
    border-bottom: none;
}

/* Color indicator dot in table */
.color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid #DDD;
}

/* Group dropdown in table */
.group-select {
    padding: 4px 8px;
    border: 1px solid #DDD;
    border-radius: 4px;
    font-size: 12px;
    color: #333;
    background-color: #FAFAFA;
    cursor: pointer;
    min-width: 120px;
}

.group-select:focus {
    outline: none;
    border-color: #3498DB;
}

/* Hidden row (filtered out by search) */
.emotion-table tbody tr.hidden {
    display: none;
}

/* ========================================
   MODAL RESPONSIVE
   ======================================== */
@media (max-width: 600px) {
    .modal {
        width: 98%;
        max-height: 95vh;
    }

    .table-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .emotion-search {
        width: 100%;
    }

    .sort-controls {
        justify-content: flex-start;
    }
}