/* ═══════════════════════════════════════════════════════════════
   PDF Toolbox — Stylesheet v6
   Tool settings in sidebar
   ═══════════════════════════════════════════════════════════════ */

:root {
    --primary: #d63031;
    --primary-dark: #b71c1c;
    --primary-light: #fdeaea;
    --sidebar-bg: #f7f9fc;
    --border: #e2e8f0;
    --text: #333;
    --text-muted: #888;
    --bg: #ffffff;
    --bg-page: #f4f6f9;
    --danger: #e53e3e;
    --success: #38a169;
    --warning: #d69e2e;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --sidebar-width: 220px;
    --topbar-height: 48px;
    --transition: 0.2s ease;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── Login Page ────────────────────────────────────────────── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-page);
}

.login-card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 40px 36px 32px;
    width: 380px;
    max-width: 95vw;
    text-align: center;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.login-logo svg, .login-logo img {
    width: 44px;
    height: 44px;
}

.login-card h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.login-card .subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.login-card .form-group {
    text-align: left;
    margin-bottom: 16px;
}

.login-card .login-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 20px;
}

/* ── App Layout ────────────────────────────────────────────── */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Top Bar ───────────────────────────────────────────────── */

.top-bar {
    height: var(--topbar-height);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0;
    flex-shrink: 0;
    gap: 0;
}

.top-bar .file-tabs-bar {
    flex: 1;
    border-bottom: none;
    min-height: var(--topbar-height);
    background: transparent;
}

.top-bar-right {
    position: relative;
    flex-shrink: 0;
    padding: 0 12px;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    border: none;
    background: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
}

.user-menu-trigger:hover {
    background: var(--primary-light);
}

.user-menu-trigger .user-avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.user-menu-trigger .caret {
    font-size: 10px;
    color: var(--text-muted);
}

.user-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 100;
    overflow: hidden;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    transition: background var(--transition);
}

.user-menu-item:hover {
    background: var(--primary-light);
}

.user-menu-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.user-menu-divider {
    border-top: 1px solid var(--border);
    margin: 2px 0;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header svg, .sidebar-header img {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.nav-category {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 12px 12px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background var(--transition), border-color var(--transition);
    user-select: none;
    box-sizing: border-box;
}

.nav-item:hover {
    background: var(--primary-light);
}

.nav-item.active {
    background: var(--primary-light);
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.nav-item svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.nav-item.active svg {
    color: var(--primary);
}

.nav-item.open-pdf-btn {
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 4px;
}

.nav-divider {
    border-top: 1px solid var(--border);
    margin: 4px 12px;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 6px 8px;
    flex-shrink: 0;
}

.sidebar-footer .nav-item {
    border-left: none;
    border-radius: var(--radius-sm);
    padding: 7px 12px;
}

/* ── Tool Settings in Sidebar ──────────────────────────────── */

.tool-settings {
    padding: 6px 8px 10px 8px;
    border-left: 3px solid var(--primary);
    margin: 0 0 4px 0;
    background: var(--primary-light);
    border-radius: 0;
    overflow: hidden;
    box-sizing: border-box;
}
.tool-settings.hidden { display: none; }

.ts-body { display: flex; flex-direction: column; gap: 4px; }
.ts-hint { font-size: 11px; color: var(--text-muted); padding: 2px 0; line-height: 1.4; }
.ts-label { font-size: 11px; font-weight: 600; color: var(--text); margin-top: 4px; }
.ts-check { font-size: 12px; color: var(--text); display: flex; align-items: center; gap: 4px; cursor: pointer; }
.ts-check input { margin: 0; width: 14px; height: 14px; accent-color: var(--primary); cursor: pointer; }
.ts-input {
    font-size: 12px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    box-sizing: border-box;
}
.ts-input:focus {
    outline: none;
    border-color: var(--primary);
}
.ts-select {
    font-size: 12px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    appearance: auto;
}
.ts-select:focus {
    outline: none;
    border-color: var(--primary);
}
.ts-range { width: 100%; }
.ts-divider { border-top: 1px solid var(--border); margin: 4px 0; }
.ts-color-row { display: flex; gap: 6px; margin: 2px 0; flex-wrap: wrap; }
.ts-color-opt {
    width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
    border: 2px solid transparent; transition: border-color 0.15s;
}
.ts-color-opt:hover { border-color: var(--text); }
.ts-color-opt.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }
.ts-bg-opt {
    width: 22px; height: 22px; border-radius: 4px; cursor: pointer;
    border: 2px solid var(--border); transition: border-color 0.15s;
}
.ts-bg-opt:hover { border-color: var(--text); }
.ts-bg-opt.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }

.ts-img-row { display: flex; gap: 6px; margin: 2px 0; }
.ts-img-opt {
    width: 52px; height: 36px; border-radius: 4px; cursor: pointer;
    border: 2px solid var(--border); display: flex; align-items: center;
    justify-content: center; overflow: hidden; background: #fff;
    transition: border-color 0.15s;
}
.ts-img-opt:hover { border-color: var(--text); }
.ts-img-opt.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.ts-img-opt img { max-width: 44px; max-height: 28px; object-fit: contain; }
.ts-img-placeholder { font-size: 18px; color: var(--text-muted); font-weight: 300; }
.ts-img-none { font-size: 16px; color: var(--text-muted); }
.ts-result { margin-top: 6px; font-size: 11px; }

.ts-upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--bg);
}
.ts-upload-zone:hover,
.ts-upload-zone.dragover {
    border-color: var(--primary);
    background: #fff;
}
.ts-upload-files {
    font-size: 11px;
    color: var(--primary);
    font-weight: 500;
    margin-top: 4px;
}

/* ── Main Area ─────────────────────────────────────────────── */

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* ── File Tabs ─────────────────────────────────────────────── */

.file-tabs-bar {
    display: flex;
    align-items: center;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    min-height: 36px;
    flex-shrink: 0;
    overflow: hidden;
}

.file-tabs-scroll {
    display: flex;
    align-items: center;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    padding: 0 4px;
}

.file-tabs-scroll::-webkit-scrollbar {
    height: 4px;
}

.file-tabs-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.file-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    transition: color var(--transition), border-color var(--transition), background var(--transition);
    flex-shrink: 0;
    max-width: 200px;
}

.file-tab:hover {
    color: var(--text);
    background: rgba(0,0,0,0.03);
}

.file-tab.active {
    border-bottom-color: currentColor;
    font-weight: 600;
}

/* Original files — blue */
.file-tab.tab-original { color: #3b82f6; }
.file-tab.tab-original svg { stroke: #3b82f6; }
.file-tab.tab-original.active { color: #2563eb; border-bottom-color: #2563eb; }

/* Generated files — red */
.file-tab.tab-generated { color: var(--primary); }
.file-tab.tab-generated svg { stroke: var(--primary); }
.file-tab.tab-generated.active { color: var(--primary-dark); border-bottom-color: var(--primary-dark); }

.file-tab .tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-tab .tab-close {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    line-height: 1;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition);
}

.file-tab .tab-close:hover {
    background: var(--danger);
    color: #fff;
}

.file-tab .tab-dl {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    padding: 1px;
    transition: color var(--transition);
}

.file-tab .tab-dl svg {
    width: 13px;
    height: 13px;
}

.file-tab .tab-dl:hover {
    color: var(--primary);
}

.file-tab .merge-check {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.file-tab-add {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    margin: 0 4px;
    transition: background var(--transition), color var(--transition);
}

.file-tab-add:hover {
    background: var(--primary-light);
    color: var(--primary);
}

/* ── Viewer ────────────────────────────────────────────────── */

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

.viewer {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

.thumb-strip {
    width: 110px;
    min-width: 110px;
    overflow-y: auto;
    background: #f0f2f5;
    border-right: 1px solid var(--border);
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
}

.thumb-strip::-webkit-scrollbar {
    width: 4px;
}

.thumb-strip::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.thumb-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
    transition: border-color var(--transition), box-shadow var(--transition);
    position: relative;
    flex-shrink: 0;
}

.thumb-item:hover {
    border-color: #ccc;
}

.thumb-item.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(214, 48, 49, 0.2);
}

.thumb-item img {
    width: 100%;
    display: block;
}

.thumb-item .thumb-num {
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    padding: 2px;
    color: var(--text-muted);
    background: #f9fafb;
}

/* Rotate indicator on thumbnails */
.thumb-item .thumb-rotate-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--primary);
    color: #fff;
    font-size: 8px;
    padding: 1px 4px;
    border-radius: 2px;
    font-weight: 700;
}

/* Drag handle for reorder mode */
.thumb-item.draggable {
    cursor: grab;
}
.thumb-item.draggable:active {
    cursor: grabbing;
}
.thumb-item.drag-over {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(214, 48, 49, 0.2);
}
.thumb-item.dragging {
    opacity: 0.4;
}

/* Split selection highlight */
.thumb-item.selected-split {
    border-color: var(--success);
    box-shadow: 0 0 0 2px rgba(56, 161, 105, 0.2);
}

.thumb-item .split-check {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--success);
    color: #fff;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.preview-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.zoom-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

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

.zoom-level {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
    font-weight: 600;
}

.page-preview {
    flex: 1 1 0;
    overflow: auto;
    padding: 0;
    background: #e8e8e8;
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 0;
}

.pages-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px;
}

.page-slot {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

.page-slot .page-loading {
    padding: 40px;
    color: var(--text-muted);
    font-size: 13px;
}

.preview-page-img {
    max-width: 100%;
    height: auto;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    background: #fff;
    display: block;
    object-fit: contain;
}

.page-preview .preview-placeholder {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 40px;
    align-self: center;
}

/* ── Empty / Drop Zone State ──────────────────────────────── */

.viewer-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-page);
}

.drop-zone-large {
    border: 3px dashed var(--border);
    border-radius: 16px;
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    max-width: 500px;
    width: 90%;
}

.drop-zone-large:hover,
.drop-zone-large.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone-large .dz-icon {
    margin-bottom: 16px;
    color: var(--text-muted);
}

.drop-zone-large .dz-icon svg {
    width: 48px;
    height: 48px;
}

.drop-zone-large .dz-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.drop-zone-large .dz-hint {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Tool Panel (legacy, kept for compatibility) ──────────── */

.tool-panel {
    border-top: 1px solid var(--border);
    background: var(--bg);
    padding: 16px 20px;
    flex-shrink: 0;
    overflow-y: auto;
    max-height: 45vh;
}

.tool-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.tool-panel-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.tool-panel-close {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-panel-close:hover {
    background: #f0f0f0;
}

.tool-panel-body {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.tool-panel-body .form-group {
    margin-bottom: 0;
    min-width: 140px;
}

.tool-panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* ── Settings Page (rendered in main area) ─────────────────── */

.settings-page {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    background: var(--bg-page);
}

.tool-page {
    max-width: 960px;
    margin: 0 auto;
}

.tool-page h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text);
}

.tool-page .tool-desc {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

/* ── Upload Zone (small, for tool panel) ──────────────────── */

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--bg);
    margin-bottom: 12px;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone .upload-icon {
    margin-bottom: 6px;
    color: var(--text-muted);
}

.upload-zone .upload-text {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    margin-bottom: 2px;
}

.upload-zone .upload-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.upload-zone .upload-files {
    margin-top: 8px;
    font-size: 12px;
    color: var(--primary);
    font-weight: 500;
}

.upload-zone input[type="file"] {
    display: none;
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 20px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: #f0f0f0;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #c53030;
    border-color: #c53030;
}

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

/* ── Forms ─────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    border: 1px solid #cbd5e0;
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    transition: border-color var(--transition);
    font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(214, 48, 49, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-select {
    appearance: auto;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13px;
    cursor: pointer;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* ── Page Number Overlay ──────────────────────────────────── */

.pn-overlay {
    color: rgba(0, 0, 0, 0.7);
    font-family: serif;
    pointer-events: none;
    white-space: nowrap;
    z-index: 5;
    background: rgba(255, 220, 100, 0.3);
    padding: 1px 6px;
    border-radius: 2px;
}

/* ── Password Prompt ──────────────────────────────────────── */

.pw-prompt {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    z-index: 20;
}

.pw-prompt-box {
    text-align: center;
    padding: 32px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-width: 320px;
}

.pw-prompt-box h3 {
    margin-bottom: 4px;
    font-size: 16px;
}

/* ── Watermark Overlay ────────────────────────────────────── */

.wm-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    font-weight: 700;
    font-family: Arial, sans-serif;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
    letter-spacing: 0.1em;
    user-select: none;
}

/* ── Signature Overlay ─────────────────────────────────────── */

.sig-overlay {
    position: absolute;
    cursor: grab;
    border: 2px dashed var(--primary);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.92);
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    user-select: none;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    touch-action: none;
}

.sig-overlay:active {
    cursor: grabbing;
}

.sig-overlay .sig-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    align-self: stretch;
    min-width: 60px;
}

.sig-overlay .sig-image {
    max-width: 70px;
    object-fit: contain;
    flex-shrink: 1;
}

.sig-overlay .sig-divider {
    width: 1px;
    align-self: stretch;
    background: var(--border);
    flex-shrink: 0;
}

.sig-overlay .sig-details {
    font-size: 10px;
    line-height: 1.5;
    color: var(--text);
}

.sig-overlay .resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary);
    border: 1px solid white;
    border-radius: 2px;
    z-index: 20;
}
.sig-overlay .resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.sig-overlay .resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.sig-overlay .resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.sig-overlay .resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

.sig-overlay .sig-badge {
    position: absolute;
    bottom: 1px;
    left: 1px;
    max-width: 48%;
    overflow: hidden;
    background: var(--primary);
    color: #fff;
    font-size: 7px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 5px;
    border-radius: 0 2px 0 2px;
    white-space: nowrap;
    text-align: center;
    line-height: 1;
    z-index: 5;
}

/* ── Result Card ───────────────────────────────────────────── */

.result-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: var(--shadow);
}

.result-card .result-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-card .result-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    background: #f0fdf4;
    color: var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-card .result-text h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 1px;
}

.result-card .result-text p {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Before / After ────────────────────────────────────────── */

.before-after {
    display: flex;
    gap: 16px;
    margin-top: 16px;
}

.before-after .ba-panel {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.before-after .ba-panel .ba-header {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
}

.before-after .ba-panel img {
    width: 100%;
    display: block;
}

/* ── Redact ────────────────────────────────────────────────── */

.redact-canvas-wrap {
    position: relative;
    display: inline-block;
    cursor: crosshair;
}

.redact-canvas-wrap img {
    display: block;
    max-width: 100%;
}

.redact-rect {
    position: absolute;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(0, 0, 0, 0.6);
}

.redact-rect .redact-delete {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    display: none;
}

.redact-rect:hover .redact-delete {
    display: block;
}

.redact-list {
    margin-top: 12px;
}

.redact-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 11px;
}

/* ── Modal ─────────────────────────────────────────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 520px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
}

.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: #f0f0f0;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Toast ─────────────────────────────────────────────────── */

#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    font-weight: 500;
    animation: toast-in 0.3s ease;
    max-width: 360px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

.toast.toast-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* ── Spinner ───────────────────────────────────────────────── */

#spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-text {
    margin-top: 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Page Selector ─────────────────────────────────────────── */

.page-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    font-size: 13px;
}

.page-selector button {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.page-selector button:hover {
    background: #f0f0f0;
}

/* ── Settings page ─────────────────────────────────────────── */

.settings-section {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.settings-section h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.sig-preview-img {
    max-height: 80px;
    max-width: 200px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    background: #fff;
}

/* ── Admin Users Table ─────────────────────────────────────── */

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

.users-table th,
.users-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.users-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.users-table tr:hover td {
    background: #f9fafb;
}

/* ── Text Output ───────────────────────────────────────────── */

.text-output {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: var(--radius);
    padding: 16px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 12px;
}

/* ── Preview Container (for esign/redact in tool panel) ────── */

.preview-container {
    position: relative;
    background: #e8e8e8;
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-container img {
    max-width: 100%;
    display: block;
}

.preview-placeholder {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 40px;
}

/* ── Coming Soon ───────────────────────────────────────────── */

.coming-soon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    gap: 12px;
}

.coming-soon svg {
    width: 48px;
    height: 48px;
    opacity: 0.4;
}

.coming-soon h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.coming-soon p {
    font-size: 13px;
}

/* ── Two Column Layout ─────────────────────────────────────── */

.two-col {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.two-col .col-left {
    flex: 0 0 340px;
}

.two-col .col-right {
    flex: 1;
    min-width: 0;
}

/* ── Responsive ────────────────────────────────────────────── */

.mobile-header {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
}

.mobile-header .hamburger {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 500;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: none;
        height: 100vh;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-md);
    }

    .mobile-header {
        display: flex;
    }

    .thumb-strip {
        width: 80px;
        min-width: 80px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .two-col {
        flex-direction: column;
    }

    .two-col .col-left {
        flex: none;
        width: 100%;
    }
}

/* ── Utility ───────────────────────────────────────────────── */

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.inline-flex { display: inline-flex; align-items: center; }

/* ── Rotate Thumbnail Controls ──────────────────────────────── */

.thumb-rotate-controls {
    position: absolute;
    bottom: 18px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    z-index: 5;
}

.thumb-rot-btn {
    width: 22px;
    height: 22px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
    line-height: 1;
}

.thumb-rot-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* ── Text Block Overlay (click-to-edit) ──────────────────── */

.text-block-overlay {
    background: transparent;
    border: 1px dashed transparent;
    transition: background 0.15s, border-color 0.15s;
    z-index: 5;
}

.text-block-overlay:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.4);
}

.text-block-overlay.selected {
    background: rgba(59, 130, 246, 0.15);
    border-color: #3b82f6;
    border-style: solid;
}
