/* canvas.css — tldraw-inspired layout
   Place in: wwwroot/css/canvas.css
*/

/* ── Reset & base ─────────────────────────────────────────────────────── */
.canvas-app * {
    box-sizing: border-box;
}

.canvas-app {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 13px;
    background: #f0f0f0;
    color: #1a1a1a;
}

.canvas-container {
    border: none !important;
}
/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
    width: 0;
    overflow: hidden;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    flex-shrink: 0;
}

    .sidebar.open {
        width: 220px;
        overflow: visible !important;
    }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px 10px;
    border-bottom: 1px solid #f0f0f0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #111;
}

.sidebar-section-label {
    padding: 10px 12px 4px;
    font-size: 11px;
    font-weight: 500;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.doc-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.doc-item {
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    color: #374151;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
}

    .doc-item:hover {
        background: #f3f4f6;
    }

    .doc-item.active {
        background: #eff6ff;
        color: #2563eb;
        font-weight: 500;
    }

    /* Nút icon mặc định sẽ ẩn */
    .doc-item .icon-btn {
        opacity: 0;
        transition: opacity 0.2s ease-in-out;
        background: transparent;
        border: none;
        cursor: pointer;
        flex-shrink: 0; /* Đảm bảo nút không bị bóp méo khi tên quá dài */
    }

    /* Khi hover vào dòng (doc-item) thì hiện nút */
    .doc-item:hover .icon-btn {
        opacity: 1;
    }

.doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-rename-input {
    border: 1px solid #3b82f6;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 13px;
    width: 100%;
    outline: none;
    background: #fff;
}

/* Đảm bảo phần tên chiếm hết không gian còn lại và xuống dòng nếu quá dài */
.doc-name, .doc-rename-input {
    flex-grow: 1;
    margin-right: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid #f0f0f0;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
}

    .user-chip:hover {
        background: #f3f4f6;
    }

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #6366f1;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

/* ── Main area ────────────────────────────────────────────────────────── */
.canvas-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* ── Topbar ───────────────────────────────────────────────────────────── */
.topbar {
    height: 44px;
    background: #fff;
    /*border-bottom: 1px solid #e5e7eb;*/
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px 0 8px;
    gap: 8px;
    flex-shrink: 0;
    z-index: 10;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #374151;
}

.breadcrumb-doc {
    font-weight: 500;
    color: #6b7280;
}

.breadcrumb-sep {
    color: #d1d5db;
}

.breadcrumb-page {
    display: flex;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 5px;
    color: #111;
    transition: background 0.1s;
}

    .breadcrumb-page:hover {
        background: #f3f4f6;
    }

/* ── Page menu ────────────────────────────────────────────────────────── */
.page-menu {
    position: absolute;
    top: 44px;
    left: 90px;
    /*transform: translateX(-30%);*/
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
    min-width: 180px;
    z-index: 100;
    padding: 6px 0;
}

.page-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px 6px;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.page-menu-actions {
    display: flex;
    gap: 2px;
}

.page-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    color: #374151;
    transition: background 0.1s;
}

    .page-item:hover {
        background: #f3f4f6;
    }

    .page-item.active {
        color: #2563eb;
        font-weight: 500;
    }

    /* Nút icon mặc định sẽ ẩn */
    .page-item .icon-btn {
        opacity: 0;
        transition: opacity 0.2s ease-in-out;
        background: transparent;
        border: none;
        cursor: pointer;
        flex-shrink: 0; /* Đảm bảo nút không bị bóp méo khi tên quá dài */
    }

    /* Khi hover vào dòng (doc-item) thì hiện nút */
    .page-item:hover .icon-btn {
        opacity: 1;
    }

/* Nhóm nội dung bên trái (Avatar + Tên hoặc Icon + Tên) */
.page-content, .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-grow: 1;
    overflow: hidden;
}

/* Ép tên không bị tràn làm đẩy nút ra ngoài */
.user-chip span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
}

/* Container chứa mục Theme */
.has-submenu {
    position: relative; /* Gốc tọa độ cho sub-menu con */
}

/* Layout cho nội dung chính của mục Theme */
.menu-item-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Định dạng khối Sub-menu */
.sub-menu {
    display: none; /* Mặc định ẩn */
    position: absolute;
    left: 100%; /* Đẩy sang phải hoàn toàn so với menu chính */
    top: 0; /* Căn lề trên bằng với lề trên của mục Theme */
    min-width: 120px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 4px 0;
    z-index: 1001;
    margin-left: 2px; /* Tạo khoảng hở nhỏ giữa 2 menu */
}

.sub-menu {
    /*left: auto;*/
    /*right: 100%;*/ /* Bung sang bên trái thay vì bên phải */
    margin-right: 2px;
}

/* HIỆU ỨNG HOVER: Khi di chuột vào cha thì hiện con */
.has-submenu:hover > .sub-menu {
    display: block;
}

/* Tạo "cầu nối" vô hình để khi di chuột qua khoảng hở 2px không bị mất hover */
.sub-menu::before {
    content: "";
    position: absolute;
    left: -10px;
    top: 0;
    width: 10px;
    height: 100%;
}

/* ── Workspace ────────────────────────────────────────────────────────── */
.canvas-workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle, #d1d5db 1px, transparent 1px);
    background-size: 24px 24px;
    background-color: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .canvas-workspace canvas {
        border-radius: 4px;
        box-shadow: 0 2px 16px rgba(0,0,0,.12);
    }

/* ── Bottom toolbar ───────────────────────────────────────────────────── */
.bottom-toolbar {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 5px 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    z-index: 20;
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-left {
    margin-right: 4px;
}

.toolbar-right {
    margin-left: 4px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: #e5e7eb;
    margin: 0 4px;
}

.zoom-btn {
    background: none;
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: background 0.1s;
    min-width: 44px;
    text-align: center;
}

    .zoom-btn:hover {
        background: #f3f4f6;
    }

/* ── Right panel ──────────────────────────────────────────────────────── */
.right-panel {
    position: absolute;
    right: 12px;
    top: 56px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 20;
}

.panel-colors {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.color-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
    padding: 0;
}

    .color-dot:hover {
        transform: scale(1.15);
    }

    .color-dot.active {
        border-color: #3b82f6;
        transform: scale(1.1);
    }

    .color-dot[style*="#ffffff"] {
        border-color: #d1d5db;
    }

.panel-size {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 6px;
    display: flex;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

/* SAU */
.size-slider {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 22px;
    height: 80px;
    cursor: pointer;
    accent-color: #3b82f6;
}

.panel-shapes {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 3px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.shape-btn {
    width: 26px;
    height: 26px;
    background: none;
    border: 1px solid #e5e7eb;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

    .shape-btn:hover {
        background: #f3f4f6;
    }

.panel-size-labels {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 5px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.size-label {
    background: none;
    border: none;
    padding: 3px 6px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.1s;
    text-align: center;
}

    .size-label:hover {
        background: #f3f4f6;
        color: #111;
    }

    .size-label.active {
        background: #eff6ff;
        color: #2563eb;
    }

/* ── Shared button styles ─────────────────────────────────────────────── */
.icon-btn {
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    transition: background 0.1s, color 0.1s;
    padding: 0;
    flex-shrink: 0;
}

    .icon-btn:hover {
        background: #f3f4f6;
        color: #111;
    }

    .icon-btn.sm {
        width: 24px;
        height: 24px;
        border-radius: 4px;
    }

.tool-btn {
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    transition: background 0.1s, color 0.1s;
    padding: 0;
}

    .tool-btn:hover {
        background: #f3f4f6;
        color: #111;
    }

    .tool-btn.active {
        background: #2563eb;
        color: #fff;
    }

.btn-outline {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 7px;
    border: 1px solid #e5e7eb;
    background: #fff;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: background 0.1s;
}

    .btn-outline:hover {
        background: #f3f4f6;
    }

.btn-primary {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    border-radius: 7px;
    border: none;
    background: #2563eb;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    transition: background 0.1s;
}

    .btn-primary:hover {
        background: #1d4ed8;
    }

/* Thẻ bao ngoài của Menu */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999;
    background: transparent; /* Hoặc rgba(0,0,0,0.01) để debug */
}

.custom-menu {
    position: absolute;
    /*top: 100%; */ /* Hiển thị ngay dưới nút bấm */
    /* right: 0;*/ /* Căn lề phải bằng với lề phải của nút bấm */
    z-index: 1000;
    min-width: 160px;
    max-width: 160px;
    background-color: #ffffff;
    border-radius: 8px;
    /*box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); */ /* Đổ bóng nhẹ như hình */
    box-shadow: 0 10px 25px rgba(0,0,0,0.2); /* Đổ bóng đậm hơn để nổi bật */
    padding: 4px 0;
    border: 1px solid #eee;
    /* Loại bỏ transition nếu dùng tọa độ chuột để tránh menu "chạy" theo */
}
/* Từng dòng trong menu */
.menu-item {
    padding: 10px 16px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.2s;
}

    .menu-item:hover {
        background-color: #f5f5f5; /* Màu nền khi hover vào option */
    }

    /* Màu riêng cho nút Delete */
    .menu-item.delete {
        color: #d32f2f;
    }

/* Đường kẻ ngang chia tách (giữa Pin và Delete) */
.menu-divider {
    height: 1px;
    background-color: #eee;
    margin: 4px 0;
}
/* Giữ highlight nền và hiện nút icon khi đang mở Menu */
.page-item.menu-open, .doc-item.menu-open {
    background-color: #f0f0f0; /* Màu nền highlight khi mở menu */
    color: #000;
}

    /* Quan trọng: Giữ cho nút ba chấm luôn hiện khi menu đang mở */
    .page-item.menu-open .icon-btn, .doc-item.menu-open .icon-btn {
        opacity: 1;
        color: #333;
    }

/* Nếu bạn muốn dòng đang Active và dòng đang mở Menu có màu khác nhau một chút */
.page-item.active.menu-open, .doc-item.active.menu-open {
    background-color: #e8f0fe;
    color: #1a73e8;
}

.user-menu-popup {
    position: absolute;
    /* Cách đáy của user-chip khoảng 50px để nó nằm lơ lửng bên trên */
    bottom: calc(100% + 10px);
    right: 0;
    min-width: 160px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    z-index: 999; /* Cao hơn overlay */
    padding: 6px 0;
    /* Chống bị cắt bởi các thẻ cha khác nếu có overflow: hidden */
    /* Lưu ý: Nếu sidebar-footer có overflow: hidden, absolute vẫn sẽ bị cắt */
}

/* Thêm hiệu ứng xuất hiện cho chuyên nghiệp */
.user-menu-popup {
    animation: popupSlideUp 0.15s ease-out;
}

.more-tools-menu {
    position: absolute;
    bottom: 42px; /* Điều chỉnh tùy theo vị trí toolbar */
    /*left: 50%;*/
    right: 0;
    /*transform: translateX(-50%);*/
    background: #ffffff; /* Nền trắng */
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    min-width: 140px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1); /* Đổ bóng nhẹ nhàng */
    z-index: 1000;
}

.tool-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: #333333; /* Chữ tối */
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease;
}

    /* Hiệu ứng khi hover vào item */
    .tool-item:hover {
        background: #f0f2f5;
        color: #000;
    }

    .tool-item span {
        flex-grow: 1;
        text-align: left;
    }
/* Đường kẻ ngăn cách các nhóm tool */
.menu-divider {
    height: 1px;
    background: #eeeeee;
    margin: 4px 8px;
}

.more-tools-menu-d {
    position: absolute;
    bottom: 50px; /* Cách toolbar một khoảng */
    left: 50%;
    transform: translateX(-50%);
    background: #2c2c2c; /* Màu tối cho đồng bộ */
    border: 1px solid #444;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    z-index: 100;
}

.tool-item-d {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    white-space: nowrap;
}

    .tool-item-d:hover {
        background: rgba(255, 255, 255, 0.1);
    }
/* ── Scrollbar ────────────────────────────────────────────────────────── */
.doc-list::-webkit-scrollbar {
    width: 4px;
}

.doc-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

/* ── Sidebar collapse button ── */
.sidebar-collapse-btn {
    display: none; /* ẩn trên desktop */
    width: 26px;
    height: 26px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
    color: #6b7280;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.1s, color 0.1s;
    margin-left: auto;
}

    .sidebar-collapse-btn:hover {
        background: #f3f4f6;
        color: #111;
    }

@media (max-width: 768px) {
    .sidebar-collapse-btn {
        display: flex; /* chỉ hiện khi sidebar là overlay */
    }
}
