:root {
    --paper: #f4f2ec;
    --surface: #fffdf8;
    --sunken: #ebe8df;
    --ink: #1f1e1b;
    --ink-2: #55524a;
    --ink-3: #8a867b;
    --rule: #e0dbcf;
    --rule-strong: #c9c2b2;
    --accent: #2d5a4b;
    --accent-ink: #f4f2ec;
    --accent-soft: #dde8e2;
    --bar-muted: #c3d2ca;
    --warn: #9a5b12;
    --warn-soft: #f4e6d0;
    --danger: #9e3626;
    --danger-soft: #f5dfda;
    --ok: #2d5a4b;
    --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
    --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
    --radius: 3px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--sans); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--paper); font-variant-numeric: tabular-nums; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

/* Estrutura com barra lateral */
.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.sidebar { border-right: 1px solid var(--rule); padding: 28px 20px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.wordmark { font-family: var(--serif); font-size: 21px; font-weight: 600; letter-spacing: -0.01em; text-decoration: none; }
.wordmark small { display: block; font-family: var(--sans); font-size: 11px; font-weight: 400; color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { text-decoration: none; padding: 6px 10px; margin: 0 -10px; border-radius: var(--radius); color: var(--ink-2); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sidebar nav a:hover { background: var(--sunken); color: var(--ink); }
.sidebar nav a[aria-current="page"] { color: var(--ink); font-weight: 600; background: var(--sunken); }
.sidebar .foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-3); }
.sidebar .foot span:first-child { color: var(--ink); font-weight: 500; }
.sidebar .foot button { background: none; border: 0; text-align: left; color: var(--ink-2); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule-strong); }
/* Menu sanduiche: so aparece no celular; no computador o menu fica direto na barra lateral */
.menu-toggle { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 44px; height: 44px; padding: 0 12px; background: none; border: 0; border-radius: var(--radius); cursor: pointer; }
.menu-toggle span { display: block; height: 2px; background: var(--ink); border-radius: 1px; }
.menu-toggle:hover { background: var(--sunken); }
.sidebar-menu { display: contents; }
.sidebar-menu .menu-title { display: none; font-family: var(--serif); font-size: 19px; font-weight: 600; }
.menu-backdrop { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(31, 30, 27, 0.28); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rule-strong); display: inline-block; flex: none; }
.dot.on { background: #3c8a5e; }
.dot.off { background: var(--danger); }
main { padding: 32px 40px 64px; max-width: 1240px; width: 100%; }

@media (max-width: 860px) {
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    /* Barra do topo com menu sanduiche: o menu abre como gaveta pela esquerda */
    .sidebar { position: sticky; top: 0; z-index: 15; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 8px 16px 8px 8px; background: var(--paper); border-right: 0; border-bottom: 1px solid var(--rule); }
    .wordmark small { display: none; }
    .menu-toggle { display: inline-flex; }
    .sidebar-menu { display: flex; flex-direction: column; gap: 24px; position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 85vw); z-index: 31; padding: 20px 16px 24px; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--rule-strong); transform: translateX(-100%); visibility: hidden; transition: transform 0.2s ease, visibility 0.2s; }
    .sidebar.menu-open .sidebar-menu { transform: none; visibility: visible; }
    .sidebar.menu-open .menu-backdrop { display: block; }
    .sidebar-menu .menu-title { display: block; }
    .sidebar nav a { margin: 0; padding: 12px 10px; font-size: 16px; }
    .sidebar .foot { margin-top: auto; font-size: 14px; }
    .sidebar .foot button { padding: 10px 0; font-size: 15px; }
    body.menu-locked { overflow: hidden; }
    main { padding: 20px 16px 48px; }
    main h1 { font-size: 26px; }
    .segmented { max-width: 100%; overflow-x: auto; }
    .segmented button { white-space: nowrap; padding: 9px 12px; }
    label.field { min-width: 0; max-width: 100%; }
    /* Alvos de toque maiores; 16px nos campos evita o zoom automatico do iPhone ao focar */
    .btn { min-height: 40px; }
    input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="date"], input[type="tel"], select, textarea { font-size: 16px; min-height: 40px; }
    .drawer { padding: 20px 16px 40px; }
    .drawer .close { top: 12px; right: 12px; }
    .drawer h2 { padding-right: 72px; }
    .drawer .form textarea, main .form textarea { font-size: 16px; }
    .panel-head { padding: 14px 14px 0; }
    .panel-body { padding: 12px 14px 16px; }
    table.data th, table.data td { padding-left: 8px; padding-right: 8px; }
    .toolbar > * { flex: 1 1 auto; }
}

/* Tipografia */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 30px; letter-spacing: -0.015em; line-height: 1.15; }
h2 { font-family: var(--serif); font-weight: 600; font-size: 18px; letter-spacing: -0.005em; }
.lede { color: var(--ink-2); margin-top: 4px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.eyebrow { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; }

/* Controles */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--rule-strong); background: var(--surface); padding: 6px 12px; border-radius: var(--radius); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #244a3e; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--bar-muted); }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="date"], input[type="tel"], select { border: 1px solid var(--rule-strong); background: var(--surface); border-radius: var(--radius); padding: 6px 9px; min-height: 32px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.segmented { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.segmented button { border: 0; background: none; padding: 6px 11px; cursor: pointer; color: var(--ink-2); border-left: 1px solid var(--rule); }
.segmented button:first-child { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* Etiquetas */
.tag { display: inline-block; font-size: 11.5px; padding: 1px 6px; border-radius: 2px; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.ok { background: var(--accent-soft); color: var(--accent); }

/* Blocos */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 18px 0; }
.panel-body { padding: 14px 18px 18px; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-3); }
.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); margin-bottom: 16px; }

/* Tabelas */
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-3); padding: 8px 12px; border-bottom: 1px solid var(--rule-strong); white-space: nowrap; }
table.data th button { background: none; border: 0; cursor: pointer; color: inherit; font-weight: inherit; padding: 0; }
table.data th[aria-sort] button { color: var(--ink); }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: #f8f6f0; }
table.data td.num, table.data th.num { text-align: right; }
.table-wrap { overflow-x: auto; }

/* Gaveta lateral (detalhes e formularios) */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(31, 30, 27, 0.28); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface); border-left: 1px solid var(--rule-strong); z-index: 21; overflow-y: auto; padding: 24px 24px 40px; }
.drawer h2 { font-size: 24px; margin-top: 4px; }
.drawer .close { position: absolute; top: 16px; right: 16px; }

/* Formularios */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.form .row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form label.field input, .form label.field select { width: 100%; min-height: 36px; }
.form .hint { font-size: 12px; color: var(--ink-3); }
.form .actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--rule); }
.form .actions .end { display: flex; gap: 8px; margin-left: auto; }
.form .notice { margin: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
@media (max-width: 640px) { .form .row { grid-template-columns: 1fr; } }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius); z-index: 50; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }

/* Documentos (assets/documents.js): status por tipo, envio de foto/PDF e assinatura no tablet */
.docs-section { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 10px; }
.docs-section > h3 { font-size: 15px; font-weight: 600; }
.doc-item { border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; background: var(--paper); display: flex; flex-direction: column; gap: 4px; }
.doc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.doc-history { list-style: none; margin-top: 8px; border-top: 1px dashed var(--rule); padding-top: 6px; font-size: 12.5px; color: var(--ink-2); }
.doc-history li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 3px 0; }
.link.danger-link { color: var(--danger); text-decoration-color: var(--danger-soft); }
.sign-overlay { position: fixed; inset: 0; z-index: 40; background: var(--paper); display: flex; flex-direction: column; gap: 12px; padding: 20px max(20px, calc((100vw - 900px) / 2)); }
.sign-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.sign-terms { flex: 1; min-height: 120px; overflow-y: auto; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; white-space: pre-wrap; font-size: 16px; line-height: 1.6; }
.sign-overlay label.field input { min-height: 44px; font-size: 18px; }
.sign-pad-wrap { position: relative; }
.sign-pad { display: block; width: 100%; height: 220px; background: #fff; border: 1px dashed var(--rule-strong); border-radius: var(--radius); touch-action: none; cursor: crosshair; }
.sign-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-3); pointer-events: none; font-size: 15px; }
.sign-actions { display: flex; justify-content: space-between; gap: 12px; }
.sign-actions .btn { min-height: 48px; padding: 0 20px; font-size: 16px; }
