/* Workspace stylesheet.

   Standalone: this UI does not extend Django's admin, so nothing here is
   overriding admin/css/base.css and nothing has to fight it. The palette
   matches the admin theme so the two surfaces look like one product. */

/* ---------------------------------------------------------------- tokens */
:root {
    --canvas: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;

    --chrome: #1e293b;
    --chrome-fg: #f1f5f9;
    --chrome-muted: #94a3b8;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: #eff6ff;
    --accent-border: #bfdbfe;

    --fg: #0f172a;
    --fg-muted: #64748b;
    --fg-subtle: #94a3b8;

    --border: #dfe5ec;
    --hairline: #edf1f6;

    --success: #15803d;
    --success-bg: #ecfdf3;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-bg: #fef2f2;
    --info: #0369a1;
    --info-bg: #f0f9ff;

    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;

    --nav-width: 248px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--canvas);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- chrome */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 20px;
    height: 56px;
    background: var(--chrome);
    color: var(--chrome-fg);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--chrome-fg);
    font-weight: 700;
    font-size: 1rem;
}
.brand:hover { text-decoration: none; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
}

.top-links {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--chrome-muted);
}
.top-links a,
.top-links button {
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--chrome-fg);
    font: inherit;
    cursor: pointer;
}
.top-links a:hover,
.top-links button:hover {
    background: rgba(255, 255, 255, 0.16);
    text-decoration: none;
}
.top-links .who { color: var(--chrome-muted); }
.top-links .who strong { color: var(--chrome-fg); }

/* ----------------------------------------------------------------- shell */
.shell {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 56px);
}

.nav {
    flex: 0 0 var(--nav-width);
    padding: 16px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    min-height: calc(100vh - 56px);
}

.nav-heading {
    padding: 8px 12px 4px;
    color: var(--fg-subtle);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--fg);
    font-weight: 500;
}
.nav a:hover { background: var(--surface-3); text-decoration: none; }
.nav a.active {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent);
    font-weight: 600;
}
.nav svg { width: 18px; height: 18px; flex: none; opacity: 0.75; }
.nav a.active svg { opacity: 1; }

.main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 24px 28px 48px;
}

.crumbs { margin-bottom: 12px; color: var(--fg-muted); font-size: 0.8125rem; }
.crumbs a { color: var(--fg-muted); }

h1 { margin: 0 0 4px; font-size: 1.5rem; letter-spacing: -0.01em; }
h1 .qualifier {
    margin-left: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--fg-muted);
}
h2 { margin: 0 0 12px; font-size: 1.0625rem; }
.lede { margin: 0 0 20px; color: var(--fg-muted); }

/* ------------------------------------------------------------------ cards */
.card {
    padding: 16px 18px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.tile {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: inherit;
}
.tile:hover { border-color: var(--accent-border); text-decoration: none; }
.tile-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--accent-soft);
    color: var(--accent);
}
.tile-mark svg { width: 20px; height: 20px; }
.tile-warning .tile-mark { background: var(--warning-bg); color: var(--warning); }
.tile-success .tile-mark { background: var(--success-bg); color: var(--success); }
.tile-count { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.tile-label {
    color: var(--fg-muted);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ---------------------------------------------------------------- buttons */
.button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}
.button:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }
.button-secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--fg);
}
.button-secondary:hover { background: var(--surface-3); color: var(--fg); }
.button-success { background: var(--success); }
.button-success:hover { background: #166534; }
.button-danger { background: var(--danger); }
.button-danger:hover { background: var(--danger-hover); }
.button[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* --------------------------------------------------------------- messages */
.messages { margin-bottom: 16px; }
.message {
    padding: 10px 14px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius);
    font-size: 0.8125rem;
}
.message-success { border-color: var(--success); background: var(--success-bg); color: var(--success); }
.message-error   { border-color: var(--danger);  background: var(--danger-bg);  color: var(--danger); }
.message-warning { border-color: var(--warning); background: var(--warning-bg); color: var(--warning); }
.message-info,
.message-debug   { border-color: var(--info);    background: var(--info-bg);    color: var(--info); }

/* ------------------------------------------------------------------ forms */
label { display: block; font-weight: 600; font-size: 0.8125rem; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="file"],
textarea,
select {
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--fg);
    font-family: inherit;
    font-size: 0.8125rem;
    /* Never a fixed height: the padding above has to be free to grow the box,
       or the value is clipped through the edge of the control. */
    height: auto;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}
textarea {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.field { margin-bottom: 16px; }
.field label { margin-bottom: 6px; }
.field .hint { margin-top: 4px; color: var(--fg-muted); font-size: 0.75rem; }
.field .type { color: var(--fg-subtle); font-weight: 500; }
.field input:not([type="checkbox"]),
.field select { min-width: 340px; max-width: 100%; }
.required { color: var(--danger); font-weight: 700; }

.form-actions { display: flex; gap: 8px; padding-top: 4px; }

/* ---------------------------------------------------------------- filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 18px;
    padding: 14px 16px;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.filters .filter { display: flex; flex-direction: column; gap: 6px; }
.filters label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--fg-muted);
}
.filters select,
.filters input[type="date"] { min-width: 190px; }
.filter-range { display: flex; align-items: center; gap: 8px; }
.filters .filter-actions { flex-direction: row; align-items: center; }
.filter-sep { color: var(--fg-muted); font-size: 0.8125rem; }
.filter-count { margin-left: auto; color: var(--fg-muted); font-size: 0.8125rem; }

/* ----------------------------------------------------------------- tables */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: auto;
}

table.data { width: 100%; border-collapse: collapse; }
table.data th,
table.data td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--hairline);
    text-align: left;
    vertical-align: middle;
    font-size: 0.8125rem;
}
table.data thead th {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--fg-muted);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.2;
    text-transform: uppercase;
    vertical-align: bottom;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.selected { background: var(--accent-soft); }
table.data td.actions-cell { white-space: nowrap; }
table.data td.actions-cell .button { padding: 5px 10px; }
.select-col { width: 34px; }

/* A table of unknown width - the dynamic tables run to twenty columns - is
   laid out at the width it needs and scrolled sideways inside .table-wrap.
   Without this, the 100% above scales every column down until the headings
   collide with one another. */
table.data.wide { table-layout: fixed; width: max-content; min-width: 100%; }
table.data.wide th.id-col,
table.data.wide td.id-col { width: 72px; }
table.data.wide th.data-col,
table.data.wide td.data-col { width: 168px; }
/* Pinned, so acting on a row does not mean scrolling the whole width across
   and losing sight of which row it was. A sticky cell paints its own
   background or the columns slide visibly under it. */
table.data.wide th.actions-cell,
table.data.wide td.actions-cell {
    width: 156px;
    position: sticky;
    right: 0;
    border-left: 1px solid var(--border);
}
table.data.wide thead th.actions-cell { background: var(--surface-2); z-index: 1; }
table.data.wide tbody td.actions-cell { background: var(--surface); }
table.data.wide tbody tr:hover td.actions-cell { background: var(--surface-2); }
table.data.wide tbody tr.selected td.actions-cell { background: var(--accent-soft); }
table.data.wide td.data-col .cell {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty { color: var(--fg-subtle); font-style: italic; }
.empty-row { padding: 28px; text-align: center; }

/* ------------------------------------------------------------- pagination */
.paginator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 2px;
    color: var(--fg-muted);
    font-size: 0.8125rem;
}
.paginator .current { font-weight: 600; color: var(--fg); }

/* The copy at the top of a list carries the count as well as the links, and
   the two are pushed apart so the count reads as a heading for what follows
   rather than as part of the controls. */
.paginator-top {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.paginator-links {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --------------------------------------------------------------- markdown */
.answer {
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    white-space: pre;
}

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.pill-on  { background: var(--success-bg); color: var(--success); }
.pill-off { background: var(--surface-3); color: var(--fg-muted); }

.columns-two {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}
.column-list { margin: 0; padding-left: 20px; font-size: 0.8125rem; }
.column-list li { margin-bottom: 4px; }

/* ------------------------------------------------------------------ login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--canvas);
}

/* Two panels: the illustration, and the form. The grid is what drops the
   illustration on a narrow screen - see the media query at the end. */
.login-card {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    width: 100%;
    max-width: 940px;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 24px rgba(15, 23, 42, 0.10);
}

.login-art {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 32px 28px;
    /* A tint the illustration's own blues sit inside, rather than the flat
       white that would leave its edges floating on the panel. */
    background: linear-gradient(160deg, var(--accent-soft), var(--surface) 70%);
    border-right: 1px solid var(--border);
}
.login-art img {
    display: block;
    width: 100%;
    max-width: 420px;
    height: auto;
    /* The illustration carries its own near-white background, which would
       otherwise sit on the tint as a visible rectangle. Multiplying drops the
       white into whatever is behind it and leaves the artwork alone. */
    mix-blend-mode: multiply;
}
.login-art-caption {
    margin: 0;
    max-width: 34ch;
    color: var(--fg-muted);
    font-size: 0.8125rem;
    text-align: center;
}

.login-form { padding: 36px 32px; align-self: center; }
.login-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-weight: 700;
}
.login-brand .brand-mark { width: 28px; height: 28px; }
.login-card h1 { margin-bottom: 20px; font-size: 1.25rem; }
.login-card .field input { width: 100%; min-width: 0; }
.login-card .button { width: 100%; justify-content: center; }

/* Below this the two panels would each be too narrow to be worth having, and
   the illustration would push the form off the screen. The form is the point
   of the page, so the illustration goes. */
@media (max-width: 780px) {
    .login-card { grid-template-columns: 1fr; max-width: 400px; }
    .login-art { display: none; }
}

@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .nav {
        flex: none;
        width: 100%;
        min-height: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .main { padding: 16px; }
}
