/* Root Variables - Glassmorphic Dark Design System */
:root {
    --bg-primary: #0a0d14;
    --bg-secondary: #10141f;
    --bg-tertiary: #161c2b;
    --glass-bg: rgba(16, 20, 31, 0.65);
    --glass-border: rgba(255, 255, 255, 0.05);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --color-primary: #3b82f6; /* Blue */
    --color-primary-glow: rgba(59, 130, 246, 0.3);
    --color-accent: #ef4444; /* Rose Red */
    --color-accent-glow: rgba(239, 68, 68, 0.3);
    
    --color-green: #10b981; /* Emerald */
    --color-green-glow: rgba(16, 185, 129, 0.2);
    --color-orange: #f59e0b; /* Amber */
    --color-orange-glow: rgba(245, 158, 11, 0.2);
    
    --border-radius-sm: 6px;
    --border-radius-md: 10px;
    --border-radius-lg: 14px;
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    
    --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 16px;
    gap: 16px;
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.05) 0px, transparent 50%);
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.portal-icon, .admin-logo-icon {
    font-size: 1.6rem;
    color: var(--color-primary);
    text-shadow: 0 0 10px var(--color-primary-glow);
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.logo-text span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Search inputs: by document name (sidebar), and inside an open document (viewer header) */
.doc-name-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
}

.doc-name-search input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    width: 100%;
}

.doc-name-search i {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.in-doc-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
}

.in-doc-search input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    width: 160px;
}

.in-doc-search i {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.in-doc-search-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Sidebar and Main Layout */
.workspace {
    display: flex;
    flex: 1;
    gap: 0;
    min-height: 0;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    margin-right: 12px;
    gap: 16px;
    min-height: 0;
}

/* Draggable handle to resize the sidebar against the main pane */
.sidebar-resizer {
    width: 5px;
    flex-shrink: 0;
    margin-right: 12px;
    cursor: col-resize;
    position: relative;
}

.sidebar-resizer::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 1px;
    width: 3px;
    border-radius: 3px;
    background: var(--glass-border);
    transition: background 0.15s;
}

.sidebar-resizer:hover::after,
.sidebar-resizer.resizing::after {
    background: var(--color-primary);
}

.sidebar-header, .sidebar-header-admin {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2, .sidebar-header-admin h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Category Tree Styles */
.categories-tree, .categories-tree-admin {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
}

.tree-node {
    display: flex;
    flex-direction: column;
}

.tree-header {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition-smooth);
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}

.tree-header:hover {
    background: rgba(255,255,255,0.03);
}

.tree-header i.folder-icon {
    color: #eab308; /* Yellow folder */
}

.tree-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.7rem;
}

.tree-toggle:hover {
    color: var(--text-primary);
}

.tree-toggle-spacer {
    display: inline-block;
    width: 16px;
    flex-shrink: 0;
}

.tree-children {
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

.tree-doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition-smooth);
    gap: 6px;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid transparent;
}

.tree-doc-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--glass-border);
}

.tree-doc-item.active {
    background: var(--bg-tertiary);
    border-color: var(--color-primary-glow);
    box-shadow: inset 3px 0 0 var(--color-primary);
}

.tree-doc-item i {
    color: #ef4444; /* Red PDF icon */
}

.tree-doc-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Category Actions in Admin */
.cat-actions {
    display: none;
    gap: 4px;
    margin-left: auto;
}

.tree-header:hover .cat-actions {
    display: flex;
}

/* Drag-and-drop zone */
.upload-section {
    border-top: 1px solid var(--glass-border);
    padding-top: 12px;
}

.upload-section h3 {
    font-size: 0.85rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.drag-drop-zone {
    border: 2px dashed var(--glass-border);
    background: rgba(255,255,255,0.01);
    border-radius: var(--border-radius-md);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.drag-drop-zone:hover, .drag-drop-zone.dragover {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.03);
}

.upload-plus {
    font-size: 1.6rem;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.drag-drop-zone:hover .upload-plus {
    color: var(--color-primary);
    transform: scale(1.1);
}

.drag-drop-zone p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.hidden-file-input {
    display: none;
}

/* Queue progress bar list */
.upload-queue {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    max-height: 120px;
    overflow-y: auto;
}

.queue-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-sm);
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.queue-item-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
}

.queue-item-name {
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-item-status {
    color: var(--text-muted);
}

.queue-progress-container {
    height: 4px;
    background: rgba(255,255,255,0.05);
    border-radius: 20px;
    overflow: hidden;
}

.queue-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--color-primary), var(--color-green));
    transition: width 0.4s ease;
}

/* Translation Pane */
.translation-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
    min-height: 0;
}

.admin-edit-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 12px;
}

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 12px;
}

.current-page-info {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 60%;
}

.current-page-info h2 {
    font-size: 1.15rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-title-input {
    background: none;
    border: none;
    border-bottom: 1px dashed transparent;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1.15rem;
    font-weight: 600;
    outline: none;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 4px;
}

.viewer-title-input.renamable {
    border-bottom-color: var(--glass-border);
    cursor: text;
}

.viewer-title-input.renamable:focus {
    border-bottom-color: var(--color-primary);
}

.viewer-actions, .pane-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.viewer-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Page navigation */
.page-navigator {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.page-counter {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0 10px;
    color: var(--text-secondary);
}

.page-counter input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    width: 40px;
    text-align: center;
}

/* Unified layout-preserving page viewer */
.unified-viewer-container {
    display: flex;
    flex: 1;
    min-height: 0;
}

.unified-viewer {
    flex: 1;
    display: flex;
    min-height: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.page-frame {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--border-radius-md);
    border: none;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition-smooth);
}

.btn-xs { padding: 4px 8px; font-size: 0.7rem; border-radius: var(--border-radius-sm); }
.btn-sm { padding: 6px 12px; font-size: 0.75rem; border-radius: var(--border-radius-sm); }
.btn-block { width: 100%; }

.btn-icon-only {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
}

.btn-primary { background: linear-gradient(135deg, var(--color-primary), #8b5cf6); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px var(--color-primary-glow); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--glass-border); }
.btn-secondary:hover { background: var(--bg-secondary); border-color: var(--color-primary); }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-accent:hover { transform: translateY(-1px); box-shadow: 0 4px 12px var(--color-accent-glow); }
.btn-success { background: var(--color-green); color: #fff; }
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 4px 12px var(--color-green-glow); }

/* Badges */
.badge {
    padding: 2px 8px;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: 20px;
    text-transform: uppercase;
}

.badge-pending { background: rgba(148, 163, 184, 0.1); color: var(--text-secondary); }
.badge-translating { background: var(--color-orange-glow); color: var(--color-orange); animation: blink 1.5s infinite; }
.badge-completed { background: var(--color-green-glow); color: var(--color-green); }
.badge-error { background: var(--color-accent-glow); color: var(--color-accent); }
.badge-paused { background: var(--color-orange-glow); color: var(--color-orange); }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
    text-align: center;
}

.empty-state i {
    font-size: 2.5rem;
    color: var(--bg-tertiary);
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.8rem;
    max-width: 300px;
}

/* Admin Login Wrapper */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-image: radial-gradient(circle at center, rgba(59, 130, 246, 0.1), transparent);
}

.login-card {
    width: 320px;
    padding: 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-icon {
    font-size: 2.5rem;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.login-card h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.login-card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    outline: none;
    font-size: 0.85rem;
    text-align: center;
}

.input-group input:focus {
    border-color: var(--color-primary);
}

.login-back-link {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
}

.login-back-link:hover {
    color: var(--color-primary);
}

/* Engine status indicator */
.engine-status {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.engine-status.active .status-dot {
    background-color: var(--color-green);
    box-shadow: 0 0 6px var(--color-green-glow);
    animation: blink 1.5s infinite;
}

/* Approximate daily Gemini quota gauge */
.usage-gauge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.usage-gauge i {
    color: var(--color-orange);
}

.badge-tokens {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
}

/* Editable Title Input in Admin */
.doc-title-editor-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.editable-title-input {
    background: none;
    border: none;
    border-bottom: 1px dashed var(--glass-border);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1.15rem;
    font-weight: 600;
    outline: none;
    width: 80%;
    padding: 2px 4px;
}

.editable-title-input:focus {
    border-color: var(--color-primary);
}

/* Dragging items indicator */
.tree-doc-item.drag-source {
    opacity: 0.4;
    border-style: dashed;
}

.tree-header.drag-source {
    opacity: 0.4;
}

.tree-header.drag-enter {
    background: var(--color-primary-glow);
    border-color: var(--color-primary);
}

.tree-header.drag-enter i.folder-icon {
    color: var(--color-primary);
    transform: scale(1.15);
}

.tree-header.drag-before, .tree-header.drag-after {
    position: relative;
}

.tree-header.drag-before::before, .tree-header.drag-after::after {
    content: '';
    position: absolute;
    left: 4px;
    right: 4px;
    height: 2px;
    border-radius: 2px;
    background: var(--color-primary);
    box-shadow: 0 0 4px var(--color-primary-glow);
}

.tree-header.drag-before::before {
    top: -3px;
}

.tree-header.drag-after::after {
    bottom: -3px;
}

.hidden {
    display: none !important;
}
.sidebar-header-admin {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--glass-border);
    transition: var(--transition-smooth);
    border: 2px solid transparent;
}
.sidebar-header-admin.root-drop-highlight {
    border: 2px dashed rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.05);
    padding: 8px;
    border-radius: var(--border-radius-md);
}
.sidebar-header-admin.drag-enter {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--color-primary);
}

/* Generic modal (delete-category choices, trash panel) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    width: 420px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
}

.modal-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.trash-card {
    width: 560px;
}

.trash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.trash-header h3 {
    margin-bottom: 0;
}

.trash-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.trash-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
}

.trash-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-md);
}

.trash-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.trash-item-label {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trash-item-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.trash-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
