/**
 * PDF Question & Solution Cropper - Modern Responsive CSS
 * Designed for Desktop, Tablet, and Mobile devices (Hostinger PHP Ready)
 */

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --bg-input: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #60a5fa;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-color: #334155;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --sidebar-width: 380px;
    --header-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-light);
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    margin-left: 0.5rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* App Main Container */
.app-container {
    display: flex;
    flex: 1;
    min-height: calc(100vh - var(--header-height));
    position: relative;
}

/* Sidebar / Controls Panel */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-height));
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 90;
}

.sidebar-content {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.panel-section {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.panel-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-light);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Form Controls */
.form-group {
    margin-bottom: 0.875rem;
}

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

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-control, .form-select, .form-textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.875rem;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.form-control:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.form-textarea {
    resize: vertical;
    min-height: 65px;
    font-family: monospace;
    font-size: 0.8rem;
}

.form-hint {
    font-size: 0.725rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
}

/* PYQ Multi-Row Card Styles */
.pyq-row-card {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 0.65rem;
    position: relative;
    transition: border-color 0.2s;
}

.pyq-row-card:hover {
    border-color: #60a5fa;
}

.pyq-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.4rem;
}

.pyq-row-badge {
    background: #3b82f6;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
}

.btn-delete-pyq {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem;
}

.btn-delete-pyq:hover {
    color: #f87171;
}

/* Toggle Switches */
.toggle-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #334155;
    transition: .3s;
    border-radius: var(--radius-full);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background: var(--accent);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.45);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #334155;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.775rem;
}

.btn-block {
    width: 100%;
}

/* Main Workspace View */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary);
    overflow: hidden;
    position: relative;
}

/* Workspace Toolbar */
.workspace-toolbar {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    z-index: 50;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.page-indicator {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0 0.5rem;
}

/* Canvas Area */
.canvas-container {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1.5rem;
    background: #090d16;
}

.canvas-wrapper {
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    background: white;
    position: relative;
    max-width: 100%;
}

.canvas-stage {
    position: relative;
    user-select: none;
    touch-action: none;
}

.pdf-render-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.boxes-svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Bounding Box SVG Styles */
.box-rect {
    fill: rgba(16, 185, 129, 0.12);
    stroke-width: 2;
    transition: stroke-width 0.15s;
}

.box-rect.box-q {
    stroke: #10b981;
    fill: rgba(16, 185, 129, 0.12);
}

.box-rect.box-s {
    stroke: #f59e0b;
    fill: rgba(245, 158, 11, 0.12);
}

.box-group.selected .box-rect {
    stroke-width: 2.5;
    filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.6));
}

.box-label-bg.label-q {
    fill: #10b981;
}

.box-label-bg.label-s {
    fill: #f59e0b;
}

.box-label-text {
    fill: #ffffff;
    font-size: 11px;
    font-weight: 700;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.box-handle {
    fill: #ffffff;
    stroke: #3b82f6;
    stroke-width: 2.5;
    cursor: pointer;
    transition: transform 0.1s;
}

.box-handle:hover {
    transform: scale(1.3);
}

.handle-nw { cursor: nw-resize; }
.handle-ne { cursor: ne-resize; }
.handle-sw { cursor: sw-resize; }
.handle-se { cursor: se-resize; }
.handle-n  { cursor: n-resize; }
.handle-s  { cursor: s-resize; }
.handle-w  { cursor: w-resize; }
.handle-e  { cursor: e-resize; }

/* Bottom Floating Toolbar / Mobile Actions */
.floating-actions {
    position: absolute;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 0.4rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 60;
}

/* Modal and Progress Bar */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.progress-bar-bg {
    width: 100%;
    height: 10px;
    background: var(--bg-primary);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 1rem 0;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-gradient);
    width: 0%;
    transition: width 0.2s ease;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 300;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.875rem;
    color: var(--text-primary);
    min-width: 260px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive Styles for Tablet & Mobile */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 100%;
    }

    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: calc(100vh - var(--header-height));
        transform: translateY(100%);
    }

    .sidebar.open {
        transform: translateY(0);
    }

    .workspace {
        min-height: calc(100vh - var(--header-height));
    }

    .mobile-menu-toggle {
        display: block !important;
    }

    .floating-actions {
        width: 90%;
        justify-content: space-around;
        bottom: 0.75rem;
    }
}

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.35rem;
    cursor: pointer;
}
