:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --danger: #b91c1c;
    --ok: #047857;
    --warning: #b45309;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}
.header {
    background: linear-gradient(135deg, #173b70, #2563eb);
    color: #fff;
    padding: 22px 0;
}
.app-shell { width: 80%; max-width: none; min-width: 0; margin: 0 auto; }
.header-inner { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.header h1 { margin: 0 0 6px; font-size: 26px; }
.header p { margin: 0; opacity: .9; }
.userbox { text-align: right; font-size: 14px; }
.userbox a { color: #fff; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid.three { grid-template-columns: 1fr 1.2fr 1fr; }
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}
.card h1, .card h2 { margin-top: 0; }
.card h2 { font-size: 20px; background: #d9d9d9; color: #1f2937; padding: 9px 12px; border-radius: 10px; margin: -4px -4px 14px; }
.card h3 { margin: 8px 0; font-size: 16px; }
label { display: block; font-weight: 700; margin-top: 12px; margin-bottom: 6px; }
input, textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 14px;
    background: #fff;
}
textarea { min-height: 86px; resize: vertical; }
button, .btn {
    display: inline-block;
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    margin-top: 12px;
    white-space: nowrap;
}
button:hover, .btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #64748b; }
.btn.danger { background: var(--danger); }
.btn.compact { margin-top: 0; padding: 9px 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.small { font-size: 13px; color: var(--muted); }
.flex-grow { flex: 1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8fafc; font-size: 13px; color: #334155; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e0e7ff; color: #3730a3; }
.badge.done { background: #dcfce7; color: var(--ok); }
.badge.progress { background: #fef3c7; color: var(--warning); }
.badge.todo { background: #e0f2fe; color: #0369a1; }
.nav { grid-column: 1 / -1; margin-top: 4px; display: flex; gap: 14px; flex-wrap: wrap; }
.nav a { color: #fff; text-decoration: underline; font-weight: 700; }
.notice { padding: 10px 12px; border-radius: 10px; background: #ecfdf5; border: 1px solid #bbf7d0; color: #065f46; margin: 16px 0; }
.errorbox { padding: 10px 12px; border-radius: 10px; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; margin: 12px 0; }
.footer { text-align: center; color: var(--muted); padding: 24px; }
.checklist {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px;
    max-height: 220px;
    overflow: auto;
    background: #fff;
}
.checkitem { display: block; font-weight: 400; margin: 6px 0; }
.checkitem input { width: auto; margin-right: 6px; }
.top-project { margin-top: 16px; }
.project-selector label { margin: 0; min-width: 110px; }
.project-selector select { max-width: 360px; }
.inline-editor {
    display: grid;
    grid-template-columns: 1fr 1.5fr auto auto;
    gap: 10px;
    align-items: end;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.inline-editor label { margin-top: 0; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 360px; max-width: 100%; padding: 16px; }
.auth-card h1 { font-size: 22px; margin-bottom: 8px; }
.progress-ring { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 115px; }
.bigpct { font-size: 48px; line-height: 1; font-weight: 800; color: var(--primary); }
.bar { height: 12px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: 10px; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.blocker { border-left: 4px solid var(--warning); background: #fffbeb; padding: 10px; border-radius: 8px; margin-bottom: 10px; }
.blocker small { color: #92400e; }
.muted-card { background: #f8fafc; }
canvas { width: 100%; display: block; }
@media (max-width: 1200px) { .app-shell { width: 80%; min-width: 0; } .grid.three { grid-template-columns: 1fr; } }
@media (max-width: 800px) { .app-shell { width: 92%; } .grid { grid-template-columns: 1fr; } .header { padding: 20px 0; } .header-inner { grid-template-columns: 1fr; } .userbox { text-align: left; } .inline-editor { grid-template-columns: 1fr; } .project-selector select { max-width: none; } }

/* Correção v3.2: largura real do ecrã e login compacto */
.app-shell,
.header .app-shell {
    width: 80vw !important;
    max-width: 80vw !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

.auth-wrap {
    width: 100vw !important;
    min-height: 100vh !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 24px !important;
}

.auth-wrap .auth-card,
main.auth-wrap > section.auth-card {
    width: 420px !important;
    max-width: 80vw !important;
    min-width: 0 !important;
    margin: 0 auto !important;
    flex: 0 0 auto !important;
}

.auth-card input,
.auth-card button {
    width: 100%;
}

@media (max-width: 800px) {
    .app-shell,
    .header .app-shell {
        width: 92vw !important;
        max-width: 92vw !important;
    }
    .auth-wrap .auth-card,
    main.auth-wrap > section.auth-card {
        width: 92vw !important;
        max-width: 92vw !important;
    }
}

/* Correção v3.3: headers e títulos das caixas em cinza suave */
.header {
    background: #bfbfbf !important; /* cinza aprox. 25% */
    color: #1f2937 !important;
    border-bottom: 1px solid #a8a8a8 !important;
}
.header h1,
.header p,
.userbox,
.userbox a,
.nav a {
    color: #1f2937 !important;
}
.header p {
    opacity: 0.85 !important;
}
.card h1,
.card h2,
.card h3,
.section-title,
.box-title {
    background: #bfbfbf !important; /* cinza aprox. 25% */
    color: #1f2937 !important;
}
.card h2 {
    border: 1px solid #adadad !important;
}
.auth-card h1 {
    background: #bfbfbf !important;
    color: #1f2937 !important;
    padding: 9px 12px !important;
    border-radius: 10px !important;
    border: 1px solid #adadad !important;
}

/* Correção v3.4: manter apenas a barra geral superior em azul */
.header {
    background: linear-gradient(135deg, #173b70, #2563eb) !important;
    color: #ffffff !important;
    border-bottom: 0 !important;
}
.header h1,
.header p,
.userbox,
.userbox a,
.nav a {
    color: #ffffff !important;
}
.header p {
    opacity: 0.9 !important;
}

/* Ajuste v3.5: limitar backlog visível a 8 itens, com expansão à direita */
.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.card-title-row h2 {
    margin-bottom: 0 !important;
    flex: 1;
}
.backlog-toggle {
    white-space: nowrap;
    margin: 0 !important;
}
.backlog-extra.hidden {
    display: none;
}
.backlog-note {
    text-align: right;
    margin: 8px 0 0;
}

@media (max-width: 800px) {
    .card-title-row {
        align-items: stretch;
        flex-direction: column;
    }
    .backlog-toggle,
    .backlog-note {
        text-align: left;
    }
}
