/* ==========================================================
   Peda — Pousada Encontro das Águas
   Explorer estilo macOS Finder
   ========================================================== */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #f5f5f7;
    --bg-panel: #ffffff;
    --bg-sidebar: #ebebed;
    --border: #d2d2d7;
    --border-soft: #e5e5ea;
    --text: #1d1d1f;
    --text-soft: #6e6e73;
    --text-mute: #8e8e93;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-soft: rgba(0, 113, 227, .12);
    --danger: #ff3b30;
    --danger-soft: rgba(255, 59, 48, .12);
    --success: #34c759;
    --warn: #ff9500;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, .08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .18);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --header-h: 72px;
    --sidebar-w: 260px;
    --toolbar-h: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    background: transparent;
    color: inherit;
}
input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* ====== Login ====== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(1200px 600px at 20% 10%, rgba(0, 113, 227, .18), transparent 60%),
        radial-gradient(1000px 500px at 90% 90%, rgba(52, 199, 89, .16), transparent 60%),
        linear-gradient(180deg, #e3f2ff 0%, #dff5ea 100%);
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-panel);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 40px 36px 32px;
    border: 1px solid var(--border-soft);
}
.login-brand {
    text-align: center;
    margin-bottom: 28px;
}
.login-brand .logo {
    width: 68px;
    height: 68px;
    border-radius: 18px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, #0ea5e9, #10b981);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    box-shadow: 0 8px 24px rgba(14, 165, 233, .3);
}
.login-brand h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 600;
}
.login-brand p {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--text-soft);
}
.login-field {
    margin-bottom: 14px;
}
.login-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-soft);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.login-field input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fafafa;
    outline: none;
    transition: border .15s, background .15s;
}
.login-field input:focus {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border-radius: 10px;
    font-weight: 600;
    font-size: 12px;
    margin-top: 8px;
    transition: background .15s, transform .1s;
}
.login-btn:hover:not(:disabled) { background: var(--accent-hover); }
.login-btn:active { transform: scale(.98); }
.login-btn:disabled { opacity: .6; cursor: wait; }

.login-error {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 12px;
    display: none;
}
.login-error.show { display: block; }

/* ====== App shell ====== */
.app {
    display: grid;
    grid-template-rows: var(--header-h) 1fr;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    padding: 0 18px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-soft);
    gap: 14px;
    z-index: 10;
}
.app-header .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 13px;
}
.app-header .brand .logo {
    height: 52px;
    min-width: 52px;
    max-width: 220px;
    padding: 2px 8px;
    border-radius: 10px;
    background: linear-gradient(135deg, #0ea5e9, #10b981);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 22px;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
}
.app-header .brand .logo img { max-height: 100%; max-width: 100%; object-fit: contain; display: block; }
.app-header .search {
    flex: 1;
    max-width: 460px;
    margin: 0 auto;
    position: relative;
}
.app-header .search input {
    width: 100%;
    padding: 8px 14px 8px 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f5f5f7;
    outline: none;
    transition: all .15s;
}
.app-header .search input:focus {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.app-header .search::before {
    content: "🔍";
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    opacity: .5;
}
.app-header .user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    border-radius: 30px;
    background: #f5f5f7;
    cursor: pointer;
    transition: background .15s;
}
.app-header .user-chip:hover { background: #ebebed; }
.app-header .user-chip .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 13px;
    overflow: hidden;
    flex-shrink: 0;
}
.app-header .user-chip .avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Modal de perfil */
.profile-header {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 6px 2px 16px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 16px;
}
.pf-avatar {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 36px;
    font-weight: 600;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
}
.pf-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pf-avatar .pf-initial { line-height: 1; }
.pf-actions { display: flex; flex-direction: column; gap: 8px; }
.app-header .user-chip .name {
    font-weight: 500;
    font-size: 12px;
}
.app-header .user-chip .role {
    font-size: 10px;
    color: var(--text-mute);
}

/* ====== Main layout ====== */
.app-body {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    overflow: hidden;
}

.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-soft);
    overflow-y: auto;
    padding: 12px 8px 20px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }

.sb-section {
    margin-bottom: 18px;
}
.sb-section h3 {
    text-transform: uppercase;
    font-size: 10px;
    color: var(--text-mute);
    font-weight: 600;
    letter-spacing: .5px;
    padding: 4px 10px;
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sb-section h3 .add {
    cursor: pointer;
    font-size: 13px;
    color: var(--text-soft);
    padding: 0 4px;
    border-radius: 4px;
}
.sb-section h3 .add:hover { background: rgba(0,0,0,.08); color: var(--text); }

.sb-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 1px;
    font-size: 12px;
    transition: background .1s;
}
.sb-item:hover { background: rgba(0,0,0,.05); }
.sb-item.active {
    background: var(--accent);
    color: white;
}
.sb-item.active .count { color: rgba(255,255,255,.85); }
.sb-item .ico {
    font-size: 15px;
    width: 18px;
    text-align: center;
}
.sb-item .txt {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Pastas: mostra o nome completo, permitindo quebrar em múltiplas linhas */
.sb-item.folder-item .txt {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.25;
    word-break: break-word;
}
/* Faixa colorida na borda esquerda — respeita a cor da pasta */
.sb-item.folder-item {
    border-left: 3px solid transparent;
}
.sb-item.folder-item[data-color] {
    border-left-color: var(--folder-color, transparent);
}
.sb-item .count {
    font-size: 10px;
    color: var(--text-mute);
    font-variant-numeric: tabular-nums;
}
/* Ícone colorido da pasta — respeita style inline color */
.sb-item.folder-item .ico { transition: color .12s; }

/* Botão de toggle da sidebar no header */
.app-header .sidebar-toggle {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* Sidebar recolhida (desktop) */
@media (min-width: 801px) {
    body.sidebar-collapsed .sidebar {
        width: 0 !important;
        min-width: 0;
        padding: 0;
        overflow: hidden;
        border-right: none;
    }
    body.sidebar-collapsed .app-body {
        grid-template-columns: 0 1fr !important;
    }
}

/* Modal de escolher cor: bolinhas */
.color-dot {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,.08);
    cursor: pointer;
    transition: transform .12s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.color-dot:hover { transform: scale(1.15); }

/* Ações inline na pasta da sidebar (renomear/excluir) — aparecem ao hover */
.sb-item.folder-item { position: relative; }
.sb-item.folder-item .folder-act {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity .12s, background .12s;
    color: inherit;
    line-height: 1;
    flex-shrink: 0;
}
.sb-item.folder-item:hover .folder-act { opacity: .85; }
.sb-item.folder-item .folder-act:hover { opacity: 1; background: rgba(0,0,0,.1); }
.sb-item.folder-item.active .folder-act:hover { background: rgba(255,255,255,.2); }
.sb-item.folder-item .folder-act.trash:hover { background: var(--danger); color: #fff; }

.sb-item.folder-item.dragover,
.sb-item.drop-target.dragover {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    background: var(--accent-soft);
}
.sb-item.drop-target {
    transition: background .12s, outline-color .12s;
}

/* Realce geral de drop-targets quando há drag interno em curso */
body.peda-dragging .sb-item.drop-target {
    background: rgba(0,113,227,.05);
    cursor: copy;
}

/* Ghost flutuante para drag de múltiplos */
.drag-ghost {
    position: fixed;
    top: -1000px;
    left: -1000px;
    background: var(--accent);
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(0,0,0,.2);
    pointer-events: none;
    white-space: nowrap;
}

/* Item sendo arrastado */
.file-card.dragging,
.files-list tbody tr.dragging {
    opacity: 0.4;
}

/* ====== Content ====== */
.content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-panel);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-soft);
    min-height: var(--toolbar-h);
}
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
}
.breadcrumb .crumb {
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.breadcrumb .crumb:hover { text-decoration: underline; }
.breadcrumb .sep {
    color: var(--text-mute);
    font-weight: 400;
}
.tb-btn {
    padding: 7px 11px;
    border-radius: 7px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, color .15s;
    font-size: 11px;
    white-space: nowrap;
}
.tb-btn:hover { background: #f0f0f2; }
.tb-btn.primary {
    background: var(--accent);
    color: white;
}
.tb-btn.primary:hover { background: var(--accent-hover); }
.tb-btn.ghost { background: transparent; }
.tb-btn.danger { color: var(--danger); }
.tb-btn.danger:hover { background: var(--danger-soft); }
.view-toggle {
    display: inline-flex;
    background: #f0f0f2;
    border-radius: 7px;
    padding: 2px;
}
.view-toggle button {
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 11px;
    color: var(--text-soft);
}
.view-toggle button.active {
    background: white;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.files-area {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px 30px;
    position: relative;
}
.files-area.dropzone-active::after {
    content: "Solte os arquivos aqui";
    position: absolute;
    inset: 8px;
    border: 2px dashed var(--accent);
    border-radius: 14px;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 20px;
    font-weight: 600;
    pointer-events: none;
    z-index: 5;
}

/* Grid view */
.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}
.file-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 14px 10px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: transform .12s, box-shadow .12s, border-color .12s;
    position: relative;
}
.file-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border);
}
.file-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.file-thumb {
    width: 92px;
    height: 92px;
    border-radius: 10px;
    background: #f5f5f7;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 38px;
    margin-bottom: 10px;
    position: relative;
}
.file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}
.file-thumb.pdf { background: linear-gradient(180deg, #fde2e2, #ffefef); color: #ef4444; }
.file-thumb.png { background: linear-gradient(180deg, #dbeafe, #eff6ff); color: #3b82f6; }
.file-thumb.cdr { background: linear-gradient(180deg, #ede9fe, #f5f3ff); color: #8b5cf6; }
.file-thumb.folder { background: linear-gradient(180deg, #fef3c7, #fffbeb); color: #f59e0b; }
.file-name {
    font-size: 11.5px;
    font-weight: 500;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
    line-height: 1.35;
    max-height: 2.7em;
}
.file-meta {
    font-size: 10px;
    color: var(--text-mute);
    margin-top: 4px;
}
.file-path {
    font-size: 9.5px;
    color: var(--text-mute);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    letter-spacing: 0.2px;
}

.cat-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 4px;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}
.cat-pill-ico { font-size: 10px; }
/* Selection bar — barra de ações em massa */
.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    gap: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    z-index: 3;
}
.selection-bar .sel-info { font-size: 12px; }
.selection-bar .sel-info strong {
    font-size: 14px;
    background: rgba(255,255,255,.2);
    padding: 2px 10px;
    border-radius: 10px;
    margin-right: 6px;
}
.selection-bar .sel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.selection-bar .btn {
    background: rgba(255,255,255,.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,.3);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: background .12s;
    font-family: inherit;
}
.selection-bar .btn:hover { background: rgba(255,255,255,.28); }
.selection-bar .btn.danger { background: var(--danger); border-color: var(--danger); }
.selection-bar .btn.danger:hover { background: #e0332b; }

/* Checkbox visível nos cards em modo de seleção */
.file-card.selection-mode { cursor: pointer; }
.file-card .sel-checkbox {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    z-index: 3;
    accent-color: var(--accent);
}
.file-card.selection-mode .cat-badge { top: 8px; left: 34px; }

.tb-btn.active {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}

/* Ícones na seção "Tipos de arquivo" da sidebar — bem pequenos e uniformes */
.sb-item.type-item .type-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    background: #fff;
    border-radius: 3px;
    padding: 1px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px var(--border-soft);
}
.sb-item.type-item .ico {
    width: 18px;
    height: 18px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Badge de tipo (PDF/CDR) — ícone pequeno no canto superior direito do card */
.file-card .ext-badge-icon {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    object-fit: contain;
    background: #fff;
    padding: 2px;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    z-index: 2;
    pointer-events: none;
}
.row-type-icon { width: 18px; height: 18px; object-fit: contain; vertical-align: middle; }

/* Agrupamento por tipo */
.group-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 4px 6px;
    margin-top: 4px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-soft);
}
.group-header:first-child { margin-top: 0; }
.group-header .gh-label { text-transform: uppercase; }
.group-header .gh-count {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 2px 9px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 10px;
}
.group-grid {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}
.files-list tr.group-row {
    cursor: default;
    background: var(--bg-sidebar) !important;
}
.files-list tr.group-row:hover { background: var(--bg-sidebar) !important; }
.files-list tr.group-row td {
    padding: 9px 14px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-soft);
}
.files-list tr.group-row .gh-count {
    margin-left: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
}

.group-toggle.active {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}

.file-card .cat-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 9px;
    padding: 3px 7px;
    border-radius: 10px;
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.file-card .ext-badge {
    position: absolute;
    bottom: 54px;
    right: 26px;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0,0,0,.55);
    color: white;
    font-weight: 600;
    letter-spacing: .4px;
}

/* List view */
.files-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.files-list th {
    text-align: left;
    padding: 8px 12px;
    font-weight: 600;
    color: var(--text-soft);
    border-bottom: 1px solid var(--border-soft);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .3px;
    background: #fafafa;
    position: sticky;
    top: 0;
    z-index: 2;
}
.files-list td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-soft);
}
.files-list tr {
    cursor: pointer;
    transition: background .1s;
}
.files-list tr:hover { background: #f7f7f9; }
.files-list tr.selected { background: var(--accent-soft); }
.files-list .name-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}
.files-list .name-cell .ico {
    font-size: 20px;
    width: 24px;
    flex-shrink: 0;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-mute);
}
.empty-state .ico {
    font-size: 60px;
    margin-bottom: 14px;
    opacity: .5;
}
.empty-state h3 {
    margin: 0 0 6px;
    color: var(--text-soft);
    font-weight: 500;
}
.empty-state p { margin: 0; font-size: 12px; }

/* ====== Modal ====== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    padding: 24px;
}
.modal-backdrop.show { display: flex; }
.modal {
    background: var(--bg-panel);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn .18s ease-out;
}
.modal.wide { max-width: 880px; }
.modal.xwide { max-width: 1100px; }
@keyframes modalIn {
    from { transform: translateY(12px) scale(.97); opacity: 0; }
    to { transform: none; opacity: 1; }
}
.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.modal-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.modal-header .close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ebebed;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-soft);
}
.modal-header .close:hover { background: #d8d8db; color: var(--text); }
.modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border-soft);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    background: #fafafa;
}
.field {
    margin-bottom: 14px;
}
.field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-soft);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.field input, .field select, .field textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    outline: none;
    transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 72px; }
.field .hint { font-size: 10px; color: var(--text-mute); margin-top: 4px; }

.btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
    transition: all .15s;
    font-size: 12px;
}
.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: #f0f0f2; color: var(--text); }
.btn.ghost:hover { background: #e5e5e9; }
.btn.danger { background: var(--danger); color: white; }
.btn.danger:hover { background: #e0332b; }

/* Upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    margin-bottom: 16px;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.upload-zone .ico { font-size: 40px; color: var(--accent); margin-bottom: 8px; }
.upload-zone h4 { margin: 0 0 4px; }
.upload-zone p { margin: 0; font-size: 11px; color: var(--text-mute); }

.upload-progress {
    margin-top: 16px;
    padding: 18px;
    background: #f5f5f7;
    border-radius: 10px;
}
.upload-progress .up-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 12px;
}
.upload-progress .up-head strong { font-size: 13px; }
.upload-progress .up-count {
    font-size: 11px;
    color: var(--text-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}
.upload-progress .bar {
    height: 10px;
    background: #e5e5ea;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}
.upload-progress .bar > div {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    width: 0%;
    transition: width .25s ease;
    border-radius: 5px;
    position: relative;
    overflow: hidden;
}
.upload-progress .bar > div::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
    animation: upShimmer 1.4s linear infinite;
}
@keyframes upShimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
.upload-progress .up-percent {
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}
.upload-list { display: flex; flex-direction: column; gap: 6px; font-size: 11px; margin-top: 12px; max-height: 200px; overflow-y: auto; }
.upload-list .ul-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.upload-list .ul-item .st { width: 16px; text-align: center; font-size: 12px; }
.upload-list .ul-item.ok .st { color: var(--success); }
.upload-list .ul-item.err .st { color: var(--danger); }
.upload-list .ul-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-list .ul-item .pc {
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    color: var(--text-soft);
    min-width: 44px;
    text-align: right;
}
.upload-list .ul-item.ok .pc { color: var(--success); font-weight: 600; }
.upload-list .ul-item.err .pc { color: var(--danger); }

/* Tela de conclusão */
.upload-complete {
    padding: 36px 20px 20px;
    text-align: center;
    animation: ucFadeIn .35s ease;
}
@keyframes ucFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.upload-complete .uc-check {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: var(--success);
    color: #fff;
    font-size: 42px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
    box-shadow: 0 8px 24px rgba(52,199,89,.35);
    animation: ucPop .4s cubic-bezier(.2,1.4,.5,1);
}
@keyframes ucPop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}
.upload-complete.has-errors .uc-check {
    background: var(--warn);
    box-shadow: 0 8px 24px rgba(255,149,0,.35);
}
.upload-complete h3 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 600;
}
.upload-complete p {
    margin: 0 0 16px;
    color: var(--text-soft);
    font-size: 12px;
}
.upload-complete .upload-list {
    text-align: left;
    background: #f5f5f7;
    padding: 10px 14px;
    border-radius: 8px;
}

/* Preview modal */
.preview-body {
    padding: 0;
    background: #1c1c1e;
    min-height: 400px;
    max-height: 80vh;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}
.preview-body > .preview-split { width: 100%; }
.preview-body img {
    max-width: 100%;
    max-height: 78vh;
    display: block;
    object-fit: contain;
}
.preview-body iframe {
    width: 100%;
    height: 78vh;
    border: none;
    background: white;
}
.preview-body .no-preview {
    color: white;
    text-align: center;
    padding: 60px 20px;
}
.preview-body .no-preview .ico { font-size: 60px; margin-bottom: 16px; }
.preview-sidebar {
    background: #f5f5f7;
    padding: 20px;
    width: 280px;
    border-left: 1px solid var(--border);
    overflow-y: auto;
}
.preview-split {
    display: grid;
    grid-template-columns: 1fr 280px;
    height: 78vh;
}
.preview-sidebar h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; color: var(--text-soft); }
.preview-sidebar dl { margin: 0 0 16px; font-size: 11.5px; }
.preview-sidebar dt { color: var(--text-mute); font-size: 10px; text-transform: uppercase; letter-spacing: .3px; margin-top: 8px; }
.preview-sidebar dd { margin: 2px 0 0; word-break: break-word; }
.preview-sidebar .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.preview-sidebar .tag {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--accent);
    color: white;
    font-weight: 500;
}

/* Users admin */
.users-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.users-table th, .users-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-soft); }
.users-table th { font-size: 10px; text-transform: uppercase; color: var(--text-soft); font-weight: 600; letter-spacing: .3px; }
.role-pill {
    font-size: 9px;
    padding: 3px 9px;
    border-radius: 10px;
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.role-pill.admin { background: #8b5cf6; }
.role-pill.viewer { background: #6b7280; }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1d1d1f;
    color: white;
    padding: 11px 22px;
    border-radius: 24px;
    font-size: 12px;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* Contextmenu */
.ctxmenu {
    position: fixed;
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    min-width: 180px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    font-size: 12px;
    display: none;
}
.ctxmenu.show { display: block; }
.ctxmenu .it {
    padding: 7px 10px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ctxmenu .it:hover { background: var(--accent); color: white; }
.ctxmenu .it.danger:hover { background: var(--danger); }
.ctxmenu .sep { height: 1px; background: var(--border-soft); margin: 4px 0; }

/* Thumb — fallback de emoji (quando falhar o carregamento da miniatura) */
.file-thumb.thumb-fallback { font-size: 38px; }
.file-thumb .thumb-img { object-fit: contain; background: #fff; width: 100%; height: 100%; }
.file-thumb .thumb-img.thumb-icon-fallback { object-fit: contain; padding: 10px; background: #fff; }

/* Ordenador */
.sort-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}
.sort-wrap select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-panel);
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
}
.sort-wrap select:hover { border-color: var(--accent); }
.sort-wrap select:focus { outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent); }
.sort-dir {
    width: 32px;
    padding: 6px 0;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
}

/* ==================== PDF Viewer (multi-página + zoom) ==================== */
.pdf-viewer, .img-viewer {
    display: flex;
    flex-direction: column;
    background: #323234;
    overflow: hidden;
    min-height: 0;
}
.pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #1c1c1e;
    color: #fff;
    border-bottom: 1px solid #000;
    flex-shrink: 0;
    font-size: 12px;
}
.pdf-toolbar .tb-tool {
    background: rgba(255,255,255,.08);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 11px;
    cursor: pointer;
    transition: background .12s;
    min-width: 32px;
    text-align: center;
}
.pdf-toolbar .tb-tool:hover { background: rgba(255,255,255,.18); }
.pdf-toolbar .tb-tool:active { background: var(--accent); }
.pdf-toolbar .tb-sep { width: 1px; height: 20px; background: rgba(255,255,255,.18); margin: 0 4px; }
.pdf-toolbar .zoom-label,
.pdf-toolbar .pdf-page-info {
    font-variant-numeric: tabular-nums;
    min-width: 68px;
    text-align: center;
    color: rgba(255,255,255,.9);
    font-size: 11px;
}
.pdf-toolbar .pdf-cdr-hint {
    margin-left: auto;
    font-size: 10px;
    background: rgba(139,92,246,.25);
    color: #c4b5fd;
    padding: 3px 9px;
    border-radius: 10px;
    font-weight: 500;
}
.pdf-canvas-host, .img-canvas-host {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 20px;
    background: #3a3a3c;
    min-height: 0;
}
.pdf-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.pdf-page-label {
    font-size: 10px;
    color: rgba(255,255,255,.55);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.pdf-canvas-wrap {
    background: #fff;
    box-shadow: 0 6px 20px rgba(0,0,0,.35);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    min-width: 40px;
}
.pdf-canvas-wrap canvas { display: block; max-width: none; }

.pdf-loading {
    color: rgba(255,255,255,.75);
    text-align: center;
    padding: 60px 20px;
}
.pdf-loading .spin {
    width: 38px; height: 38px;
    border: 3px solid rgba(255,255,255,.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 14px;
    animation: pdfSpin 0.8s linear infinite;
}
@keyframes pdfSpin { to { transform: rotate(360deg); } }
.pdf-loading p { font-size: 12px; margin: 0; max-width: 320px; margin: 0 auto; }

.pdf-error {
    color: #fff;
    text-align: center;
    padding: 50px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 60vh;
}
.pdf-error .ico { font-size: 48px; margin-bottom: 12px; }
.pdf-error .pdf-error-icon {
    width: 96px;
    height: 96px;
    object-fit: contain;
    background: #fff;
    padding: 10px;
    border-radius: 14px;
    margin-bottom: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.pdf-error h3 { margin: 0 0 6px; font-size: 14px; }
.pdf-error p { margin: 4px 0; opacity: .85; font-size: 12px; max-width: 380px; }

/* Img viewer (PNG com zoom) */
.img-canvas-host { padding: 0; position: relative; justify-content: center; }
.img-canvas-host img {
    transform-origin: center;
    max-width: none;
    transition: transform .12s ease;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

/* ==========================================================
   Responsividade — tablet & mobile
   Breakpoints: 1024px (tablet), 800px (mobile), 480px (phone)
   ========================================================== */

.mobile-menu-btn { display: none; }

/* ==========================================================
   Navegação inferior mobile — sempre acessível em < 800px
   ========================================================== */
.mobile-bottom-nav { display: none; }
@media (max-width: 800px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--border-soft);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        z-index: 55;
        box-shadow: 0 -2px 14px rgba(0, 0, 0, 0.06);
        gap: 2px;
    }
    .mobile-bottom-nav .mb-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 6px 4px;
        color: var(--text-soft);
        text-decoration: none;
        border-radius: 10px;
        background: transparent;
        border: none;
        cursor: pointer;
        font-family: inherit;
        min-width: 0;
        transition: background 0.12s, color 0.12s, transform 0.1s;
    }
    .mobile-bottom-nav .mb-tab:active { transform: scale(0.96); }
    .mobile-bottom-nav .mb-tab.active {
        color: var(--accent);
        background: var(--accent-soft);
    }
    .mobile-bottom-nav .mb-ico {
        font-size: 18px;
        line-height: 1;
    }
    .mobile-bottom-nav .mb-lbl {
        font-size: 9.5px;
        font-weight: 600;
        letter-spacing: 0.2px;
        white-space: nowrap;
    }
    .mobile-bottom-nav .admin-only { display: none; }
    body.is-admin .mobile-bottom-nav .admin-only { display: flex; }

    /* Toast fica acima do nav inferior */
    .toast {
        bottom: calc(72px + env(safe-area-inset-bottom));
    }
}

/* Safe-area iOS (notch) */
.app-header {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
}

/* Viewport dinâmico — resolve problema da barra do navegador mobile */
@supports (height: 100dvh) {
    html, body { height: 100dvh; }
    .app { height: 100dvh; }
    .login-wrap { min-height: 100dvh; }
    .modal { max-height: 90dvh; }
    .preview-body { max-height: 80dvh; }
    .preview-body img { max-height: 78dvh; }
    .preview-body iframe { height: 78dvh; }
    .preview-split { height: 78dvh; }
}

/* ============ Tablet (≤ 1024px) ============ */
@media (max-width: 1024px) {
    :root { --sidebar-w: 220px; }
    .preview-split { grid-template-columns: 1fr 240px; }
    .preview-sidebar { width: 240px; padding: 16px; }
    .erp-view { padding: 20px 22px !important; }
    .erp-body { grid-template-columns: 200px 1fr !important; }
    .files-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ============ Mobile (≤ 800px) ============ */
@media (max-width: 800px) {
    :root {
        --sidebar-w: 0;
        --header-h: 56px;
        --toolbar-h: 48px;
    }

    body { font-size: 12.5px; }
    /* Previne zoom automático do iOS ao focar inputs (<16px) */
    input, select, textarea { font-size: 16px; }

    /* ===== Header compacto ===== */
    .app-header {
        padding: 0 10px;
        gap: 8px;
    }
    .app-header .sidebar-toggle { display: none; }
    .app-header .brand { gap: 8px; min-width: 0; }
    .app-header .brand .logo {
        height: 38px;
        min-width: 38px;
        max-width: 38px;
        font-size: 16px;
        border-radius: 9px;
        padding: 2px 4px;
    }
    .app-header .brand span#brandTitle { display: none; }
    .app-header .search {
        flex: 1;
        max-width: none;
        margin: 0;
        min-width: 0;
    }
    .app-header .search input {
        padding: 8px 12px 8px 32px;
        font-size: 13px;
    }
    .app-header .search::before { left: 10px; }
    .app-header .user-chip {
        padding: 3px;
        background: transparent;
        gap: 0;
        flex-shrink: 0;
    }
    .app-header .user-chip:hover { background: transparent; }
    .app-header .user-chip > div:not(.avatar) { display: none; }
    .app-header .user-chip .avatar {
        width: 34px;
        height: 34px;
        font-size: 12px;
    }
    .mobile-menu-btn {
        display: inline-flex !important;
        width: 38px;
        height: 38px;
        padding: 0;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        flex-shrink: 0;
        border-radius: 8px;
    }

    /* ===== Sidebar drawer (ambos index + ERP) ===== */
    .app-body, .erp-body {
        grid-template-columns: 1fr !important;
    }
    .sidebar, .erp-sidebar {
        position: fixed;
        left: 0;
        top: var(--header-h);
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 60;
        box-shadow: 4px 0 24px rgba(0,0,0,.18);
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.open, .erp-sidebar.open { transform: none; }

    /* Backdrop via :has — fecha ao tocar fora */
    body:has(.sidebar.open)::before,
    body:has(.erp-sidebar.open)::before {
        content: '';
        position: fixed;
        inset: var(--header-h) 0 0 0;
        background: rgba(0,0,0,.38);
        z-index: 40;
        animation: pedaFadeIn .18s ease;
    }
    @keyframes pedaFadeIn {
        from { opacity: 0; } to { opacity: 1; }
    }

    /* ===== Toolbar (gerenciador de arquivos) ===== */
    .toolbar {
        padding: 8px 10px;
        gap: 6px;
        flex-wrap: wrap;
    }
    .breadcrumb {
        font-size: 13px;
        flex-basis: 100%;
        order: -1;
        min-height: 22px;
    }
    .sort-wrap { margin-left: 0; gap: 3px; }
    .sort-wrap select {
        max-width: 150px;
        padding: 6px 8px;
        font-size: 11px;
    }
    .sort-dir { width: 30px; padding: 5px 0; }
    .tb-btn { padding: 8px 10px; font-size: 11px; }
    .tb-btn .txt { display: none; }
    .view-toggle button { padding: 6px 10px; font-size: 11px; }

    /* ===== Barra de seleção ===== */
    .selection-bar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }
    .selection-bar .sel-info {
        font-size: 12px;
        flex-basis: 100%;
    }
    .selection-bar .sel-actions {
        flex: 1;
        justify-content: flex-end;
        gap: 6px;
    }
    .selection-bar .btn {
        padding: 7px 11px;
        font-size: 11px;
    }

    /* ===== Área de arquivos ===== */
    .files-area { padding: 12px 12px calc(90px + env(safe-area-inset-bottom)); }
    .files-grid,
    .group-grid {
        grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
        gap: 10px;
    }
    .file-card { padding: 10px 6px 8px; }
    .file-thumb {
        width: 74px;
        height: 74px;
        font-size: 30px;
        margin-bottom: 6px;
    }
    .file-name { font-size: 11px; }
    .file-meta { font-size: 10px; }
    .file-path { display: none; }
    .file-card .ext-badge { bottom: 42px; right: 14px; }
    .file-card .ext-badge-icon { width: 18px; height: 18px; }
    .group-header { padding: 8px 2px 4px; font-size: 10px; }

    /* Lista: esconde colunas menos críticas */
    .files-list { font-size: 11.5px; }
    .files-list th, .files-list td { padding: 8px 8px; }
    .files-list th:nth-child(3),
    .files-list td:nth-child(3),
    .files-list th:nth-child(4),
    .files-list td:nth-child(4) { display: none; }

    /* ===== Modais em tela cheia com footer empilhado ===== */
    .modal-backdrop { padding: 0; align-items: stretch; }
    .modal {
        max-width: 100% !important;
        max-height: 100vh !important;
        width: 100%;
        height: 100vh;
        border-radius: 0;
        animation: modalInMobile .22s ease-out;
    }
    @supports (height: 100dvh) {
        .modal { max-height: 100dvh !important; height: 100dvh; }
    }
    @keyframes modalInMobile {
        from { transform: translateY(16px); opacity: 0; }
        to { transform: none; opacity: 1; }
    }
    .modal-header { padding: 14px 16px; }
    .modal-header h2 { font-size: 14px; }
    .modal-header .close { width: 32px; height: 32px; font-size: 13px; }
    .modal-body { padding: 16px; }
    .modal-footer {
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
        flex-direction: column-reverse;
        gap: 8px;
    }
    .modal-footer .btn {
        width: 100%;
        padding: 12px;
        font-size: 12px;
    }

    /* ===== Preview empilhado ===== */
    .preview-body { min-height: 0; }
    .preview-split {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        height: calc(100vh - var(--header-h));
    }
    @supports (height: 100dvh) {
        .preview-split { height: calc(100dvh - var(--header-h)); }
    }
    .preview-sidebar {
        width: 100%;
        max-height: 38vh;
        border-left: none;
        border-top: 1px solid var(--border);
        padding: 14px 16px;
    }
    .preview-body img { max-height: 55vh; }
    .preview-body iframe { height: 55vh; }

    /* ===== Visualizador de PDF ===== */
    .pdf-toolbar {
        flex-wrap: wrap;
        padding: 6px 8px;
        gap: 4px;
    }
    .pdf-toolbar .tb-tool {
        padding: 7px 10px;
        min-width: 34px;
        font-size: 11px;
    }
    .pdf-toolbar .tb-sep { display: none; }
    .pdf-toolbar .zoom-label,
    .pdf-toolbar .pdf-page-info {
        min-width: 52px;
        font-size: 10px;
    }
    .pdf-toolbar .pdf-cdr-hint { display: none; }
    .pdf-canvas-host, .img-canvas-host {
        padding: 10px;
        gap: 10px;
    }

    /* ===== Modal perfil ===== */
    .profile-header { gap: 12px; }
    .pf-avatar { width: 64px; height: 64px; font-size: 26px; }
    .pf-actions .btn { width: auto; }

    /* ===== ERP — drawer + view compacta ===== */
    .erp-view { padding: 14px 12px calc(90px + env(safe-area-inset-bottom)) !important; }
    .erp-view > h2 {
        font-size: 15px;
        margin-bottom: 14px;
        gap: 10px;
    }
    .erp-view > h2 .page-logo,
    .erp-view > h2 .page-logo-fallback {
        width: 30px !important;
        height: 30px !important;
        font-size: 15px;
    }
    .erp-card {
        padding: 14px;
        margin-bottom: 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .erp-card h3 { font-size: 11px; }

    /* Tabelas viram cards empilhados — sem scroll horizontal */
    .erp-card { overflow-x: visible; }
    .data-table, .users-table {
        display: block;
        width: 100%;
        background: transparent;
        border: none;
    }
    .data-table thead, .users-table thead { display: none; }
    .data-table tbody, .users-table tbody { display: block; }
    .data-table tr, .users-table tr {
        display: block;
        background: var(--bg-panel);
        border: 1px solid var(--border-soft);
        border-radius: 10px;
        padding: 10px 12px;
        margin-bottom: 10px;
        box-shadow: 0 1px 2px rgba(0,0,0,.03);
    }
    .data-table tr:hover, .users-table tr:hover { background: var(--bg-panel); }
    .data-table tr:hover td, .users-table tr:hover td { background: transparent; }
    .data-table td, .users-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 7px 0;
        border: none;
        border-bottom: 1px dashed var(--border-soft);
        text-align: right;
        white-space: normal;
        min-height: 32px;
    }
    .data-table td:last-child, .users-table td:last-child { border-bottom: none; padding-bottom: 0; }
    .data-table td:first-child, .users-table td:first-child { padding-top: 0; }
    .data-table td::before, .users-table td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-size: 9.5px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        color: var(--text-soft);
        text-align: left;
    }
    .data-table td.no-label::before, .users-table td.no-label::before,
    .data-table td:not([data-label])::before, .users-table td:not([data-label])::before {
        content: none;
    }
    /* Célula de ações — sem rótulo, botões alinhados */
    .data-table td.actions-cell,
    .users-table td:last-child {
        justify-content: flex-end;
        gap: 4px;
        padding-top: 10px;
        border-top: 1px solid var(--border-soft);
        margin-top: 4px;
    }
    .data-table td.actions-cell::before,
    .users-table td:last-child::before { display: none; }
    .data-table .actions-cell .ico-btn,
    .users-table td .ico-btn {
        padding: 8px 10px;
        font-size: 13px;
        background: var(--bg-sidebar);
        border-radius: 6px;
    }
    /* Pill/status fica compacto dentro da célula */
    .data-table td .status-pill,
    .data-table td .role-pill,
    .users-table td .role-pill { flex-shrink: 0; }

    /* Campos em grid — uma coluna */
    .row { grid-template-columns: 1fr !important; }

    /* Linhas de itens — empilha bonitinho */
    .item-row {
        grid-template-columns: 1fr 1fr 32px !important;
        gap: 6px;
        padding: 8px;
        border: 1px solid var(--border-soft);
        border-radius: 8px;
        margin-bottom: 8px;
        background: var(--bg-panel);
    }
    .item-row > *:first-child { grid-column: 1 / 3; }
    .item-row input { padding: 10px 10px; font-size: 13px; }

    /* Item rico (com miniatura) — miniatura à esquerda, resto empilhado */
    .rich-item-wrap { padding: 10px; }
    .rich-item-row {
        grid-template-columns: 56px 1fr 32px !important;
        gap: 6px;
        row-gap: 6px;
    }
    .rich-item-row > *:nth-child(2) { grid-column: 2 / 4; }
    .rich-item-row > *:nth-child(3),
    .rich-item-row > *:nth-child(4),
    .rich-item-row > *:nth-child(5) { grid-column: 1 / 4; }
    .rich-item-row .it-imgcell { grid-row: 1 / 3; }
    .rich-item-row .remove-item {
        grid-column: 3 / 4;
        grid-row: 1;
        justify-self: end;
    }
    .rich-item-row input { padding: 9px 10px; font-size: 13px; }

    /* Parcelas: data + valor lado a lado, checkbox embaixo */
    .inst-row {
        grid-template-columns: 1fr 1fr 32px !important;
        row-gap: 4px;
        padding: 8px;
        border: 1px solid var(--border-soft);
        border-radius: 8px;
        margin-bottom: 6px;
        background: var(--bg-panel);
    }
    .inst-row .inst-paid { grid-column: 1 / 3; }

    /* KPI cards menores */
    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
        gap: 10px;
        margin-bottom: 18px;
    }
    .kpi { padding: 12px 14px; }
    .kpi .value { font-size: 17px; }
    .kpi .label { font-size: 9.5px; }

    /* Bancos */
    .bank-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
    .bank-card { padding: 10px 8px; }
    .bank-card img { width: 38px; height: 38px; }

    /* Upload */
    .upload-zone { padding: 22px 14px; }
    .upload-zone .ico { font-size: 34px; }
    .upload-progress { padding: 14px; }

    /* Toast acima da safe-area */
    .toast {
        bottom: calc(18px + env(safe-area-inset-bottom));
        font-size: 11.5px;
        padding: 10px 18px;
        max-width: calc(100vw - 32px);
        text-align: center;
    }

    /* Contextmenu — alvos de toque maiores */
    .ctxmenu {
        min-width: 200px;
        font-size: 11px;
    }
    .ctxmenu .it { padding: 10px 12px; }

    /* Login */
    .login-wrap { padding: 16px; }
    .login-card {
        padding: 28px 22px 22px;
        border-radius: 16px;
        box-shadow: var(--shadow-md);
    }
    .login-brand .logo { width: 58px; height: 58px; font-size: 24px; }
    .login-brand h1 { font-size: 17px; }
}

/* ============ Phones pequenos (≤ 480px) ============ */
@media (max-width: 480px) {
    .app-header { gap: 6px; padding: 0 8px; }
    .app-header .brand .logo {
        height: 34px;
        min-width: 34px;
        max-width: 34px;
        font-size: 15px;
    }
    .app-header .user-chip .avatar { width: 30px; height: 30px; font-size: 12px; }
    .app-header .search input { padding: 7px 10px 7px 28px; }
    .app-header .search::before { font-size: 11px; left: 8px; }

    .tb-btn { padding: 7px 8px; font-size: 10.5px; }
    .view-toggle button { padding: 5px 8px; font-size: 10.5px; }
    .sort-wrap select { max-width: 130px; }

    .files-grid,
    .group-grid {
        grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
        gap: 8px;
    }
    .file-thumb { width: 62px; height: 62px; font-size: 26px; }
    .file-name { font-size: 11px; }
    .file-meta { font-size: 10px; }

    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .erp-view { padding: 12px 10px calc(88px + env(safe-area-inset-bottom)) !important; }
    .erp-view > h2 { font-size: 16px; }

    .modal-header h2 { font-size: 13px; }
    .login-card { padding: 24px 18px 18px; }
    .login-brand h1 { font-size: 15px; }
}

/* ============ Landscape em phones baixos (≤ 480px de altura) ============ */
@media (max-height: 480px) and (max-width: 900px) {
    :root { --header-h: 48px; }
    .app-header .brand .logo { height: 32px; min-width: 32px; }
    .files-area { padding-top: 8px; }
    .toolbar { padding: 5px 10px; }
}
