/* Global Styles */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Sidebar (Left) */
.sidebar {
    width: 400px;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.02);
    z-index: 10;
    overflow-y: auto;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Form Elements */
.input-group {
    margin-bottom: 12px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    column-rule-color: var(--text-main);
    box-sizing: border-box;
    transition: all 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.url-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.btn-icon {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 38px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: #f9fafb;
    color: #ef4444;
    border-color: #ef4444;
}

.btn-add {
    width: 100%;
    padding: 8px;
    background: white;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-add:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Search Section */
.search-container {
    margin-bottom: 12px;
}

.search-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.search-input-row input {
    flex: 1;
}

.btn-search {
    padding: 10px 14px;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-search:hover {
    background: var(--primary-hover);
}

.btn-search:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.search-type-toggle {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 13px;
}

.search-results {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    display: none;
}

.search-results.visible {
    display: block;
}

.search-result-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: #eef2ff;
}

.search-result-item.added {
    background: #dcfce7;
    color: #166534;
}

.search-result-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.search-loading {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.search-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Folder expansion styles */
.folder-item {
    position: relative;
}

.folder-toggle {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.folder-item.expanded {
    background: #f8fafc;
    border-bottom-color: transparent;
}

.folder-sets-container {
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.set-item {
    padding-left: 36px !important;
    background: #fff;
    border-left: 2px solid var(--primary);
    margin-left: 12px;
}

.set-item:hover {
    background: #eef2ff !important;
}

.set-item.added {
    background: #dcfce7 !important;
    color: #166534;
}

.set-item .search-result-title {
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
}

.set-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-preview {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
}

.btn-preview:hover {
    background: #eef2ff;
    border-color: var(--primary);
}

.add-status {
    font-size: 16px;
    font-weight: 600;
    width: 20px;
    text-align: center;
    color: var(--text-muted);
}

.set-item.added .add-status {
    color: #16a34a;
}

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

/* Primary Buttons */
.btn-primary {
    width: 100%;
    padding: 12px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-primary:disabled {
    background-color: var(--border);
    cursor: not-allowed;
}

.status-bar {
    margin-top: 12px;
    padding: 12px;
    background: #eff6ff;
    border-radius: 6px;
    font-size: 13px;
    color: #1e40af;
    display: none;
}

.status-bar.visible {
    display: block;
}

/* Main Content (Preview) */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e2e8f0;
    /* Darker grey for contrast with paper */
}

.top-bar {
    height: 60px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.tabs {
    display: flex;
    gap: 4px;
}

.tab {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab:hover {
    background: #f3f4f6;
    color: var(--text-main);
}

.tab.active {
    background: #eef2ff;
    color: var(--primary);
}

.btn-action {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-action:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f9fafb;
}

.preview-area {
    flex: 1;
    padding: 40px;
    overflow: auto;
    display: flex;
    justify-content: center;
}

.paper-frame {
    width: 210mm;
    min-height: 297mm;
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: none;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* History List */
.history-list {
    width: 100%;
    max-width: 800px;
    padding: 20px;
}

.history-item {
    background: white;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.history-info {
    flex: 1;
}

.history-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.history-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 8px;
}

.btn-history-action {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-history-action:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-history-action.delete:hover {
    border-color: #ef4444;
    color: #ef4444;
}

.history-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.history-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}