:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --sidebar-w: 300px;
    --tools-sidebar-w: 68px;
    --header-h: 54px;
}

html {
    height: 100%;
}

/* 1. CORREÇÃO DO CORPO */
body { 
    margin: 0; 
    font-family: 'Segoe UI', sans-serif; 
    height: 100%; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; /* Remove scroll do body */

}

/* 2. TOOLBAR */
.toolbar { 
    height: var(--header-h);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 6px rgba(0,0,0,.07);
    display: flex; 
    flex-direction: row; 
    align-items: center; 
    padding: 0 16px; 
    gap: 10px; 
    color: #1e293b; 
    z-index: 2000;
    flex-shrink: 0;
}

.logo {
    display: inline-flex;
    align-items: center;
    min-width: 160px;
}

.logo-img {
    height: 50px;
    width: auto;
    display: block;
}

.header-spacer { flex: 1; }

.header-palette {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
}

#header-palette-colors {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.header-color-dot {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #cbd5e1;
    cursor: pointer;
}

.header-color-dot.selected {
    border: 3px solid #ffffff;
    box-shadow: 0 0 0 1px #111827;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Divisor vertical no header */
.h-divider {
    width: 1px;
    height: 24px;
    background: #e2e8f0;
    margin: 0 4px;
}

/* ── BOARD LAYOUT ── */
.board-layout {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: visible;
    min-height: 0;
    position: relative;
}

/* ── LEFT TOOLS SIDEBAR ── */
.tools-sidebar {
    width: var(--tools-sidebar-w);
    min-width: var(--tools-sidebar-w);
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    overflow: visible;
    z-index: 3000;
    position: relative;
    flex-shrink: 0;
}

.tools-sidebar-scroll {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.tools-divider {
    width: 60%;
    height: 1px;
    background: #e2e8f0;
    margin: 4px 0;
}

/* 3. WORKSPACE COM SUPORTE A ZOOM */
#workspace {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 60px 20px;
    background-color: #d3d3d3;
    position: relative;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    min-height: 0;
    z-index: 1;
}

body.pan-mode,
body.pan-mode * {
    cursor: grab !important;
}

body.pan-active,
body.pan-active * {
    cursor: grabbing !important;
}

#workspace-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    transform-origin: 0 0;
}

/* FOLHA A4 - ADICIONADO SUPORTE A TRANSFORMAÇÃO */
.folha-a4 {
    background: white;
    width: 210mm;
    height: 297mm;
    min-width: 210mm;
    min-height: 297mm;
    max-height: 297mm; /* Garante que não ultrapassa */
    position: relative;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    overflow: visible; /* Mudamos para visible para não cortar o traço no limite exato */
    /* Configuração de Zoom */
    transition: transform 0.2s ease-out; 
    transform-origin: top center; /* Garante que a folha cresça para baixo e para os lados */
}

/* ── BOTÕES ── */
.tool-btn {
    background: #f1f5f9;
    border: none;
    color: #1e293b;
    padding: 8px 13px;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
    font-weight: 500;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}

.tool-btn i.lucide {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    flex-shrink: 0;
}

.toolbar .tool-btn i.lucide {
    width: 1.1rem;
    height: 1.1rem;
}

.tools-sidebar .tool-btn i.lucide,
.tools-sidebar .tool-dropdown i.lucide {
    width: 15px;
    height: 15px;
}

.lucide {
    height:1.1rem;
}

.header-actions .tool-btn span {
    font-size: 13px;
}

.tool-btn:hover {
    background: var(--accent);
    color: #fff;
}

.tool-btn.active {
    background: var(--accent);
    color: #fff;
}

.tool-btn:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.8;
}

.tool-btn:disabled:hover {
    background: #e2e8f0;
    color: #94a3b8;
}

/* Tools na sidebar esquerda: botões quadrados */
.tools-sidebar-scroll .tool-btn,
.tools-sidebar-scroll .tool-dropdown {
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 10px;
    font-size: 18px;
}

.tool-dropdown {
    position: relative;
    z-index: 3100;
}

.tool-dropdown > span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* Menu de sub-ferramentas */
.shape-menu {
    display: none;
    position: fixed;
    background: #fff;
    padding: 6px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    gap: 6px;
    flex-wrap: wrap;
    z-index: 10000;
}

/* Na sidebar vertical: abre para a direita */
.tools-sidebar .shape-menu {
    top: 0;
    left: 0;
    margin-left: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    min-width: 46px;
}

.tool-dropdown.open .shape-menu {
    display: flex;
}

.tools-sidebar .tool-dropdown.open {
    z-index: 3300;
}

.shape-option {
    background: #f1f5f9;
    color: #1e293b;
    border: none;
    border-radius: 10px;
    width: 46px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.shape-option i.lucide {
    width: 15px;
    height: 15px;
}

.shape-option:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-1px);
}

.shape-option-labeled {
    width: auto;
    min-width: 170px;
    padding: 0 12px;
    justify-content: flex-start;
    gap: 10px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
}

.shape-option-labeled span {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.shape-option-labeled small {
    font-weight: 400;
    font-size: 11px;
    opacity: 0.75;
}

.shape-option-labeled#btn-pdf-eraser {
    border-left: 3px solid #e11d48;
}

.shape-option-labeled#btn-eraser-ink {
    border-left: 3px solid #2563eb;
}

.shape-option.selected {
    background: var(--accent);
    color: #fff;
}

/* FUNDOS */
.pautado {
    background-color: #fff;
    background-image: linear-gradient(#e5e5e5 1px, transparent 1px);
    background-size: 100% 30px;
}

.quadriculado {
    background-color: #fff;
    background-image: 
        linear-gradient(#e5e5e5 1px, transparent 1px),
        linear-gradient(90deg, #e5e5e5 1px, transparent 1px);
    background-size: 20px 20px;
}

/* ── STATUS BADGE ── */
#status-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    background: #f1f5f9;
    color: #334155;
}

#users-online {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    padding: 4px 10px;
    border-radius: 20px;
    background: #f1f5f9;
    color: #334155;
    font-size: 12px;
    font-weight: bold;
}
#users-online .users-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #27ae60;
}

/* SIDEBAR FIXA (painel de opções à direita) */
#sidebar { 
    position: fixed;
    right: -300px; 
    top: var(--header-h);
    bottom: 0;
    width: var(--sidebar-w);
    background: #f8f9fa;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1500;
    padding: 25px;
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

#sidebar.open { right: 0; }

#sidebar h3 {
    margin-top: 0;
    border-bottom: 2px solid #ddd;
    padding-bottom: 10px;
    color: var(--primary);
}

#sidebar-content {
    flex: 1;
}

#sidebar-content label {
    display: block;
    margin-top: 12px;
    margin-bottom: 5px;
    font-size: 13px;
    color: #555;
    font-weight: 500;
}

#sidebar-content input[type="number"],
#sidebar-content input[type="text"],
#sidebar-content input[type="color"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    box-sizing: border-box;
}

#sidebar-content input[type="range"] {
    width: calc(100% - 40px);
    margin-right: 10px;
}

#sidebar-content input[type="checkbox"] {
    margin-right: 8px;
}

.control-group label {
    font-size: 14px;
    color: #555;
    font-weight: bold;
}

/* Adiciona isto ao final do style.css */
.folha-a4 canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    touch-action: none; /* Melhora a precisão em tablets/telemóveis */
}

@media print {
    #sidebar, .toolbar, .tools-sidebar { display: none !important; }
    #workspace { padding: 0 !important; background: white !important; }
    .folha-a4 { box-shadow: none !important; margin: 0 !important; }
}

/* Botão de apagar no canto da folha */
.btn-apagar-folha {
    position: absolute;
    top: -15px;
    right: -15px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    z-index: 10;
    display: none; /* Só aparece para o professor */
}

.folha-a4:hover .btn-apagar-folha {
    display: block;
}

/* Botão de adicionar página abaixo de cada folha */
.btn-adicionar-pagina {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 50px;
    font-size: 14px;
    font-weight: bold;
    margin: 8px auto 20px auto;
    display: block;
    transition: all 0.3s;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Acoes por pagina: fundo e delete */
.page-container {
    position: relative;
    display: inline-block;
    margin-bottom: 60mm;
    transform-origin: top center;
}

.page-actions {
    position: absolute;
    top: 10px;
    right: -50px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 5;
}

.btn-action-circle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #0f172a;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.btn-action-circle:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.18);
}

.btn-action-circle.apagar {
    border-color: #f87171;
    color: #b91c1c;
    background: #fff5f5;
}

.btn-add-circular {
    position: absolute;
    bottom: -65px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: #2563eb;
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.btn-add-circular:hover {
    transform: translateX(-50%);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.btn-adicionar-pagina:hover {
    background: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Modal para seleção de tipo de página */
.modal-tipo-pagina {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

.modal-tipo-pagina.open {
    display: flex;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 1.5rem;
    box-shadow: 0 5px 30px rgba(0,0,0,0.3);
    text-align: center;
}

.modal-content h3 {
    margin-top: 0;
    color: var(--primary);
}

.modal-logo-wrap {
    display: flex;
    justify-content: center;
    margin: 0 auto 16px;
}

.modal-logo-img {
    height: 72px;
    width: auto;
    display: block;
}

.tipo-pagina-btns {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.btn-tipo-pagina {
    padding: 15px 25px;
    border: 2px solid var(--accent);
    background: white;
    color: var(--accent);
    cursor: pointer;
    border-radius: 0.75rem;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s;
    box-shadow: 3px 6px 20px 0px #3498db30;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-tipo-pagina i.lucide {
    width: 18px;
    height: 18px;
}

.btn-tipo-pagina:hover {
    background: var(--accent);
    color: white;
}

.btn-cancelar {
    margin-top: 15px;
    padding: 10px 20px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/* Efeito visual ao arrastar ficheiro */
.drag-over {
    border: 4px dashed #3498db !important;
    background: rgba(52, 152, 219, 0.1) !important;
}

/* Imagem de fundo do PDF na folha */
.folha-pdf-bg {
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
}

/* Estilos para as camadas (layers) */
.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Layers antigas - não são mais usadas, ocultando */
.layer-background,
.layer-base,
.layer-documents,
.layer-marker,
.layer-pen,
[class^="layer-"] {
    display: none !important;
}

.folha-a4 {
    position: relative;
}

.canvas-pdf-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0 !important;
    /* Máscara de PDF - entre o background e os outros canvases */
}

.canvas-marker {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1 !important;
    /* Camada traseira - marcador desenha aqui */
}

.canvas-pen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999 !important;
    will-change: z-index;
    transform: translateZ(0);
    /* Camada frontal - caneta e borracha desenham aqui - SEMPRE à frente */
    touch-action: none;
    cursor: crosshair;
}

/* Cursor otimizado para stylus/caneta no iPad */
@supports (cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="6" fill="black" opacity="0.5"/><circle cx="16" cy="16" r="14" fill="none" stroke="black" stroke-width="1" opacity="0.3"/></svg>') 16 16, auto) {
    .canvas-pen {
        cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="4" fill="black"/><circle cx="16" cy="16" r="12" fill="none" stroke="black" stroke-width="1" opacity="0.3"/></svg>') 16 16, crosshair;
    }
}

/* Suporte a toque no iPad e tablets */
@media (pointer: coarse) {
    .canvas-pen {
        cursor: auto;
    }
}
/* Overlay de objetos matem�ticos */
.math-object-overlay {
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.math-object-overlay:hover {
    border-color: #0088ff !important;
}

.math-object-overlay canvas {
    pointer-events: none;
}

/* Canvas de pré-visualização para linha e formas (camada transparente ultra-rápida) */
.canvas-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000 !important;
    pointer-events: none !important;
    background: transparent !important;
}

/* Seletor de tipo de traço (Linha) */
.line-dash-selector {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.line-dash-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    color: #334155;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
    width: 100%;
    box-sizing: border-box;
}

.line-dash-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
}

.line-dash-btn.active {
    background: #eff6ff;
    border-color: #2563eb;
    color: #2563eb;
    font-weight: 600;
}

.line-dash-label {
    flex-shrink: 0;
    width: 95px;
    text-align: left;
}

.line-dash-svg {
    flex: 1;
    height: 12px;
    margin-left: 8px;
    overflow: visible;
}
