/* Design tokens — adapted from design.md (Vercel-style: monochrome canvas,
   shadow-as-border, tight tracking, restrained accents). Vanilla CSS since
   this is server-rendered Django, not React/Tailwind. */

:root {
    --font-sans: Geist, "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "Geist Mono", "SFMono-Regular", Consolas, monospace;

    --color-bg: #ffffff;
    --color-bg-subtle: #fafafa;
    --color-surface: #ffffff;
    --color-text: #171717;
    --color-text-muted: #666666;
    --color-text-faint: #8f8f8f;
    --color-border-shadow: rgba(0, 0, 0, 0.08);
    --color-border-shadow-strong: rgba(0, 0, 0, 0.14);

    --color-accent: #0070f3;
    --color-accent-bg: #f0f6ff;
    --color-focus: hsla(212, 100%, 48%, 1);

    --color-danger: #e5484d;
    --color-danger-bg: #fff1f0;
    --color-warning: #f5a623;
    --color-warning-bg: #fff8ec;
    --color-success: #12805c;
    --color-success-bg: #eefaf3;

    --priority-baixa: #666666;
    --priority-media: #0070f3;
    --priority-alta: #f5a623;
    --priority-urgente: #e5484d;

    /* Editor de codigo/Markdown (static/css/components.css, static/js/code_editor.js)
       — fundo sempre escuro (visual de IDE de verdade), independente do
       tema claro/escuro do resto do site. */
    --code-bg: #1e1e2e;
    --code-text: #d4d4e0;
    --code-gutter: #6c6f85;
    --code-kw: #c678dd;
    --code-str: #98c379;
    --code-com: #7f848e;
    --code-num: #d19a66;
    --code-deco: #56b6c2;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-border: 0 0 0 1px var(--color-border-shadow);
    --shadow-card: 0 0 0 1px var(--color-border-shadow), 0 2px 2px rgba(0, 0, 0, 0.04);
    --shadow-raised: 0 0 0 1px var(--color-border-shadow), 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-focus: 0 0 0 1px var(--color-bg), 0 0 0 3px var(--color-focus);

    --sidebar-w: 248px;
    --topbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #0a0a0a;
        --color-bg-subtle: #111111;
        --color-surface: #171717;
        --color-text: #ededed;
        --color-text-muted: #a1a1a1;
        --color-text-faint: #757575;
        --color-border-shadow: rgba(255, 255, 255, 0.12);
        --color-border-shadow-strong: rgba(255, 255, 255, 0.2);
        --color-accent-bg: #0d1b2e;
        --color-danger-bg: #2a1415;
        --color-warning-bg: #241c0d;
        --color-success-bg: #0d2019;
    }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }

/* The [hidden] attribute must win over any component's own `display`
   rule (e.g. `.field { display: flex }`) — same specificity, and without
   this an element toggled via `.hidden = true` in JS stays visible. */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "liga" 1;
}

.tabular-nums { font-variant-numeric: tabular-nums; }

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
h1 .icon, h2 .icon, h3 .icon, h4 .icon { vertical-align: -3px; margin-right: 3px; color: var(--color-text-faint); }
p { margin: 0; }

a { color: inherit; }

/* Focus — never remove outline without a visible replacement */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}

/* ---------- Buttons ---------- */
.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 0;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-border);
    cursor: pointer;
    transition: background-color 0.12s ease, box-shadow 0.12s ease, transform 0.1s ease;
    white-space: nowrap;
}
.btn:hover { background: var(--color-bg-subtle); box-shadow: 0 0 0 1px var(--color-border-shadow-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--color-text); color: var(--color-bg); box-shadow: none; }
.btn-primary:hover { background: var(--color-text); opacity: 0.85; }

.btn-danger { color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-bg); }

.btn-ghost { box-shadow: none; background: transparent; }
.btn-ghost:hover { background: var(--color-bg-subtle); }

.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-icon { width: 32px; padding: 0; }

.btn .spinner { display: none; }
.btn[aria-busy="true"] .spinner { display: inline-block; }
.btn[aria-busy="true"] .btn-label-icon { display: none; }

.spinner {
    width: 13px; height: 13px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 1.4s; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--color-text-muted); }
.field-hint { font-size: 12px; color: var(--color-text-faint); }
.field-error { font-size: 12px; color: var(--color-danger); }

input[type=text], input[type=password], input[type=email], input[type=search],
input[type=date], input[type=number], textarea, select {
    font: inherit;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-surface);
    border: 0;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-border);
    padding: 8px 10px;
    min-height: 36px;
    width: 100%;
    transition: box-shadow 0.12s ease;
}
textarea { min-height: 88px; resize: vertical; font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--color-text-faint); }
input:hover, textarea:hover, select:hover { box-shadow: 0 0 0 1px var(--color-border-shadow-strong); }

.checkbox-row { display: flex; align-items: center; gap: 8px; min-height: 24px; }
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; margin: 0; }
.checkbox-row label { font-size: 13px; color: var(--color-text); cursor: pointer; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 20px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}
.badge-neutral { background: var(--color-bg-subtle); color: var(--color-text-muted); box-shadow: var(--shadow-border); }
.badge-accent { background: var(--color-accent-bg); color: var(--color-accent); }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }

.priority-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.priority-baixa { background: var(--priority-baixa); }
.priority-media { background: var(--priority-media); }
.priority-alta { background: var(--priority-alta); }
.priority-urgente { background: var(--priority-urgente); }

/* ---------- Avatar ---------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--color-text);
    color: var(--color-bg);
    font-size: 10px;
    font-weight: 600;
    flex: none;
    box-shadow: 0 0 0 2px var(--color-surface);
}
.avatar-lg { width: 36px; height: 36px; font-size: 13px; }

/* ---------- Cards / surfaces ---------- */
.surface {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

/* ---------- Icons ---------- */
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 20px; height: 20px; }

/* ---------- Toasts ---------- */
#toast-region {
    position: fixed;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 90;
}
.toast {
    background: var(--color-text);
    color: var(--color-bg);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-raised);
    font-size: 13px;
    max-width: 320px;
    animation: toast-in 0.16s ease;
}
.toast.toast-danger { background: var(--color-danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Skip link ---------- */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--color-text);
    color: var(--color-bg);
    padding: 8px 12px;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 100;
}
.skip-link:focus { left: 0; }

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-faint);
    padding: 10px 14px;
    box-shadow: inset 0 -1px 0 var(--color-border-shadow);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 14px;
    box-shadow: inset 0 -1px 0 var(--color-border-shadow);
    vertical-align: middle;
}
.data-table tr:last-child td { box-shadow: none; }
.data-table tr:hover td { background: var(--color-bg-subtle); }
.row-link { text-decoration: none; color: inherit; display: flex; align-items: center; gap: 8px; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--color-text-faint); font-size: 13px; }

/* ---------- Page toolbar (search + filters above a list/table) ---------- */
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* ---------- Simple two-column form layout ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-section { margin-bottom: 22px; }
.form-section h2 { margin-bottom: 4px; }
.form-section .lede { color: var(--color-text-muted); font-size: 13px; margin-bottom: 14px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; }
.perm-app-group { margin-bottom: 14px; }
.perm-app-group > summary { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); cursor: pointer; padding: 6px 0; }

::selection { background: var(--color-accent); color: #fff; }
