/* Cofre Digital — design system (plano de controlo).
   Aspeto empresarial, sóbrio: paleta neutra slate + um acento, sombras discretas,
   espaçamento consistente. Estiliza elementos semânticos (para as páginas existentes
   herdarem o aspeto) e oferece classes de componente (.cd-card, .cd-btn, .cd-table…). */

:root {
    --cd-bg: #eef1f5;
    --cd-surface: #ffffff;
    --cd-ink: #1c2733;
    --cd-ink-soft: #5a6b7b;
    --cd-line: #e2e8f0;
    --cd-brand: #0d3b66;      /* azul profundo institucional */
    --cd-brand-600: #12508c;
    --cd-accent: #148f77;     /* teal para ações/positivo */
    --cd-nav: #0f1f30;        /* sidebar escura */
    --cd-nav-ink: #c6d4e1;
    --cd-nav-active: #1d3a57;
    --cd-ok: #148f77;
    --cd-warn: #b8860b;
    --cd-crit: #c0392b;
    --cd-radius: 10px;
    --cd-shadow: 0 1px 2px rgba(16,32,48,.06), 0 4px 16px rgba(16,32,48,.06);
    --cd-font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--cd-font);
    color: var(--cd-ink);
    background: var(--cd-bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 1.75rem 0 .75rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 .5rem; }
a { color: var(--cd-brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: "Cascadia Code", "Consolas", monospace; font-size: .86em;
       background: #f1f4f8; padding: .1em .4em; border-radius: 4px; color: #33475b; }
p { color: var(--cd-ink); }

/* ── Estrutura: sidebar + conteúdo ── */
.cd-shell { display: flex; min-height: 100vh; }

.cd-sidebar {
    width: 232px; flex-shrink: 0; background: var(--cd-nav); color: var(--cd-nav-ink);
    padding: 1.25rem 0; display: flex; flex-direction: column;
}
.cd-brand {
    display: flex; align-items: center; gap: .55rem; padding: 0 1.25rem 1.25rem;
    font-size: 1.05rem; font-weight: 650; color: #fff; letter-spacing: -.01em;
    border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: .75rem;
}
.cd-brand .cd-brand-mark {
    width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--cd-brand-600), var(--cd-accent)); font-size: 1rem;
}
.cd-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 .6rem; }
.cd-nav a {
    color: var(--cd-nav-ink); text-decoration: none; padding: .55rem .75rem; border-radius: 7px;
    font-size: .92rem; display: flex; align-items: center; gap: .55rem; transition: background .12s;
}
.cd-nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.cd-nav a.active { background: var(--cd-nav-active); color: #fff; font-weight: 550; }
.cd-nav-spacer { flex: 1; }
.cd-nav-foot { padding: .75rem 1.25rem 0; font-size: .8rem; color: #6b7f92; }
.cd-nav-foot a { color: #8ea3b7; }

.cd-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cd-topbar {
    height: 56px; background: var(--cd-surface); border-bottom: 1px solid var(--cd-line);
    display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 10;
}
.cd-topbar .cd-user { color: var(--cd-ink-soft); font-size: .9rem; }
.cd-content { padding: 1.75rem; max-width: 1280px; width: 100%; }

/* ── Cartões ── */
.cd-card {
    background: var(--cd-surface); border: 1px solid var(--cd-line); border-radius: var(--cd-radius);
    box-shadow: var(--cd-shadow); padding: 1.25rem 1.35rem; margin-bottom: 1.25rem;
}
.cd-card > h2:first-child, .cd-card > h3:first-child { margin-top: 0; }
.cd-muted { color: var(--cd-ink-soft); }
.cd-toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }

/* ── Tabelas (também apanha <table> nu das páginas antigas) ── */
table, .cd-table {
    width: 100%; border-collapse: collapse; background: var(--cd-surface);
    border: 1px solid var(--cd-line); border-radius: var(--cd-radius); overflow: hidden;
}
thead tr { background: #f5f8fb; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
     color: var(--cd-ink-soft); font-weight: 600; padding: .7rem .85rem; border-bottom: 1px solid var(--cd-line); }
td { padding: .7rem .85rem; border-bottom: 1px solid var(--cd-line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fbfd; }

/* ── Botões (também apanha <button> nu) ── */
button, .cd-btn {
    font-family: inherit; font-size: .9rem; font-weight: 550; cursor: pointer;
    background: var(--cd-brand); color: #fff; border: 1px solid transparent;
    padding: .5rem .9rem; border-radius: 7px; transition: background .12s, box-shadow .12s;
}
button:hover, .cd-btn:hover { background: var(--cd-brand-600); }
button:disabled { opacity: .5; cursor: not-allowed; }
.cd-btn-ghost { background: transparent; color: var(--cd-brand-600); border-color: var(--cd-line); }
.cd-btn-ghost:hover { background: #f1f4f8; }
.cd-btn-danger { background: var(--cd-crit); }
.cd-btn-danger:hover { background: #a93226; }
.cd-btn-primary { background: var(--cd-accent); }
.cd-btn-primary:hover { background: #0f7d68; }
a.cd-btn { display: inline-block; text-decoration: none; }
.cd-input {
    font-family: inherit; font-size: .92rem; color: var(--cd-ink);
    background: var(--cd-surface); border: 1px solid var(--cd-line);
    border-radius: 7px; padding: .5rem .7rem; width: 100%;
}
.cd-input:focus { outline: 2px solid var(--cd-accent); outline-offset: 1px; border-color: var(--cd-accent); }
.cd-langbar { position: fixed; top: 1rem; right: 1rem; z-index: 50; display: flex; gap: .1rem;
    border: 1px solid var(--cd-line); border-radius: 999px; padding: .15rem; background: var(--cd-surface); }
/* Na área de cliente (que tem topbar própria), a barra flutuante colidia com o "Terminar sessão".
   Esconde-se a flutuante e usa-se a variante inline dentro da topbar. */
.cd-langbar:has(+ .cd-shell) { display: none; }
.cd-langbar-inline { position: static; top: auto; right: auto; z-index: auto; }
.cd-langbtn { font: 600 .72rem/1 "IBM Plex Mono", monospace; letter-spacing: .04em; padding: .3rem .55rem;
    border-radius: 999px; text-decoration: none; color: var(--cd-ink-soft); }
.cd-langbtn:hover { color: var(--cd-ink); }
.cd-langbtn.active { color: #fff; background: var(--cd-accent); }

/* ── Inputs (também apanha os nus) ── */
input, select, textarea {
    font-family: inherit; font-size: .9rem; color: var(--cd-ink); background: #fff;
    border: 1px solid #cdd7e1; border-radius: 7px; padding: .45rem .6rem;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--cd-brand-600); box-shadow: 0 0 0 3px rgba(18,80,140,.12);
}

/* ── Badges / semáforos ── */
.cd-badge { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem;
    border-radius: 999px; font-size: .78rem; font-weight: 600; }
.cd-badge-ok   { background: #e3f4ef; color: #0f6f5c; }
.cd-badge-warn { background: #fbf1d9; color: #8a6400; }
.cd-badge-crit { background: #fbe3df; color: #a5281b; }
.cd-badge-idle { background: #eef1f5; color: #5a6b7b; }
.cd-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.cd-dot-ok { background: var(--cd-ok); } .cd-dot-warn { background: var(--cd-warn); }
.cd-dot-crit { background: var(--cd-crit); } .cd-dot-idle { background: #a9b6c3; }

/* ── Utilidades de layout (formulários e linhas de cartões) ── */
.cd-row { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: flex-start; }
.cd-row > .cd-card { flex: 1 1 300px; margin: 0; }
.cd-stack { display: flex; flex-direction: column; gap: .6rem; }
.cd-stack > input, .cd-stack > select { width: 100%; }
.cd-selectable { user-select: all; }

/* ── Login ── */
.cd-login-wrap { min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(1200px 600px at 30% -10%, #123a5e 0%, #0b1a2b 55%, #08111c 100%); padding: 1rem; }
.cd-login-card { width: 100%; max-width: 380px; background: var(--cd-surface);
    border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); padding: 2rem; }
.cd-login-brand { display: flex; align-items: center; gap: .6rem; font-size: 1.2rem; font-weight: 650;
    color: var(--cd-brand); margin-bottom: .35rem; }
.cd-login-card label { display: block; font-size: .85rem; font-weight: 550; color: var(--cd-ink-soft);
    margin: .9rem 0 .3rem; }
.cd-login-card input { width: 100%; }
.cd-login-card button { width: 100%; margin-top: 1.25rem; padding: .6rem; }
.cd-login-err { background: #fbe3df; color: #a5281b; border-radius: 7px; padding: .55rem .7rem;
    font-size: .87rem; margin-top: .9rem; }

.cd-alert-line { padding: .7rem .9rem; border-radius: 8px; margin: .5rem 0; font-size: .9rem; }
.cd-alert-crit { background: #fbe3df; color: #7d2018; border-left: 3px solid var(--cd-crit); }
.cd-alert-warn { background: #fbf1d9; color: #6b4e07; border-left: 3px solid var(--cd-warn); }
.cd-alert-info { background: #e7eef6; color: #234; border-left: 3px solid var(--cd-brand-600); }

@media (max-width: 820px) {
    .cd-shell { flex-direction: column; }
    .cd-sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: .5rem; }
    .cd-brand { border: none; margin: 0 1rem 0 0; padding: 0 .5rem; white-space: nowrap; }
    .cd-nav { flex-direction: row; }
    .cd-nav-spacer, .cd-nav-foot { display: none; }
}

/* ---- Área de cliente: master-detail (acordeão + detalhe) ---- */
.cd-md { display: flex; gap: 1.2rem; margin-top: 1rem; align-items: flex-start; }
.cd-md-nav { flex: 0 0 260px; max-width: 260px; background: var(--cd-surface); border: 1px solid var(--cd-line); border-radius: 10px; padding: .8rem; }
.cd-md-detail { flex: 1 1 auto; min-width: 0; }
.cd-md-company { font-weight: 700; font-size: 1.1rem; margin-bottom: .4rem; color: var(--cd-ink); }
.cd-acc-h { display: flex; align-items: center; gap: .4rem; width: 100%; text-align: left; background: transparent; color: var(--cd-ink); border: none; padding: .5rem .2rem; font-weight: 600; cursor: pointer; }
.cd-acc-h:hover { background: #f1f4f8; }
.cd-acc-item { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; background: transparent; color: var(--cd-ink); border: none; border-radius: 6px; padding: .4rem .6rem .4rem 1.4rem; cursor: pointer; font-size: .92rem; }
.cd-acc-item:hover { background: #f1f4f8; }
.cd-acc-item.sel { background: var(--cd-accent); color: #fff; }
.cd-acc-add { width: calc(100% - 1.2rem); text-align: left; background: transparent; color: var(--cd-brand-600); border: 1px dashed var(--cd-line); border-radius: 6px; padding: .35rem .6rem; margin: .3rem 0 .3rem 1.2rem; cursor: pointer; font-size: .85rem; }
.cd-acc-add:hover { background: #f1f4f8; }
.cd-events { border: 1px solid var(--cd-line); border-radius: 8px; max-height: 340px; overflow-y: auto; }
.cd-ev { display: flex; gap: .7rem; align-items: baseline; padding: .4rem .7rem; border-bottom: 1px solid var(--cd-line); font-size: .86rem; }
.cd-ev:last-child { border-bottom: none; }
.cd-ev-when { color: var(--cd-ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cd-ev-kind { font-weight: 600; text-transform: uppercase; font-size: .72rem; letter-spacing: .03em; padding: .05rem .4rem; border-radius: 4px; white-space: nowrap; }
.cd-ev-kind.ev-ok { background: #e4f6ef; color: #0f7d68; }
.cd-ev-kind.ev-warn { background: #fef3e0; color: #a86a12; }
.cd-ev-kind.ev-crit { background: #fbe3df; color: #a93226; }
.cd-ev-kind.ev-info { background: #eef1f4; color: #5a6b7b; }
.cd-ev-text { color: var(--cd-ink); word-break: break-word; }
textarea.cd-input { resize: vertical; font-family: inherit; }
@media (max-width: 760px) {
    .cd-md { flex-direction: column; }
    .cd-md-nav { flex-basis: auto; max-width: none; width: 100%; }
}

/* Botão que parece uma ligação (ex.: "Terminar sessão" em POST com token antiforgery). */
.cd-linklike { background: none; border: 0; padding: 0; font: inherit; color: #8ea3b7; cursor: pointer; text-decoration: underline; }
.cd-linklike:hover { background: none; color: #fff; }
