:root {
    --bg: #f4f5f7; --card: #fff; --line: #e1e4e8; --ink: #1c2430;
    --muted: #6b7785; --primary: #2563eb; --primary-ink: #fff; --danger: #c0392b;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 -apple-system, Segoe UI, Roboto, sans-serif;
       color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px;
          height: 56px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; }
.brand .tenant { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 16px; margin-left: 8px; }
.topbar .who { margin-left: auto; color: var(--muted); display: flex; gap: 12px; align-items: center; }
.logout { color: var(--danger); }

.wrap { max-width: 920px; margin: 24px auto; padding: 0 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0; }

.flash { background: #e7f6ec; border: 1px solid #b6e0c4; color: #1d6b3a;
         padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.error { background: #fdecea; border: 1px solid #f5c2bd; color: var(--danger);
         padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }

.btn { display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
       background: var(--card); color: var(--ink); cursor: pointer; font: inherit; }
.btn.primary, a.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.grid { width: 100%; border-collapse: collapse; background: var(--card);
        border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.grid th, .grid td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.grid th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.grid tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.status { padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eef1f4; }
.status-open { background: #e7f0ff; color: #1d4ed8; }
.status-started { background: #fff4e0; color: #b7791f; }
.status-closed { background: #e7f6ec; color: #1d6b3a; }

.form, .login-card { background: var(--card); border: 1px solid var(--line);
                     border-radius: 12px; padding: 22px; }
.login-card { max-width: 360px; margin: 60px auto; }
.login-card h1 { margin-bottom: 16px; }
fieldset { border: 0; padding: 0; margin: 0 0 20px; }
legend { font-weight: 700; padding: 0; margin-bottom: 10px; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
label { font-weight: 600; font-size: 14px; }
.req { color: var(--danger); }
input, select, textarea { padding: 9px 11px; border: 1px solid var(--line);
        border-radius: 8px; font: inherit; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd2ff; border-color: var(--primary); }
.login-card label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* token display */
.token-wrap { display: flex; gap: 8px; }
.token-wrap input { flex: 1; font-family: monospace; font-size: 13px; }

/* entity_ref picker */
.entity-ref { position: relative; }
.entity-search.chosen { border-color: #1d6b3a; background: #f5fbf7; }
.entity-results { position: absolute; z-index: 5; left: 0; right: 0; top: 100%;
        margin: 4px 0 0; padding: 0; list-style: none; background: #fff;
        border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.08);
        max-height: 240px; overflow: auto; display: none; }
.entity-results.open { display: block; }
.entity-results li { padding: 9px 12px; cursor: pointer; }
.entity-results li:hover { background: #eef4ff; }
