/* Copyright (c) 2024-2026. Jericho Crosby (Chalwk) */

:root {
    --primary: #4a86e8;
    --primary-rgb: 74, 134, 232;
    --light: #f9fafb;
    --dark: #111827;
    --gray-light: #e5e7eb;
    --gray: #6b7280;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    --radius-sm: 0.25rem;
    --radius: 0.375rem;
    --radius-lg: 0.5rem;
}

.visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

.app-container {
    display: flex;
    flex-direction: column;
    background: var(--light);
    border: 1px solid var(--gray-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 2rem;
    position: relative;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: var(--primary);
    color: white;
}

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

.header-left h2 {
    font-size: 1.2rem;
    margin: 0;
    color: white;
    font-weight: 600;
}

.header-sub {
    display: flex;
    align-items: center;
}

.header-sub select {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
}

.header-sub select:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

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

.settings-dropdown {
    position: relative;
}

.settings-toggle {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.settings-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

.settings-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    padding: 0.75rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    min-width: 220px;
    margin-top: 0.5rem;
}

.settings-dropdown.active .settings-menu {
    display: block;
}

.settings-group {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-light);
}

.settings-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.settings-group .btn {
    width: 100%;
    margin-bottom: 0.5rem;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    text-align: left;
}

.settings-group .btn:last-child {
    margin-bottom: 0;
}

.settings-group label.btn {
    cursor: pointer;
    display: block;
}

.settings-group label.btn input {
    display: none;
}

.import-label {
    cursor: pointer;
}

.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.phrase-bar {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--light);
    border-bottom: 1px solid var(--gray-light);
    align-items: center;
}

.phrase-display {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex: 1;
    min-height: 48px;
    padding: 0.75rem;
    background: white;
    border-radius: var(--radius);
    align-items: center;
    border: 1px solid var(--gray-light);
    transition: all 0.2s ease;
}

.phrase-display.drag-active {
    background: var(--light);
    border: 2px dashed var(--gray-light);
    min-height: 60px;
}

.phrase-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: var(--light);
    color: var(--dark);
    font-weight: 600;
    cursor: grab;
    user-select: none;
    transition: all 0.2s ease;
    position: relative;
    border: 2px solid transparent;
    min-height: 44px;
    box-shadow: var(--shadow-sm);
}

.phrase-item:active {
    cursor: grabbing;
}

.phrase-item:hover {
    background: #dbe8ff;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.phrase-item.dragging {
    opacity: 0.6;
    transform: scale(0.95);
    box-shadow: var(--shadow-lg);
}

.phrase-item.drag-over {
    border: 2px dashed var(--primary);
    background: #f0f5ff;
}

.phrase-item img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.phrase-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.board-toolbar {
    padding: 1rem 1.5rem;
    background: var(--light);
    border-bottom: 1px solid var(--gray-light);
}

#globalSearch {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--gray-light);
    background: white;
    color: var(--dark);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

#globalSearch:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.1);
}

.board-container {
    flex: 1;
    padding: 1.5rem;
    overflow: auto;
}

.communication-board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
}

.communication-board.fixed-grid {
    gap: 0.75rem;
    padding: 0.75rem;
}

.communication-board.grid-3x4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.communication-board.grid-4x6 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.communication-board.grid-6x8 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.symbol {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: var(--radius);
    background: #e8f0fe;
    color: var(--dark);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-align: center;
    position: relative;
    outline: none;
    min-height: 100px;
    border: 2px solid var(--gray-light);
    box-shadow: var(--shadow-sm);
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.symbol img,
.symbol-emoji {
    max-width: 80%;
    max-height: 70px;
    object-fit: contain;
    margin-bottom: 0.25rem;
    flex-shrink: 1;
}

.symbol-emoji {
    font-size: clamp(1.5rem, 8vw, 2.5rem);
    line-height: 1;
    display: block;
}

.symbol span:last-child {
    font-size: clamp(0.7rem, 2.5vw, 0.9rem);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    max-width: 100%;
    word-break: break-word;
    flex-shrink: 0;
}

.communication-board.fixed-grid .symbol {
    display: grid;
    grid-template-rows: 1fr auto;
    align-items: center;
    justify-items: center;
    padding: 0.25rem;
    aspect-ratio: 1 / 1;
    width: 100%;
    height: auto;
    min-height: 0;
}

.communication-board.fixed-grid .symbol img,
.communication-board.fixed-grid .symbol-emoji {
    max-width: 90%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    margin-bottom: 0;
    align-self: center;
}

.communication-board.fixed-grid .symbol-emoji {
    font-size: clamp(1.2rem, 6vw, 2rem);
    line-height: 1;
}

.communication-board.fixed-grid .symbol span:last-child {
    font-size: clamp(0.6rem, 2vw, 0.8rem);
    -webkit-line-clamp: 2;
    align-self: end;
    width: 100%;
    padding: 0 0.1rem;
}

.symbol.editing::after {
    content: "✏️";
    position: absolute;
    right: 0.25rem;
    top: 0.25rem;
    font-size: 0.9rem;
    z-index: 2;
}

.symbol:focus {
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.2);
    transform: translateY(-2px);
}

.symbol:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
}

.edit-mode .board-container {
    filter: brightness(0.92) saturate(0.98);
}

.floating-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal[aria-hidden="false"] {
    display: flex;
}

.modal-content {
    background: white;
    color: var(--dark);
    width: 100%;
    max-width: 520px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--light);
}

.modal-header h2 {
    margin: 0;
    color: var(--dark);
    font-size: 1.3rem;
}

.modal-body {
    padding: 1.5rem;
}

.close {
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--gray);
    transition: color 0.2s ease;
    background: none;
    border: none;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close:hover {
    color: var(--dark);
}

.form-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group label {
    font-weight: 500;
    color: var(--dark);
}

.form-group input[type="text"],
.form-group select,
.form-group input[type="color"] {
    padding: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--gray-light);
    background: white;
    color: var(--dark);
    font-size: 1rem;
    transition: border-color 0.2s ease;
    font-family: inherit;
}

.form-group input[type="text"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.1);
}

.form-group small {
    font-size: 0.85rem;
    color: var(--gray);
    margin-top: 0.25rem;
}

.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-light);
}

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

.categories-list {
    margin: 1.5rem 0;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    padding: 0.75rem;
}

.category-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--light);
    border-radius: var(--radius);
    border: 1px solid var(--gray-light);
}

.category-item:last-child {
    margin-bottom: 0;
}

.category-name-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: white;
    color: var(--dark);
    font-family: inherit;
}

.category-actions {
    display: flex;
    gap: 0.25rem;
}

.category-actions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.settings-panel {
    margin-bottom: 1.5rem;
}

.settings-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--light);
    border-radius: var(--radius);
    border: 1px solid var(--gray-light);
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    margin-bottom: 1rem;
    color: var(--dark);
    font-size: 1.1rem;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.25rem;
}

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

.settings-section .form-group:last-child {
    margin-bottom: 0;
}

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    min-width: 200px;
    max-width: 320px;
    z-index: 80;
    background: var(--dark);
    color: white;
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.empty-message {
    color: var(--gray);
    font-style: italic;
    padding: 0.5rem;
}

body.clicked-outside .settings-dropdown.active .settings-menu {
    display: none;
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 1rem;
    }

    .header-left {
        flex: 1 1 auto;
        min-width: 200px;
    }

    .header-controls {
        flex: 0 0 auto;
        margin-left: auto;
    }

    .settings-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        margin-top: 0;
        max-height: 70vh;
        overflow-y: auto;
    }

    .communication-board {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }

    .communication-board.fixed-grid {
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .communication-board.grid-6x8 {
        grid-template-columns: repeat(6, minmax(70px, 1fr));
    }

    .communication-board.grid-6x8.fixed-grid .symbol {
        padding: 0.15rem;
    }

    .communication-board.grid-6x8.fixed-grid .symbol-emoji {
        font-size: clamp(1rem, 5vw, 1.5rem);
    }

    .communication-board.grid-6x8.fixed-grid .symbol span:last-child {
        font-size: clamp(0.5rem, 1.8vw, 0.7rem);
    }

    .category-item {
        flex-direction: column;
        align-items: stretch;
    }

    .category-actions {
        justify-content: space-between;
    }

    .floating-btn {
        bottom: 1rem;
        right: 1rem;
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }

    .settings-section {
        padding: 0.75rem;
    }

    .settings-section h3 {
        font-size: 1rem;
    }

    .app-header {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 0.5rem;
        padding: 1rem;
    }

    .header-left {
        display: contents;
    }

    .header-left h2 {
        grid-column: 1;
        grid-row: 1;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-sub {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-self: stretch;
        width: 100%;
        margin-top: 0.25rem;
    }

    .header-sub select {
        width: 100%;
        max-width: none;
    }

    .header-controls {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        margin-left: 0;
    }
}

@media (max-width: 480px) {
    .communication-board {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }

    .communication-board.grid-6x8 {
        grid-template-columns: repeat(6, minmax(60px, 1fr));
    }

    .communication-board.grid-6x8.fixed-grid .symbol-emoji {
        font-size: clamp(0.9rem, 4vw, 1.3rem);
    }

    .communication-board.grid-6x8.fixed-grid .symbol span:last-child {
        font-size: clamp(0.45rem, 1.5vw, 0.6rem);
    }

    .phrase-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .phrase-controls {
        justify-content: center;
    }

    .symbol {
        min-height: 90px;
    }

    .modal-content {
        width: 95%;
        margin: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .form-actions {
        flex-direction: column;
        gap: 1rem;
    }

    .form-actions > div {
        width: 100%;
        justify-content: space-between;
    }

    .phrase-item {
        padding: 0.75rem 1rem;
        min-height: 52px;
    }

    .phrase-display.drag-active {
        border-width: 3px;
    }

    .phrase-item.drag-over {
        border-width: 3px;
        transform: scale(1.05);
    }

    .settings-panel {
        margin-bottom: 1rem;
    }

    .settings-section {
        margin-bottom: 1rem;
        padding: 0.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.symbol:focus,
.phrase-item:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media print {
    .app-header,
    .phrase-bar,
    .floating-btn,
    .settings-dropdown,
    .board-toolbar {
        display: none !important;
    }

    .app-container {
        border: none;
        box-shadow: none;
        border-radius: 0;
    }

    .communication-board {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }
}