/* ══════════════════════════════════════
   TOKENS
══════════════════════════════════════ */
:root {
    --bg:          #F6F5F2;
    --surface:     #FFFFFF;
    --surface-2:   #FAFAF8;
    --border:      #E4E2DC;
    --border-mid:  #D0CEC7;
    --border-dark: #B8B5AC;
    --text-1:      #181714;
    --text-2:      #5C5A54;
    --text-3:      #9C9A94;
    --accent:      #18171A;
    --accent-fg:   #FFFFFF;
    --danger:      #BE3027;
    --success:     #19793E;
    --inc-bg:      #F0FAF4;
    --inc-bd:      #B7DFC8;
    --rem-bg:      #FDF3F2;
    --rem-bd:      #E8B4B0;
    --font:        'Geist', system-ui, sans-serif;
    --font-mono:   'Geist Mono', monospace;
    --h-header:    54px;
    --w-aside:     200px;
    --radius:      6px;
    --radius-md:   8px;
    --shadow-xs:   0 1px 2px rgba(0,0,0,.05);
    --t:           0.15s ease;
}

/* ══════════════════════════════════════
   RESET
══════════════════════════════════════ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-1);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
header {
    height: var(--h-header);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 200;
}

.h-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-right: 20px;
    border-right: 1px solid var(--border);
    margin-right: 20px;
    text-decoration: none;
}
.h-logo img { height: 26px; opacity: .88; transition: opacity var(--t); }
.h-logo:hover img { opacity: 1; }

.h-search { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.h-search-label {
    font-size: 10.5px; font-weight: 600; letter-spacing: .08em;
    text-transform: uppercase; color: var(--text-3);
    white-space: nowrap; user-select: none;
}

.h-search-field {
    display: flex; align-items: center;
    border: 1px solid var(--border-mid);
    border-radius: var(--radius);
    background: var(--surface-2);
    overflow: hidden;
    transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
.h-search-field:focus-within {
    border-color: var(--text-1);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(24,23,26,.08);
}

#codx {
    font-family: var(--font-mono);
    font-size: 13px; font-weight: 500; letter-spacing: .06em;
    width: 120px; height: 32px; padding: 0 12px;
    border: none; background: transparent; color: var(--text-1); outline: none;
}
#codx::placeholder { color: var(--text-3); font-weight: 400; letter-spacing: .02em; }

#btn-carregar-modulo {
    height: 32px; width: 36px;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; color: var(--text-3);
    cursor: pointer; border-left: 1px solid var(--border);
    background: transparent;
    transition: color var(--t), background var(--t);
    flex-shrink: 0;
}
#btn-carregar-modulo:hover { color: var(--text-1); background: var(--border); }

.h-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; margin: 0 20px; }

.h-module { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.h-module-badge {
    display: none;
    font-family: var(--font-mono); font-size: 10px; font-weight: 500;
    color: var(--text-3); background: var(--bg);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 2px 6px; letter-spacing: .06em; flex-shrink: 0;
}
.h-module-badge.visible { display: inline-flex; }

#nome-modulo {
    font-size: 13px; font-weight: 500; color: var(--text-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: color var(--t);
}
#nome-modulo.ativo { color: var(--text-1); font-weight: 600; }

.h-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }

.user-btn {
    display: flex; align-items: center; gap: 8px;
    height: 34px; padding: 0 10px 0 6px;
    background: transparent; border: 1px solid var(--border);
    border-radius: var(--radius); cursor: pointer;
    transition: all var(--t); font-family: var(--font);
}
.user-btn:hover { background: var(--surface-2); }

.user-avatar {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--text-1); color: var(--accent-fg);
    font-size: 9px; font-weight: 700; letter-spacing: .04em;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; user-select: none;
}
.user-name { font-size: 12.5px; font-weight: 500; color: var(--text-1); white-space: nowrap; }
.icon-out { font-size: 14px; color: var(--text-3); transition: color var(--t); }
.user-btn:hover .icon-out { color: var(--text-2); }

/* ══════════════════════════════════════
   MODULE BAR
══════════════════════════════════════ */
.module-bar {
    height: 36px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: none;
    align-items: center;
    padding: 0 20px;
    gap: 6px;
}
.module-bar.visible { display: flex; }
.mb-crumb { font-size: 12px; color: var(--text-3); }
.mb-crumb a { color: var(--text-3); text-decoration: none; transition: color var(--t); }
.mb-crumb a:hover { color: var(--text-1); }
.mb-sep { font-size: 12px; color: var(--border-dark); }
.mb-active { font-size: 12px; font-weight: 600; color: var(--text-1); }
#module-toolbar { margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* ══════════════════════════════════════
   BOTÕES GLOBAIS
══════════════════════════════════════ */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; height: 32px; padding: 0 14px;
    font-family: var(--font); font-size: 12.5px; font-weight: 500;
    border: none; border-radius: var(--radius);
    cursor: pointer; white-space: nowrap;
    transition: all var(--t); user-select: none;
}
.btn i { font-size: 15px; flex-shrink: 0; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: #000; }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border-mid); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-dark); color: var(--text-1); }
.btn:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
.app-body { display: flex; min-height: calc(100vh - var(--h-header)); }
.content-area { flex: 1; min-width: 0; padding: 28px 24px; }

/* ══════════════════════════════════════
   ASIDE FILTROS
══════════════════════════════════════ */
#aside-filtros {
    width: var(--w-aside);
    flex-shrink: 0;
    background: var(--surface);
    border-left: 1px solid var(--border);
    position: sticky;
    top: var(--h-header);
    height: calc(100vh - var(--h-header));
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.aside-head {
    padding: 10px 12px 8px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.aside-head-title {
    font-size: 10px; font-weight: 700;
    letter-spacing: .09em; text-transform: uppercase;
    color: var(--text-3);
}

/* ── Ações ── */
.aside-acoes {
    padding: 8px;
    display: flex; flex-direction: column; gap: 4px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* ── Botões do aside — reutilizáveis ── */
.a-btn {
    display: flex; align-items: center; justify-content: center;
    gap: 5px; height: 28px; padding: 0 8px;
    font-family: var(--font); font-size: 11px; font-weight: 500;
    border-radius: var(--radius); cursor: pointer; border: 1px solid transparent;
    transition: all var(--t); user-select: none; white-space: nowrap;
    letter-spacing: .01em;
}
.a-btn i { font-size: 12px; flex-shrink: 0; }
.a-btn:active { transform: scale(.97); }

.a-btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.a-btn-primary:hover { background: #000; border-color: #000; }

.a-btn-ghost,
.a-btn-save,
.a-btn-reset { background: transparent; color: var(--text-2); border-color: var(--border); }
.a-btn-ghost:hover,
.a-btn-save:hover,
.a-btn-reset:hover { background: var(--surface-2); border-color: var(--border-mid); color: var(--text-1); }

/* ── Blocos incluir / remover ── */
.f-bloco { border-bottom: 1px solid var(--border); }

.f-bloco-header {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 12px 7px;
    user-select: none;
}

.f-bloco-pill {
    display: inline-flex; align-items: center;
    height: 16px; 
    font-size: 9px; font-weight: 700;
    letter-spacing: .07em; text-transform: uppercase;
    flex-shrink: 0;
}
.bloco-inc .f-bloco-pill,
.bloco-rem .f-bloco-pill {  color: var(--text-2);  }

.f-bloco-titulo { font-size: 10.5px; font-weight: 600; color: var(--text-2); flex: 1; }

.f-bloco-caret {
    display: none;
    align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 4px; border: none;
    background: transparent; cursor: pointer; font-size: 11px; color: var(--text-3);
    transition: all var(--t); flex-shrink: 0;
}
.f-bloco-caret:hover { background: var(--surface-2); color: var(--text-1); }
.f-bloco-caret i { transition: transform .18s ease; }
.f-bloco.collapsed .f-bloco-caret i { transform: rotate(-90deg); }

.f-bloco-body { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.f-bloco.collapsed .f-bloco-body { display: none; }

/* ── Campo genérico ── */
.f-field { display: flex; flex-direction: column; gap: 3px; }

.f-lbl {
    font-size: 10px; font-weight: 600;
    color: var(--text-3);
    letter-spacing: .04em;
    text-transform: uppercase;
    padding-left: 1px;
}

/* ── f-row: container de input reutilizável ── */
.f-row {
    display: flex; align-items: center;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-2); overflow: hidden;
    transition: border-color var(--t), box-shadow var(--t);
}
.f-row:focus-within {
    border-color: var(--border-dark);
    background: var(--surface);
    box-shadow: 0 0 0 2px rgba(24,23,26,.06);
}

.f-row input[type="date"] {
    flex: 1; height: 27px; padding: 0 7px;
    font-family: var(--font); font-size: 11px; color: var(--text-1);
    border: none; background: transparent; outline: none;
    cursor: pointer; min-width: 0;
}
.f-row input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: .35; cursor: pointer; scale: .85;
}

.f-clr {
    width: 24px; height: 27px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; color: var(--text-3);
    cursor: pointer; border-left: 1px solid var(--border); border-top: none; border-right: none; border-bottom: none;
    background: transparent; flex-shrink: 0;
    opacity: 0; pointer-events: none;
    transition: opacity var(--t), color var(--t), background var(--t);
}
.f-clr.vis { opacity: 1; pointer-events: all; }
.f-clr:hover { color: var(--danger); background: var(--rem-bg); }

/* ── Date-range picker ── */
.f-periodo-wrap { display: flex; flex-direction: column; gap: 4px; }

.f-periodo-row {
    cursor: pointer;
    height: auto !important;
    min-height: 27px;
    align-items: center;
    padding: 2px 0;
}

.f-periodo-txt {
    flex: 1; min-width: 0;
    font-size: 10.5px; color: var(--text-3);
    padding: 3px 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    user-select: none; line-height: 1.3;
}
.f-periodo-txt.sel { color: var(--text-1); white-space: normal; font-size: 10px; }

.f-periodo-anchor { position: relative; }

.f-cal-panel {
    display: none;
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-md);
    box-shadow: 0 6px 24px rgba(0,0,0,.14);
    padding: 10px;
    z-index: 600;
    width: 210px;
}
.f-cal-panel.open { display: block; }

.f-cal-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
}
.f-cal-nav {
    width: 24px; height: 24px; border: none; background: transparent;
    cursor: pointer; color: var(--text-3); border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; transition: all var(--t);
}
.f-cal-nav:hover { background: var(--surface-2); color: var(--text-1); }
.f-cal-month { font-size: 11.5px; font-weight: 600; color: var(--text-1); }

.f-cal-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
}
.f-cal-dow {
    font-size: 9px; font-weight: 700; color: var(--text-3);
    text-align: center; padding: 3px 0; text-transform: uppercase;
}
.f-cal-day {
    font-size: 11px; text-align: center; padding: 5px 2px;
    border-radius: 4px; cursor: pointer; color: var(--text-2);
    transition: background var(--t), color var(--t);
    user-select: none; line-height: 1;
}
.f-cal-day:hover:not(.empty):not(.selected) { background: var(--surface-2); color: var(--text-1); }
.f-cal-day.empty { cursor: default; }
.f-cal-day.selected { background: var(--accent); color: var(--accent-fg); }
.f-cal-day.in-range { background: var(--border); color: var(--text-1); border-radius: 0; }
.f-cal-day.range-start { border-radius: 4px 0 0 4px !important; }
.f-cal-day.range-end   { border-radius: 0 4px 4px 0 !important; }
.f-cal-day.today { font-weight: 700; }
.f-cal-hint { font-size: 9.5px; color: var(--text-3); text-align: center; margin-top: 6px; }

.f-cal-foot {
    margin-top: 8px; display: flex; justify-content: flex-end;
    border-top: 1px solid var(--border); padding-top: 6px;
}

/* ── Botão confirmar do calendário ── */
.f-cal-ok { height: 24px; font-size: 10.5px; padding: 0 10px; }

/* ── Busca de clientes ── */
.f-client-wrap { position: relative; display: flex; flex-direction: column; gap: 4px; }

.f-search {
    display: flex; align-items: center;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-2); overflow: hidden;
    transition: border-color var(--t), box-shadow var(--t);
}
.f-search:focus-within {
    border-color: var(--border-dark);
    background: var(--surface);
    box-shadow: 0 0 0 2px rgba(24,23,26,.06);
}
.f-search input {
    flex: 1; height: 27px; padding: 0 7px;
    font-family: var(--font); font-size: 11px; color: var(--text-1);
    border: none; background: transparent; outline: none; min-width: 0;
}
.f-search input::placeholder { color: var(--text-3); }
.f-search i { font-size: 11px; color: var(--text-3); margin-right: 7px; flex-shrink: 0; }

/* ── Dropdown de clientes ── */
.f-drop {
    position: absolute; top: calc(100% + 3px); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border-mid);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 14px rgba(0,0,0,.10);
    z-index: 400; max-height: 140px; overflow-y: auto; display: none;
}
.f-drop.open { display: block; }
.f-opt {
    padding: 5px 8px; font-size: 11px; cursor: pointer;
    display: flex; align-items: center; gap: 6px;
    color: var(--text-1); transition: background var(--t);
}
.f-opt:hover { background: var(--surface-2); }
.f-opt i { font-size: 10px; color: var(--text-3); }

/* ── Tags de clientes ── */
.f-tags { display: flex; flex-direction: column; gap: 2px; }
.f-tag {
    display: flex; align-items: center; gap: 4px;
    padding: 2px 5px 2px 6px; border-radius: 4px;
    font-size: 10.5px; font-weight: 500; border: 1px solid;
}
.f-tag i.ti { font-size: 9px; flex-shrink: 0; }
.f-tag-nome { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bloco-inc .f-tag,
.bloco-rem .f-tag { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }
.f-tag-rm {
    font-size: 10px; cursor: pointer; opacity: .45;
    transition: opacity var(--t); flex-shrink: 0;
    color: inherit; background: none; border: none;
    display: flex; align-items: center; padding: 0;
}
.f-tag-rm:hover { opacity: 1; }

/* ── Extras de módulo ── */
.f-extras { display: flex; flex-direction: column; gap: 6px; }

/* ── Filtros extras: campos reutilizáveis ── */
.f-extras .f-row select,
.f-extras .f-row input[type="text"] {
    flex: 1; height: 29px; padding: 0 7px;
    font-family: var(--font); font-size: 11.5px; color: var(--text-1);
    border: none; background: transparent; outline: none; min-width: 0;
}
.f-extras .f-row select { cursor: pointer; }
.f-extras label.f-checkbox {
    display: flex; align-items: center; gap: 7px;
    cursor: pointer; font-size: 11.5px; color: var(--text-2);
}
.f-extras label.f-checkbox input[type="checkbox"] { accent-color: var(--accent); }

/* ── Footer do aside ── */
.aside-footer {
    margin-top: auto; padding: 8px;
    display: flex; flex-direction: column; gap: 4px;
    border-top: 1px solid var(--border);
}

/* ══════════════════════════════════════
   HOME
══════════════════════════════════════ */
.home-screen {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: calc(100vh - var(--h-header) - 80px);
    text-align: center;
}
.home-logo { height: 44px; opacity: .07; margin-bottom: 36px; filter: grayscale(1); pointer-events: none; }
.home-title { font-size: 21px; font-weight: 600; letter-spacing: -.02em; margin-bottom: 10px; }
.home-sub { font-size: 13.5px; color: var(--text-2); max-width: 360px; line-height: 1.65; margin-bottom: 32px; }
.kbd-hint { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
kbd {
    display: inline-flex; align-items: center; justify-content: center;
    height: 20px; padding: 0 6px;
    background: var(--surface); border: 1px solid var(--border-mid); border-bottom-width: 2px;
    border-radius: 4px;
    font-family: var(--font-mono); font-size: 11px; color: var(--text-2);
}

/* ══════════════════════════════════════
   UTILS
══════════════════════════════════════ */
@keyframes spin { to { transform: rotate(360deg); } }
.spinning { animation: spin .85s linear infinite; display: inline-block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp .22s ease forwards; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 99px; }

/* ══════════════════════════════════════
   OVERLAY + FAB MOBILE
══════════════════════════════════════ */
#aside-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,13,10,.35);
    backdrop-filter: blur(1px);
    z-index: 499; opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
}
#aside-overlay.open { opacity: 1; pointer-events: all; }

#btn-filtros-mobile {
    display: none;
    position: fixed; bottom: 20px; right: 16px; z-index: 400;
    align-items: center; gap: 7px;
    height: 42px; padding: 0 16px;
    background: var(--accent); color: var(--accent-fg);
    border: none; border-radius: 21px;
    font-family: var(--font); font-size: 13px; font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.20);
    transition: all var(--t);
}
#btn-filtros-mobile:active { transform: scale(.96); }
#btn-filtros-mobile i { font-size: 16px; }

#filtros-badge {
    display: none;
    min-width: 18px; height: 18px; padding: 0 4px;
    background: var(--danger); color: white;
    border-radius: 9px; font-size: 10px; font-weight: 700;
    align-items: center; justify-content: center;
}
#filtros-badge.vis { display: inline-flex; }

/* ══════════════════════════════════════
   RESPONSIVO — MOBILE
══════════════════════════════════════ */
@media (max-width: 768px) {
    header { height: auto; padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
    .h-logo { border-right: none; margin-right: 0; padding-right: 0; }
    .h-logo img { height: 22px; }
    .h-search { flex: 1; min-width: 0; }
    .h-search-label { display: none; }
    .h-search-field { flex: 1; }
    #codx { width: 100%; height: 42px; font-size: 15px; }
    #btn-carregar-modulo { height: 42px; width: 42px; font-size: 20px; }
    .h-divider, .h-module { display: none; }
    .h-right { margin-left: 0; }
    .user-name { display: none; }
    .user-btn { height: 40px; padding: 0 10px; }
    .user-avatar { width: 26px; height: 26px; font-size: 11px; }
    .module-bar { height: auto; padding: 8px 14px; flex-wrap: wrap; }
    .content-area { padding: 14px; }
    .home-title { font-size: 18px; }
    .home-sub { font-size: 13px; }

    #aside-filtros {
        position: fixed; right: 0; top: 0; bottom: 0; height: 100dvh;
        z-index: 500; width: min(288px, 90vw);
        transform: translateX(100%);
        transition: transform .24s cubic-bezier(.4,0,.2,1);
    }
    #aside-filtros.open { transform: translateX(0); box-shadow: -4px 0 24px rgba(0,0,0,.13); }

    #aside-overlay { display: block; }
    #btn-filtros-mobile { display: flex; }

    .f-bloco-header { cursor: pointer; }
    .f-bloco-caret { display: flex; }

    @supports (padding: max(0px)) {
        header, .module-bar, .content-area {
            padding-left: max(14px, env(safe-area-inset-left));
            padding-right: max(14px, env(safe-area-inset-right));
        }
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    #codx { width: 100px; }
    :root { --w-aside: 192px; }
}

/* Espaço entre botões padrão e botões de módulo */
#aside-filtros .aside-acoes + div {
    padding-top: 4px;
}

/* Padding no fim do aside */
#aside-filtros::after {
    content: '';
    display: block;
    height: 24px;
    flex-shrink: 0;
}