/* ============================================================
   Padaria Rio Torto — "livro de registos"
   Papel creme, tinta de carvalho, acento cor de côdea.
   Fraunces (títulos) + Archivo (dados, números tabulares).
   ============================================================ */

:root {
    --papel: #f7f1e3;
    --papel-2: #efe6d2;
    --papel-3: #e7dabe;
    --linha: #d8c9a8;
    --tinta: #2e2418;
    --tinta-2: #6b5a44;
    --codea: #b4622d;
    --codea-escura: #8c4a1f;
    --trigo: #d9a441;
    --verde: #5a7340;
    --erro: #9d3326;
    --branco-quente: #fffdf7;
    --sombra: 0 1px 2px rgba(46, 36, 24, .08), 0 4px 14px rgba(46, 36, 24, .07);
    --raio: 10px;
    --fonte-display: "Fraunces", Georgia, serif;
    --fonte-corpo: "Archivo", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--fonte-corpo);
    font-size: 15px;
    color: var(--tinta);
    background:
        radial-gradient(1100px 500px at 85% -10%, rgba(217, 164, 65, .14), transparent 60%),
        radial-gradient(900px 600px at -10% 110%, rgba(180, 98, 45, .08), transparent 55%),
        var(--papel);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* fina textura de farinha */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .35;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .45 0 0 0 0 .3 0 0 0 .035 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
    z-index: 1;
}
body > * { position: relative; z-index: 2; }

/* ---------- barra superior ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 10px 22px;
    background: linear-gradient(180deg, #33271a, #2a2014);
    color: var(--papel);
    border-bottom: 3px solid var(--codea);
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}
.brand-mark { font-size: 26px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b {
    font-family: var(--fonte-display);
    font-weight: 900;
    font-size: 20px;
    letter-spacing: .3px;
}
.brand-text small {
    color: var(--trigo);
    font-size: 10.5px;
    letter-spacing: 2.2px;
    text-transform: uppercase;
}

.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a {
    color: #e8ddc8;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    padding: 9px 14px;
    border-radius: 8px;
    transition: background .15s, color .15s;
}
.mainnav a:hover { background: rgba(247, 241, 227, .12); color: #fff; }
.mainnav a.on {
    background: var(--codea);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,.25);
}

/* dropdown Faturação */
.navdrop { position: relative; }
.navdrop.on-grp > a { background: var(--codea); color: #fff; font-weight: 600; }
.navdrop-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 190px;
    background: #33271a;
    border: 1px solid var(--codea);
    border-radius: 0 0 10px 10px;
    padding: 6px;
    z-index: 60;
    box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.navdrop:hover .navdrop-menu,
.navdrop:focus-within .navdrop-menu { display: flex; flex-direction: column; }
.navdrop-menu a { padding: 10px 12px; border-radius: 7px; }

.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.hello { color: var(--trigo); font-size: 13.5px; font-weight: 500; }

/* ---------- estrutura ---------- */

.wrap { width: min(1280px, 100% - 32px); margin: 22px auto; flex: 1; }

/* rodapé Windland — fixo no fundo da janela */
body { padding-bottom: 46px; }
.footer-windland {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    min-height: 42px;
    padding: 6px 18px;
    background: linear-gradient(180deg, #2a2014, #221a10);
    border-top: 2px solid var(--codea);
    color: #cdbfa6;
    font-size: 12.5px;
    box-shadow: 0 -3px 12px rgba(46, 36, 24, .25);
}
.footer-windland a { color: var(--trigo); text-decoration: none; }
.footer-windland a:hover { text-decoration: underline; }
.fw-brand {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--papel) !important;
}
.fw-brand img { height: 22px; width: 22px; object-fit: contain; }
.fw-suporte { margin-left: auto; }
@media (max-width: 760px) {
    body { padding-bottom: 64px; }
    .footer-windland { gap: 4px 14px; padding: 5px 12px; font-size: 11.5px; }
    .fw-copy { order: 3; width: 100%; }
    .fw-suporte { margin-left: 0; }
}

h1.page-title {
    font-family: var(--fonte-display);
    font-weight: 900;
    font-size: clamp(26px, 4vw, 36px);
    margin: 0 0 4px;
    letter-spacing: -.5px;
}
.page-sub { color: var(--tinta-2); margin: 0 0 20px; font-size: 14.5px; }

.card {
    background: var(--branco-quente);
    border: 1px solid var(--linha);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    padding: 18px 20px;
    margin-bottom: 20px;
}
.card h2 {
    font-family: var(--fonte-display);
    font-weight: 700;
    font-size: 19px;
    margin: 0 0 12px;
}

.flash {
    width: min(1280px, 100% - 32px);
    margin: 14px auto -6px;
    padding: 11px 16px;
    border-radius: var(--raio);
    font-weight: 500;
    border: 1px solid;
    animation: flash-in .25s ease-out;
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } }
.flash-ok    { background: #eef3e4; color: var(--verde); border-color: #c4d3a8; }
.flash-erro  { background: #f9e9e4; color: var(--erro);  border-color: #e3bcae; }

/* ---------- botões e formulários ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--fonte-corpo);
    font-weight: 600;
    font-size: 14px;
    padding: 10px 16px;
    min-height: 42px;            /* alvo de toque (tablet) */
    border-radius: 8px;
    border: 1px solid var(--codea-escura);
    background: linear-gradient(180deg, #c06a32, var(--codea));
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    transition: filter .12s, transform .05s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }

.btn-sec {
    background: var(--papel-2);
    color: var(--tinta);
    border-color: var(--linha);
}
.btn-ghost {
    background: transparent;
    color: inherit;
    border-color: rgba(232, 221, 200, .4);
}
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn-danger { background: linear-gradient(180deg, #ad4334, var(--erro)); border-color: #7c2218; }

input[type=text], input[type=password], input[type=date], input[type=month],
input[type=number], select, textarea {
    font: inherit;
    color: var(--tinta);
    background: var(--branco-quente);
    border: 1px solid var(--linha);
    border-radius: 8px;
    padding: 9px 12px;
    min-height: 42px;
}
input:focus, select:focus, textarea:focus, .grade input:focus {
    outline: 2px solid var(--trigo);
    outline-offset: 1px;
    border-color: var(--trigo);
}
label.fld { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; color: var(--tinta-2); }
.nif-grupo { display: flex; gap: 6px; }
.nif-grupo input { flex: 1; min-width: 130px; }
.nif-grupo .lupa { padding: 8px 13px; font-size: 17px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }

/* ---------- mapa diário ---------- */

.daybar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.daybar .data-grande {
    font-family: var(--fonte-display);
    font-weight: 700;
    font-size: clamp(19px, 3vw, 26px);
}
.daybar .nav-dia { display: flex; gap: 6px; }
.daybar form { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

.grade-scroll {
    overflow-x: auto;
    background: var(--branco-quente);
    border: 1px solid var(--linha);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
}

table.grade {
    border-collapse: collapse;
    width: 100%;
    font-variant-numeric: tabular-nums;
}
.grade th, .grade td {
    border-bottom: 1px solid var(--papel-3);
    border-right: 1px dashed var(--papel-3);
    padding: 0;
    text-align: center;
}
.grade thead th {
    font-family: var(--fonte-corpo);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--tinta-2);
    background: var(--papel-2);
    padding: 12px 8px;
    position: sticky;
    top: 0;
    z-index: 3;
    border-bottom: 2px solid var(--linha);
    min-width: 74px;
}
.grade th.cliente-col, .grade td.cliente {
    text-align: left;
    padding: 0 14px;
    font-weight: 600;
    position: sticky;
    left: 0;
    background: var(--branco-quente);
    z-index: 2;
    min-width: 150px;
    border-right: 2px solid var(--linha);
    white-space: nowrap;
}
.grade thead th.cliente-col { background: var(--papel-2); z-index: 4; }
.grade tbody tr:nth-child(even) td { background: #fbf7ec; }
.grade tbody tr:hover td { background: #f4ecd9; }

.grade input {
    width: 100%;
    min-width: 64px;
    border: 0;
    background: transparent;
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: center;
    padding: 12px 6px;       /* alvo de toque */
    color: var(--tinta);
    -moz-appearance: textfield;
    appearance: textfield;
}
.grade input::-webkit-outer-spin-button,
.grade input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.grade input.tem-valor { font-weight: 700; color: var(--codea-escura); }

.grade tfoot td {
    background: #33271a;
    color: var(--trigo);
    font-weight: 700;
    padding: 12px 8px;
    border: 0;
    font-size: 15px;
}
.grade tfoot td.cliente {
    background: #33271a;
    color: var(--papel);
    font-family: var(--fonte-display);
    letter-spacing: .5px;
    border-right: 2px solid var(--codea);
}

.acoes-dia {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
    align-items: center;
}
.nota-dia { width: 100%; }
.nota-dia textarea { width: 100%; min-height: 56px; resize: vertical; }

/* ---------- tabelas de gestão / relatórios ---------- */

table.lista {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}
.lista th, .lista td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--papel-3); }
.lista th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--tinta-2);
    background: var(--papel-2);
}
.lista td.num, .lista th.num { text-align: right; }
.lista tr:hover td { background: #faf5e8; }
.lista .inactivo { opacity: .45; }
.lista tfoot td { font-weight: 700; background: var(--papel-2); }

/* KPIs e barras dos relatórios */
.kpis { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.kpi {
    flex: 1;
    min-width: 150px;
    background: var(--branco-quente);
    border: 1px solid var(--linha);
    border-left: 4px solid var(--codea);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kpi small { color: var(--tinta-2); text-transform: uppercase; letter-spacing: .7px; font-size: 11px; font-weight: 600; }
.kpi b { font-family: var(--fonte-display); font-size: 21px; font-variant-numeric: tabular-nums; }
.barra { background: var(--papel-2); border-radius: 99px; height: 12px; overflow: hidden; }
.barra span { display: block; height: 100%; background: linear-gradient(90deg, var(--trigo), var(--codea)); border-radius: 99px; }

.tag {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 3px 9px;
    border-radius: 99px;
    background: var(--papel-3);
    color: var(--tinta-2);
}
.tag-admin { background: var(--codea); color: #fff; }

/* ---------- login ---------- */

.login-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    width: min(400px, 100%);
    background: var(--branco-quente);
    border: 1px solid var(--linha);
    border-radius: 14px;
    box-shadow: var(--sombra);
    padding: 36px 34px;
    text-align: center;
    animation: flash-in .35s ease-out;
}
.login-card .brand-mark { font-size: 44px; }
.login-card h1 {
    font-family: var(--fonte-display);
    font-weight: 900;
    font-size: 30px;
    margin: 8px 0 2px;
}
.login-card .sub {
    color: var(--codea);
    font-size: 11px;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 26px;
}
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card .btn { justify-content: center; margin-top: 6px; }

/* ---------- impressão ---------- */

.print-sheet { background: #fff; color: #000; }
.print-sheet .grade thead th { position: static; }

@media print {
    body { background: #fff; }
    body::before, .topbar, .footer, .no-print, .flash { display: none !important; }
    .wrap { width: 100%; margin: 0; }
    .grade-scroll { border: 0; box-shadow: none; overflow: visible; }
    table.grade { font-size: 11px; }
    .grade input { padding: 4px 2px; }
    .grade thead th, .grade td.cliente { position: static; }
    .grade tfoot td { background: #ddd !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    h1.page-title { font-size: 20px; }
}

/* ---------- navegação inferior (telemóvel) ---------- */

.bottomnav { display: none; }

@media (max-width: 760px) {
    /* menu no fundo do ecrã, estilo app */
    .bottomnav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 90;
        background: linear-gradient(180deg, #33271a, #2a2014);
        border-top: 2px solid var(--codea);
        box-shadow: 0 -4px 14px rgba(46, 36, 24, .35);
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    }
    .bottomnav > a, .bottomnav summary {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 7px 2px;
        color: #cdbfa6;
        text-decoration: none;
        font-size: 11px;
        font-weight: 600;
        border-radius: 9px;
        list-style: none;
        cursor: pointer;
        text-align: center;
    }
    .bottomnav summary::-webkit-details-marker { display: none; }
    .bottomnav > a span, .bottomnav summary span { font-size: 21px; line-height: 1; }
    .bottomnav > a.on, .bottomnav summary.on { background: var(--codea); color: #fff; }
    .bn-mais { flex: 1; position: relative; display: flex; }
    .bn-mais summary { flex: 1; }
    .bn-sheet {
        position: fixed;
        bottom: calc(64px + env(safe-area-inset-bottom));
        left: 10px;
        right: 10px;
        background: #33271a;
        border: 1px solid var(--codea);
        border-radius: 14px;
        padding: 8px;
        display: flex;
        flex-direction: column;
        box-shadow: 0 -8px 28px rgba(0,0,0,.45);
        animation: flash-in .18s ease-out;
    }
    .bn-sheet a {
        color: #e8ddc8;
        text-decoration: none;
        font-size: 15px;
        font-weight: 500;
        padding: 13px 14px;
        border-radius: 9px;
    }
    .bn-sheet a:active { background: var(--codea); color: #fff; }

    /* esconder menu do topo; barra superior compacta */
    .mainnav { display: none; }
    .topbar { gap: 10px; padding: 8px 14px; }
    .hello { display: none; }

    /* rodapé Windland deixa de ser fixo (o fundo é do menu) */
    body { padding-bottom: 0; }
    .footer-windland {
        position: static;
        margin-top: 26px;
        margin-bottom: calc(64px + env(safe-area-inset-bottom));
        gap: 4px 14px;
        padding: 10px 14px;
        font-size: 11.5px;
    }
    .fw-copy { order: 3; width: 100%; }
    .fw-suporte { margin-left: 0; }

    /* formulários empilhados a toda a largura */
    .form-row { flex-direction: column; align-items: stretch; gap: 10px; }
    .form-row .fld { width: 100%; }
    .form-row input, .form-row select, .form-row textarea { width: 100%; min-width: 0 !important; }
    .form-row .btn { justify-content: center; width: 100%; }
    .daybar { gap: 8px; }
    .daybar .data-grande { width: 100%; order: -1; }
    .daybar form { flex: 1; }
    .daybar form input[type=date], .daybar form input[type=month] { flex: 1; }
    .acoes-dia .btn { flex: 1 1 45%; justify-content: center; }
    .kpis { gap: 8px; }
    .kpi { min-width: 44%; padding: 10px 12px; }
    .kpi b { font-size: 17px; }
    .card { padding: 14px; }
    .wrap { width: calc(100% - 20px); margin: 14px auto; }

    /* tabelas de gestão deslizam na horizontal */
    .card > .lista { display: block; overflow-x: auto; white-space: nowrap; }

    .grade th.cliente-col, .grade td.cliente { min-width: 116px; padding: 0 10px; font-size: 13.5px; }
}
