/* Global Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    /* Dark Mode Color Palette */
    --primary-color: #6366f1;
    --primary-light: rgba(99, 102, 241, 0.15);
    --primary-dark: #4f46e5;
    --secondary-color: #94a3b8;
    --text-color: #e2e8f0;
    --accent-color: #f59e0b;

    /* Dark Grayscale */
    --white: #1e1e2e;
    --gray-50: #1a1a2e;
    --gray-100: #16161e;
    --gray-200: #2a2a3c;
    --gray-300: #3a3a4c;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;

    /* UI Elements */
    --highlight-color: rgba(245, 158, 11, 0.25);
    --card-shadow: rgba(0, 0, 0, 0.3) 0px 1px 3px, rgba(0, 0, 0, 0.2) 0px 1px 2px;
    --card-shadow-hover: rgba(0, 0, 0, 0.4) 0px 4px 6px, rgba(0, 0, 0, 0.3) 0px 2px 4px;
    --header-shadow: rgba(0, 0, 0, 0.3) 0px 1px 3px;
    --transition: all 0.2s ease-in-out;
    --border-radius: 8px;
    --content-max-width: 1400px;

    /* Typography */
    --font-main: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;

    /* Layout */
    --header-height: 56px;
    --editor-default-height: 65%;

    /* Breakpoints */
    --mobile-breakpoint: 640px;
    --tablet-breakpoint: 768px;
}

body {
    font-family: var(--font-main);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--gray-100);
    font-size: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-container {
    max-width: var(--content-max-width);
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100vh;
    overflow: hidden;
}

/* === MOBILE: switch to scrollable stacked layout === */
@media (max-width: 640px) {
    body {
        overflow: auto;
        overflow-x: hidden;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }
}

/* Header Section */
header {
    background-color: #12121a;
    border-bottom: 1px solid var(--gray-200);
    color: var(--text-color);
    box-shadow: var(--header-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    flex-shrink: 0;
}

.header-content {
    height: 100%;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: var(--content-max-width);
    margin: 0 auto;
}

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

.unified-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-title {
    display: flex;
    flex-direction: column;
}

h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.25px;
    color: #f1f5f9;
}

/* Responsive header */
@media (max-width: 640px) {
    .header-content {
        padding: 0 12px;
    }

    h1 {
        font-size: 15px;
    }

    button.primary-action {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.menu-icon {
    width: 18px;
    height: 18px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e2e8f0" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>');
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.9;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: 44px;
    background-color: #1e1e2e;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 8px 0;
    z-index: 110;
    transform: translateY(-10px);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s ease;
    border: 1px solid var(--gray-200);
}

.dropdown-menu.show {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 16px;
    color: var(--gray-600);
    background-color: transparent;
    border: none;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-radius: 0;
    box-shadow: none;
}

.dropdown-item:hover:not(:disabled) {
    background-color: var(--gray-200);
    color: var(--gray-900);
    transform: none;
    box-shadow: none;
}

.dropdown-item:disabled {
    color: var(--gray-400);
    background-color: transparent;
    cursor: not-allowed;
}

/* Button Styles */
button {
    background-color: var(--gray-200);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.25;
}

@media (max-width: 640px) {
    button {
        padding: 6px 12px;
        font-size: 13px;
    }
}

button:hover {
    background-color: var(--gray-300);
    border-color: var(--gray-400);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

button:active {
    transform: translateY(0);
    background-color: var(--gray-300);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

button:disabled {
    background-color: var(--gray-200);
    color: var(--gray-400);
    border-color: var(--gray-200);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    opacity: 0.5;
}

button.primary-action {
    background-color: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-dark);
    font-weight: 600;
    letter-spacing: 0.25px;
    padding: 8px 18px;
}

button.primary-action:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

button.primary-action:active {
    background-color: var(--primary-dark);
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

button.primary-action:disabled {
    background-color: rgba(99, 102, 241, 0.3);
    color: rgba(255, 255, 255, 0.4);
    border-color: transparent;
    box-shadow: none;
}

/* Main Content Section with Dynamic Layout */
.main-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

@media (max-width: 640px) {
    .main-content {
        height: auto;
        min-height: calc(100vh - var(--header-height));
        overflow: visible;
    }
}

/* Tooltip styles for the disabled Create Cards button */
button[disabled][title]:hover::after {
    content: attr(title);
    position: absolute;
    z-index: 100;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 6px;
    padding: 6px 10px;
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
}

button.primary-action {
    position: relative;
}

.dynamic-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

@media (max-width: 640px) {
    .dynamic-container {
        height: auto;
        min-height: 100%;
    }
}

/* Editor Panel */
.editor-panel {
    flex-grow: 1;
    background-color: var(--white);
    overflow: hidden;
    position: relative;
    transition: height 0.3s ease;
    height: 100%;
}

@media (max-width: 640px) {
    .editor-panel {
        height: 50vh !important;
        min-height: 200px;
        flex-grow: 0;
        flex-shrink: 0;
    }
}

.text-input {
    width: 100%;
    height: 100%;
    padding: 0px;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--white);
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
    position: relative;
    white-space: pre-wrap;
    word-break: break-word;
    tab-size: 4;
}

.text-input:focus {
    outline: none;
}

.text-input::placeholder {
    color: var(--gray-500);
    font-style: italic;
}

.text-input[contenteditable]:empty::before {
    content: attr(placeholder);
    color: var(--gray-500);
    font-style: italic;
    pointer-events: none;
}

/* Splitter Handle */
.splitter-handle {
    height: 14px;
    background-color: var(--gray-200);
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    position: relative;
    z-index: 10;
    border-top: 1px solid var(--gray-300);
    border-bottom: 1px solid var(--gray-300);
    transition: all 0.3s ease;
    opacity: 1;
}

.splitter-handle:hover {
    background-color: var(--gray-300);
}

.splitter-handle.animate-in {
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.handle-line {
    width: 50px;
    height: 4px;
    background-color: var(--gray-400);
    border-radius: 2px;
}

/* Hide splitter on mobile — stacked layout doesn't need it */
@media (max-width: 640px) {
    .splitter-handle {
        display: none !important;
    }
}

/* Output Panel */
.output-panel {
    flex-grow: 1;
    background-color: var(--gray-100);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    height: 50%;
}

@media (max-width: 640px) {
    .output-panel {
        height: auto !important;
        min-height: 60vh;
        flex-grow: 1;
        overflow: visible;
    }
}

/* Spinner animation for loading states */
@keyframes spinner {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(180deg); }
    100% { transform: rotate(360deg); }
}

/* Document context indicator */
body.has-document-context .text-input {
    background-color: rgba(99, 102, 241, 0.05);
    transition: all 0.5s ease;
}

/* Content Container */
.content-container {
    flex-grow: 1;
    overflow-y: auto;
    background-color: var(--gray-100);
    height: 100%;
}

@media (max-width: 640px) {
    .content-container {
        overflow: visible;
        height: auto;
    }
}

/* Highlight styles */
::selection {
    background-color: var(--highlight-color);
}

.text-input.has-selection ::selection {
    background-color: var(--highlight-color);
}

.text-input.has-selection {
    outline: 2px solid var(--primary-light);
}

/* Custom Scrollbar (dark) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* Cards Container */
.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
    padding: 16px;
}

@media (max-width: 640px) {
    .cards-container {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
        padding-bottom: 80px; /* space for bottom export bar */
    }
}

.card {
    background-color: var(--white);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    height: auto;
    position: relative;
}

.card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
}

@media (max-width: 640px) {
    .card:hover {
        transform: none; /* no hover transforms on touch */
    }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: linear-gradient(to right, rgba(99, 102, 241, 0.12), rgba(99, 102, 241, 0.05));
    border-bottom: 1px solid var(--gray-200);
    font-size: 12px;
    height: 42px;
    min-height: 42px;
}

.card-header-left, .card-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header button {
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 4px;
    height: 22px;
    background-color: transparent;
    box-shadow: none;
    font-weight: 500;
    color: var(--gray-600);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.card-header button:hover {
    background-color: var(--gray-200);
    border-color: var(--gray-300);
    color: var(--gray-800);
}

.card-header button:active {
    transform: translateY(1px);
}

.card-deck {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--white);
    background-color: var(--primary-color);
    padding: 3px 10px;
    border-radius: 4px;
    line-height: 1.4;
    height: 24px;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #fff;
}

.card-deck:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Deck selector styles */
.deck-selector-label {
    font-size: 11px;
    color: var(--gray-500);
    margin-right: 8px;
}

.deck-count {
    font-size: 10px;
    color: var(--gray-500);
    margin-left: 4px;
    font-weight: normal;
}

.deck-selector-container {
    display: flex;
    align-items: center;
    margin-right: 12px;
}

.deck-selector {
    min-width: 180px;
    height: 30px;
    padding: 2px 8px;
    font-size: 13px;
    border: 1px solid var(--gray-300);
    border-radius: 4px 0 0 4px;
    background-color: var(--white);
    color: var(--text-color);
    cursor: pointer;
    outline: none;
}

.deck-selector:hover {
    border-color: var(--primary-color);
}

.deck-selector:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.refresh-decks-button {
    height: 30px;
    width: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 4px 4px 0;
    margin-left: -1px;
    font-size: 14px;
    background-color: var(--gray-200);
    border: 1px solid var(--gray-300);
    cursor: pointer;
}

.refresh-decks-button:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.refresh-decks-button:active {
    background-color: var(--primary-color);
    color: white;
}

/* Status notification */
.status-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 14px 20px;
    background-color: var(--white);
    color: var(--text-color);
    border-radius: 10px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    font-size: 14px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: translateY(30px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    border: 1px solid var(--gray-200);
    font-weight: 500;
    min-width: 260px;
    max-width: 90%;
}

@media (max-width: 640px) {
    .status-notification {
        bottom: 70px; /* above the mobile export bar */
        right: 12px;
        left: 12px;
        min-width: auto;
    }
}

.status-notification.show {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.status-notification.success {
    border-left: 4px solid #10b981;
    background-color: rgba(16, 185, 129, 0.1);
    color: #6ee7b7;
}

.status-notification.error {
    border-left: 4px solid #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

.status-notification.info {
    border-left: 4px solid var(--primary-color);
    background-color: var(--primary-light);
    color: #a5b4fc;
}

.status-notification .icon {
    font-size: 20px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.status-notification.success .icon::before {
    content: '\2713';
    color: #10b981;
}

.status-notification.error .icon::before {
    content: '\2717';
    color: #ef4444;
}

.status-notification.info .icon::before {
    content: '\2139';
    color: var(--primary-color);
}

@keyframes notificationPop {
    0% { transform: translateY(30px) scale(0.95); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: #1e1e2e;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    padding: 20px;
    width: 95%;
    max-width: 400px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    gap: 15px;
    border: 1px solid var(--gray-200);
}

.modal-content h3 {
    font-size: 18px;
    color: var(--gray-900);
    margin: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-subheader {
    margin: 0 0 15px 0;
    color: var(--gray-600);
    font-size: 14px;
}

.modal-select-container {
    display: flex;
    margin-bottom: 20px;
    width: 100%;
}

.deck-select {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--gray-300);
    border-radius: 4px 0 0 4px;
    font-size: 14px;
    color: var(--text-color);
    background-color: var(--white);
    outline: none;
}

.deck-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-light);
}

.modal-refresh-button {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 4px 4px 0;
    margin-left: -1px;
    font-size: 16px;
    background-color: var(--gray-200);
    border: 1px solid var(--gray-300);
    cursor: pointer;
}

.modal-refresh-button:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.modal-refresh-button:active {
    background-color: var(--primary-color);
    color: white;
}

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

.modal-cancel {
    background-color: var(--gray-200);
    color: var(--gray-700);
}

.modal-save {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-dark);
}

.modal-save:hover {
    background-color: var(--primary-dark);
    color: #fff;
}

.card-content {
    display: flex;
    flex-direction: column;
    overflow: visible;
    flex-grow: 1;
    padding: 14px;
}

.card-front, .card-back {
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.card-back {
    border-top: 1px solid var(--gray-200);
    margin-top: 8px;
    padding-top: 8px;
}

.card-text {
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--gray-200);
    border-radius: 5px;
    padding: 10px 12px;
    line-height: 1.5;
    outline: none;
    font-size: 14px;
    min-height: 28px;
    height: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
    transition: all 0.15s ease;
    color: var(--text-color);
}

.card-front .card-text {
    font-weight: 500;
}

.card-back .card-text {
    font-weight: 400;
    background-color: rgba(26, 26, 46, 0.5);
}

.card-text:hover {
    border-color: var(--gray-300);
}

.card-text:focus {
    border-color: var(--primary-color);
    background-color: var(--gray-50);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.delete-button {
    color: white;
    background-color: #dc2626;
    border: 1px solid #b91c1c;
    min-width: auto;
    font-size: 16px;
    font-weight: bold;
    padding: 0;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3);
    transition: all 0.2s ease;
}

.delete-button:hover {
    background-color: #b91c1c;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(220, 38, 38, 0.4);
    border-color: #991b1b;
}

/* Questions Container */
.questions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 20px;
    padding: 20px;
}

.question-item {
    background-color: var(--white);
    border-radius: 10px;
    border: 1px solid var(--gray-200);
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    min-height: 85px;
    height: auto;
    position: relative;
}

.question-item::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 10px;
    box-shadow: 0 0 0 2px transparent;
    transition: all 0.2s ease;
}

.question-item:hover {
    border-color: var(--gray-300);
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
}

.question-item:hover::after {
    box-shadow: 0 0 0 2px var(--primary-light);
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background-color: var(--primary-light);
    border-bottom: 1px solid var(--gray-200);
    font-size: 12px;
    height: 46px;
    min-height: 46px;
}

.question-header-left, .question-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.question-header button {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    height: 28px;
    background-color: transparent;
    box-shadow: none;
}

.question-header button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.question-topic {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background-color: var(--accent-color);
    padding: 3px 10px;
    border-radius: 16px;
    line-height: 1.3;
    height: 22px;
    letter-spacing: 0.2px;
}

.question-body {
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: visible;
    background: var(--white);
    flex-grow: 1;
}

.question-text {
    font-weight: 500;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-color);
    overflow: visible;
    word-wrap: break-word;
    white-space: pre-wrap;
    padding: 5px 0;
    border: 1px solid transparent;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.question-text:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

.question-text:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--gray-50);
    box-shadow: 0 0 0 3px var(--primary-light);
    padding: 5px 10px;
}

.delete-question-button {
    color: #f87171;
    background-color: transparent;
    border-color: #f87171;
    min-width: auto;
}

.delete-question-button:hover {
    background-color: rgba(248, 113, 113, 0.1);
}

/* Text formatting within the input */
.text-input h1, .text-input h2, .text-input h3, .text-input h4, .text-input h5, .text-input h6 {
    font-family: inherit;
    color: var(--text-color);
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 600;
    line-height: 1.3;
}

.text-input h1 { font-size: 1.5em; }
.text-input h2 { font-size: 1.3em; }
.text-input h3 { font-size: 1.2em; }
.text-input h4, .text-input h5, .text-input h6 { font-size: 1.1em; }

.text-input ul, .text-input ol {
    padding-left: 2em;
    margin: 0.7em 0;
}

.text-input li {
    margin-bottom: 0.4em;
}

.text-input p {
    margin-bottom: 0.9em;
}

.text-input blockquote {
    border-left: 3px solid var(--primary-color);
    margin-left: 0;
    padding: 0.5em 0 0.5em 1em;
    color: var(--gray-600);
    background-color: var(--gray-50);
    border-radius: 0 4px 4px 0;
}

.text-input img, .text-input video, .text-input iframe, .text-input embed, .text-input object {
    display: none;
}

/* Quill Editor Styles — Dark Mode */
.text-input {
    height: 100%;
}

.ql-container.ql-snow {
    height: calc(100% - 42px);
    overflow: auto;
    border: none;
    font-family: var(--font-main);
    font-size: 16px;
    line-height: 1.6;
}

.ql-toolbar.ql-snow {
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
    background-color: #12121a;
    padding: 8px 20px;
}

/* Dark mode Quill toolbar buttons */
.ql-toolbar.ql-snow .ql-stroke {
    stroke: var(--gray-500);
}

.ql-toolbar.ql-snow .ql-fill {
    fill: var(--gray-500);
}

.ql-toolbar.ql-snow .ql-picker-label {
    color: var(--gray-500);
}

.ql-toolbar.ql-snow button:hover .ql-stroke,
.ql-toolbar.ql-snow .ql-picker-label:hover .ql-stroke {
    stroke: var(--primary-color);
}

.ql-toolbar.ql-snow button:hover .ql-fill,
.ql-toolbar.ql-snow .ql-picker-label:hover .ql-fill {
    fill: var(--primary-color);
}

.ql-toolbar.ql-snow button.ql-active .ql-stroke {
    stroke: var(--primary-color);
}

.ql-toolbar.ql-snow button.ql-active .ql-fill {
    fill: var(--primary-color);
}

.ql-toolbar.ql-snow .ql-picker-options {
    background-color: #1e1e2e;
    border-color: var(--gray-300);
}

.ql-toolbar.ql-snow .ql-picker-item {
    color: var(--text-color);
}

.ql-toolbar.ql-snow .ql-picker-item:hover {
    color: var(--primary-color);
}

.ql-snow .ql-picker.ql-header .ql-picker-label::before,
.ql-snow .ql-picker.ql-header .ql-picker-item::before {
    color: var(--gray-500);
}

.ql-editor {
    min-height: 100%;
    padding: 20px;
    font-family: var(--font-main);
    color: var(--text-color);
}

.ql-editor ::selection {
    background-color: var(--highlight-color);
}

.ql-editor h1 {
    font-size: 1.5em;
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 600;
    color: var(--text-color);
}

.ql-editor h2 {
    font-size: 1.3em;
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 600;
    color: var(--text-color);
}

.ql-editor h3 {
    font-size: 1.2em;
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 600;
    color: var(--text-color);
}

.ql-editor ul,
.ql-editor ol {
    padding-left: 1.5em;
    margin: 0.7em 0;
}

.ql-editor ul > li {
    list-style-type: disc;
    margin-bottom: 0.4em;
}

.ql-editor ol > li {
    list-style-type: decimal;
    margin-bottom: 0.4em;
}

.ql-editor blockquote {
    border-left: 3px solid var(--primary-color);
    margin-left: 0;
    padding: 0.5em 0 0.5em 1em;
    color: var(--gray-600);
    background-color: var(--gray-50);
    border-radius: 0 4px 4px 0;
}

.text-input.has-selection .ql-editor {
    outline: 2px solid var(--primary-light);
}

.ql-editor.ql-blank::before {
    color: var(--gray-400);
    font-style: italic;
}

/* API Key / Settings Modal */
.api-key-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    animation: fadeIn 0.2s ease forwards;
}

.api-key-container {
    width: 520px;
    max-width: 90%;
    background-color: #1e1e2e;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    padding: 32px;
    transform: translateY(20px);
    animation: slideUp 0.3s ease forwards;
    border: 1px solid var(--gray-200);
}

@media (max-width: 640px) {
    .api-key-container {
        padding: 20px 16px;
        max-width: 95%;
    }
}

@keyframes slideUp {
    0% { transform: translateY(20px); }
    100% { transform: translateY(0); }
}

.api-key-header {
    text-align: center;
    margin-bottom: 28px;
}

.api-key-header h2 {
    margin-bottom: 12px;
    color: var(--gray-900);
    font-size: 22px;
    font-weight: 600;
}

.api-key-header p {
    color: var(--text-color);
    font-size: 15px;
    line-height: 1.6;
    max-width: 90%;
    margin: 0 auto 12px;
    font-weight: 500;
    background-color: var(--primary-light);
    padding: 10px 14px;
    border-radius: 8px;
    text-align: center;
}

.security-disclaimer {
    background-color: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbbf24;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    margin: 12px auto 4px;
    max-width: 95%;
    text-align: center;
    font-weight: 500;
    line-height: 1.5;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.3); }
    70% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.api-key-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.api-key-input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.api-key-input-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.api-key-input-group label span.required {
    color: white;
    font-size: 13px;
    font-weight: 600;
    background-color: var(--primary-color);
    padding: 3px 8px;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.api-key-input-group label span.optional {
    color: var(--gray-500);
    font-weight: normal;
    font-size: 13px;
    background-color: var(--gray-200);
    padding: 3px 8px;
    border-radius: 10px;
}

.api-key-input-group input {
    padding: 14px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font-mono);
    width: 100%;
    box-sizing: border-box;
    transition: all 0.15s ease;
    background-color: var(--gray-50);
    color: var(--text-color);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

#anthropicApiKey {
    border-left-width: 4px;
}

.api-key-input-group input:hover {
    border-color: var(--gray-400);
}

.api-key-input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--white);
    box-shadow: 0 0 0 4px var(--primary-light), inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.api-key-help {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 6px;
    line-height: 1.5;
}

.api-key-help a {
    color: #818cf8;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    transition: all 0.15s ease;
}

.api-key-help a:hover {
    border-bottom-color: #818cf8;
}

.api-key-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 28px;
}

.api-key-button {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    line-height: 1.2;
}

.api-key-button.secondary {
    background-color: var(--gray-200);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.api-key-button.secondary:hover {
    background-color: var(--gray-300);
    transform: translateY(-1px);
}

.api-key-button.primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.api-key-button.primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.api-key-button:active {
    transform: translateY(0);
}

.api-key-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.api-key-toggle {
    display: flex;
    align-items: center;
    margin-top: 6px;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
    color: var(--gray-600);
}

.api-key-toggle input {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.api-key-error {
    color: #f87171;
    font-size: 13px;
    margin-top: 6px;
    background-color: rgba(248, 113, 113, 0.1);
    padding: 6px 10px;
    border-radius: 6px;
    border-left: 3px solid #f87171;
    line-height: 1.4;
}

/* Header buttons like settings, menu */
.header-settings-button, .menu-button {
    margin-left: 8px;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.header-settings-button:hover, .menu-button:hover {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.header-settings-button:active, .menu-button:active {
    transform: translateY(1px);
    background-color: rgba(255, 255, 255, 0.08);
}

.settings-icon {
    width: 18px;
    height: 18px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e2e8f0" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>');
    background-repeat: no-repeat;
    background-position: center;
    transition: all 0.2s ease;
    opacity: 0.8;
}

/* Anki Connection Status */
.anki-status-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.anki-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    line-height: 1.3;
}

.anki-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.anki-status.connected {
    background-color: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.anki-status.connected::before {
    background-color: #10b981;
}

.anki-status.disconnected {
    background-color: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.anki-status.disconnected::before {
    background-color: #ef4444;
}

.anki-reconnect-button {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
    background-color: var(--gray-200);
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
    cursor: pointer;
}

.anki-reconnect-button:hover {
    background-color: var(--gray-300);
}

/* Anki Export Modal */
.anki-export-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.anki-export-form label {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
    display: block;
}

.anki-export-form select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-color);
    background-color: var(--white);
    outline: none;
}

.anki-export-form select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.field-mapping-preview {
    background-color: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 12px;
    font-size: 13px;
    color: var(--gray-600);
}

.field-mapping-preview .mapping-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.field-mapping-preview .mapping-arrow {
    color: var(--gray-400);
    font-size: 12px;
}

.field-mapping-preview .mapping-source,
.field-mapping-preview .mapping-target {
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 3px;
}

.field-mapping-preview .mapping-source {
    background-color: var(--primary-light);
    color: #818cf8;
}

.field-mapping-preview .mapping-target {
    background-color: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
}

/* ========================================
   MOBILE STICKY EXPORT BAR
   Shows Export + Clear buttons at bottom
   ======================================== */
.mobile-export-bar {
    display: none;
}

@media (max-width: 640px) {
    .mobile-export-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 200;
        background-color: #12121a;
        border-top: 1px solid var(--gray-200);
        padding: 10px 12px;
        gap: 8px;
        justify-content: stretch;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
    }

    .mobile-export-bar button {
        flex: 1;
        padding: 12px 8px;
        font-size: 14px;
        font-weight: 600;
        border-radius: 8px;
    }

    .mobile-export-bar .mobile-export-btn {
        background-color: var(--primary-color);
        color: white;
        border: none;
    }

    .mobile-export-bar .mobile-export-btn:hover {
        background-color: var(--primary-dark);
    }

    .mobile-export-bar .mobile-export-btn:disabled {
        background-color: rgba(99, 102, 241, 0.3);
        color: rgba(255, 255, 255, 0.4);
    }

    .mobile-export-bar .mobile-clear-btn {
        background-color: var(--gray-200);
        color: var(--gray-600);
        border: 1px solid var(--gray-300);
        flex: 0.5;
    }

    .mobile-export-bar .mobile-clear-btn:disabled {
        opacity: 0.4;
    }
}

/* Quill snow theme dark overrides */
.ql-snow .ql-picker.ql-expanded .ql-picker-label {
    border-color: var(--gray-300);
}

.ql-snow .ql-picker.ql-expanded .ql-picker-options {
    border-color: var(--gray-300);
    background-color: #1e1e2e;
}
