:root {
    --bg-app: #f8f9fb;
    --bg-white: #ffffff;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

h1,
h2,
.logo-text {
    font-family: 'Outfit', sans-serif;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Top Navigation */
.top-nav {
    height: 64px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-left,
.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    background: var(--primary);
    color: white;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.2rem;
}

.logo-text {
    font-weight: 600;
    font-size: 1.1rem;
}

.logo-text span {
    color: var(--primary);
}

.divider {
    width: 1px;
    height: 24px;
    background: var(--border);
}

.project-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.project-breadcrumb .root {
    color: var(--text-muted);
}

.breadcrumb-sep {
    width: 14px;
    height: 14px;
    color: var(--border);
}

.project-title {
    font-size: 1rem;
    font-weight: 600;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--bg-app);
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Toolbar */
.toolbar {
    width: 64px;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 0;
    gap: 24px;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--bg-app);
    color: var(--text-main);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
}

.tool-btn svg {
    width: 20px;
    height: 20px;
}

/* Zoom Slider */
.zoom-controls {
    align-items: center;
    gap: 8px !important;
}

.zoom-slider-container {
    height: 100px;
    display: flex;
    align-items: center;
}

#zoomSlider {
    appearance: none;
    writing-mode: vertical-lr;
    direction: rtl;
    width: 6px;
    height: 100%;
    background: var(--border);
    outline: none;
    cursor: pointer;
    border-radius: 3px;
}

#zoomSlider::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

#zoomLevelText {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Brush Size Controls */
.brush-size-controls {
    align-items: center;
    gap: 6px !important;
    display: none;
    /* Hidden by default until Pen tool is active */
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.brush-slider-container {
    height: 80px;
    display: flex;
    align-items: center;
}

.brush-slider {
    appearance: none;
    writing-mode: vertical-lr;
    direction: rtl;
    width: 4px;
    height: 100%;
    background: var(--border);
    outline: none;
    cursor: pointer;
    border-radius: 2px;
}

.brush-slider::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.brush-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#brushSizeText {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 600;
}

@media (max-width: 768px) {
    .zoom-slider-container {
        display: none;
        /* Hide vertical slider on mobile bottom nav */
    }

    #zoomLevelText {
        display: none;
    }

    .zoom-controls {
        flex-direction: row !important;
    }
}

/* Page Sidebar */
.page-sidebar {
    width: 180px;
    background: #f1f5f9;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header-sm {
    padding: 16px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.add-icon {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.page-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.page-list::-webkit-scrollbar {
    width: 4px;
}

.page-list::-webkit-scrollbar-track {
    background: transparent;
}

.page-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.page-item {
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.page-item:hover {
    background: #e2e8f0;
}

.page-item.active {
    background: white;
    box-shadow: var(--shadow-sm);
}

.page-thumb {
    width: 100%;
    aspect-ratio: 1/1.2;
    background: white;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
    border: 1px solid var(--border);
}

.page-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.empty-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--border);
}

.page-name {
    font-size: 0.75rem;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ededed;
    overflow: auto;
    padding: 40px;
}

/* Fabric.js specific wrapper overrides */
.canvas-container {
    box-shadow: var(--shadow-lg) !important;
    background: white;
    margin: 0 auto;
}

#reviewCanvas {
    max-width: 100%;
    height: auto;
}

/* Marker Styles */
.comment-marker {
    position: absolute;
    width: 30px;
    height: 30px;
    background: var(--primary);
    color: white;
    border-radius: 50% 50% 0 50%;
    transform: translate(-15px, -30px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.2s;
}

.comment-marker:hover {
    transform: translate(-15px, -30px) scale(1.1);
}

/* Sidebar */
.comments-sidebar {
    width: 360px;
    min-width: 280px;
    max-width: 600px;
    background: var(--bg-white);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

/* Resizer Handle */
.resizer {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.2s;
    z-index: 100;
}

.resizer:hover,
.resizer.resizing {
    background: var(--primary);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header .count {
    background: var(--bg-app);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.filter-controls {
    display: flex;
    gap: 8px;
}

.filter-controls button {
    background: none;
    border: none;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 0;
}

.filter-controls button.active {
    color: var(--primary);
    font-weight: 600;
    border-bottom: 2px solid var(--primary);
}

.comment-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.comment-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.comment-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.comment-author {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.avatar {
    width: 32px;
    height: 32px;
    background: #fecaca;
    color: #991b1b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.avatar-blue {
    background: #bfdbfe;
    color: #1e40af;
}

.author-info {
    display: flex;
    flex-direction: column;
}

.author-info .name {
    font-size: 0.875rem;
    font-weight: 600;
}

.author-info .time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.comment-text {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-main);
}

.comment-actions {
    margin-top: 12px;
    display: flex;
    gap: 16px;
}

.btn-text {
    background: none;
    border: none;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
}

.btn-text:hover {
    color: var(--primary);
}

.comment-input-container {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

#newCommentInput {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
}

#newCommentInput:focus {
    border-color: var(--primary);
}

.btn-send {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-send:hover {
    transform: scale(1.05);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: white;
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: zoomIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: #fafafa;
}

/* Form Styles */
.copy-input {
    display: flex;
    gap: 8px;
}

.copy-input input {
    flex: 1;
    background: #f1f5f9;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-muted);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    cursor: pointer;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.form-group input[type="password"],
.form-group input[type="text"],
.form-group input[type="email"],
.form-group select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 100%;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

input[type="color"] {
    height: 40px;
    cursor: pointer;
    background: none;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.icon-sm {
    width: 14px;
    height: 14px;
    display: inline-block;
    vertical-align: middle;
}

/* Member List */
.member-invite {
    display: flex;
    gap: 8px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.member-invite input {
    flex: 2;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.member-invite select {
    flex: 1;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.member-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.member-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.member-info .name {
    font-size: 0.9rem;
    font-weight: 500;
}

.member-info .role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.role-select {
    border: none;
    background: none;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
}

.text-danger {
    color: #ef4444;
}

.btn-icon-text {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.comment-card.resolved {
    opacity: 0.6;
    background: #f9fafb;
}

.comment-card.resolved .comment-text {
    text-decoration: line-through;
}

/* Asset Item Delete */
.page-item {
    position: relative;
}

.btn-delete-asset {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: #ef4444;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}

.page-item:hover .btn-delete-asset {
    display: flex;
}

.btn-delete-asset i {
    width: 14px;
    height: 14px;
}

.loading-state {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.btn-icon-sm {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
}

.btn-icon-sm:hover {
    color: var(--primary);
}

/* Page Check UI */
.btn-check-page {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: #f3f4f6;
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-check-page:hover {
    background: #e5e7eb;
}

.btn-check-page.checked {
    background: #dcfce7;
    border-color: #22c55e;
    color: #166534;
}

.btn-check-page i {
    width: 14px;
    height: 14px;
}

.page-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    border: 1px solid transparent;
}

.page-item:hover {
    background: #f3f4f6;
}

.page-item.active {
    background: #eff6ff;
    border-color: var(--primary);
}

.page-check-status {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    background: #22c55e;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 5;
}

.page-check-status i {
    width: 12px;
    height: 12px;
}

/* --- Responsive Adjustments --- */
@media (max-width: 1024px) {
    .comments-sidebar {
        width: 300px;
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto;
        /* Allow scroll on small screens */
    }

    .top-nav {
        padding: 0 12px;
        height: 56px;
    }

    .nav-left .logo-text,
    .nav-left .divider,
    .nav-left .project-breadcrumb,
    .status-badge {
        display: none !important;
    }

    .nav-right .btn span,
    .nav-right .version-selector .label,
    .nav-right .btn-primary {
        display: none !important;
    }

    .nav-right button.btn {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        justify-content: center;
        border-radius: 50%;
    }

    .nav-right button.btn i {
        margin: 0 !important;
        width: 18px;
        height: 18px;
    }

    /* Show only icons for Members and Share */
    .nav-right .btn {
        padding: 8px;
        min-width: 40px;
        justify-content: center;
    }

    .nav-right .btn i {
        margin: 0;
    }

    .nav-right .version-selector {
        gap: 4px;
    }

    .main-layout {
        flex-direction: column;
        height: auto;
    }

    .toolbar {
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 8px 16px;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 500;
        justify-content: space-around;
        gap: 0;
    }

    .tool-group {
        flex-direction: row;
        gap: 8px;
    }

    .page-sidebar {
        width: 100%;
        height: auto;
        order: 2;
        border-right: none;
        border-bottom: 1px solid var(--border);
        background: white;
    }

    .sidebar-header-sm {
        padding: 8px 16px;
        font-size: 0.7rem;
    }

    .page-list {
        display: flex;
        /* Ensure flex for horizontal layout */
        flex-direction: row;
        overflow-x: auto !important;
        overflow-y: hidden;
        padding: 12px 16px;
        gap: 16px;
        -webkit-overflow-scrolling: touch;
        /* Smooth scroll for iOS */
    }

    /* Restore scrollbar visibility for visual feedback */
    .page-list::-webkit-scrollbar {
        display: block;
        height: 4px;
    }

    .page-list::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 4px;
    }

    .page-item {
        min-width: 80px;
        flex-shrink: 0;
        /* Prevent items from squeezing */
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 4px;
    }

    .page-thumb {
        width: 60px;
        height: 80px;
        margin-bottom: 4px;
    }

    .page-name {
        font-size: 0.65rem;
        width: 100%;
        text-align: center;
    }

    .workspace {
        padding: 10px;
        min-height: 350px;
        order: 1;
        overflow: auto;
        /* Allow scroll if needed, though we aim to fit */
        background: #f1f5f9;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        -webkit-overflow-scrolling: touch;
    }

    .canvas-container {
        transform-origin: top center;
        /* Let JS handle width to prevent coordinate mismatch */
        box-shadow: var(--shadow-md) !important;
        margin: 0 auto;
    }

    .comments-sidebar {
        width: 100%;
        height: auto;
        /* Restrict height on mobile to allow scrolling inside the list */
        max-height: 480px;
        display: flex;
        flex-direction: column;
        order: 3;
        border-left: none;
        border-top: 1px solid var(--border);
        margin-bottom: 60px;
        /* Space for bottom toolbar */
    }

    .comment-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Force explicit height to ensure scrolling works */
        height: 300px;
        max-height: none;
        background: white;
        /* Ensure visibility */
    }

    /* Mobile specific: Page Check Button */
    #pageCheckBtn span {
        display: none;
    }

    #pageCheckBtn {
        padding: 8px;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        justify-content: center;
    }

    .comment-input-container {
        position: sticky;
        bottom: 60px;
        background: white;
        z-index: 400;
    }

    /* Modal Mobile Adjustments */
    .modal-card {
        max-width: 95%;
        margin: 10px;
        max-height: 90vh;
    }
}