/*
 * Panel design system. Hand-written, no build step. Colours and shapes follow the brand (brand/a-botta-e-risposta):
 * milk paper, ink text, maize as a ground only (--accent), never as text: text on light uses --accent-text.
 * Reuse the tokens and components below instead of restyling: buttons, fields, cards, badges, lists,
 * empty states, toasts, notice, segmented control, chips, table, page header.
 */

@font-face {
    font-family: "Parkinsans"; /* SIL OFL: assets/fonts/LICENSE-parkinsans.txt */
    font-style: normal;
    font-weight: 300 800;
    font-display: swap;
    src: url("../fonts/parkinsans-latin-wght.woff2") format("woff2");
}

:root {
    --bg: #f8f4ea;
    --surface: #fffdf7;
    --surface-2: #f3eee2;
    --border: #e9e2d0;
    --border-strong: #d3cab4;
    --text: #221e1a;
    --text-2: #4a443c;
    --text-3: #6b655c;

    --accent: #ffc83d;
    --accent-hover: #f2b41f;
    --accent-soft: #fff1c9;
    --accent-text: #6b4a00;
    --on-accent: #221e1a;

    --success: #1d8a4c;
    --success-soft: #e7f5ed;
    --warning: #a86400;
    --warning-soft: #fdf4e3;
    --danger: #c43a3a;
    --danger-soft: #fcecec;

    --font-head: "Parkinsans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --text-xs: 12px;
    --text-sm: 13px;
    --text-md: 14px;
    --text-lg: 16px;
    --text-xl: 20px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 2px rgb(16 20 30 / 6%);
    --shadow-lg: 0 10px 30px rgb(16 20 30 / 12%), 0 2px 6px rgb(16 20 30 / 6%);
    --focus: 0 0 0 3px rgb(34 30 26 / 28%);

    --sidebar-width: 232px;
    --bottom-bar: 60px;
    color-scheme: light;
}

/* Base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: var(--text-md)/1.5 var(--font);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.icon { flex-shrink: 0; }

/* Utilities */

.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: var(--text-sm); }
.mono { font-family: var(--mono); font-size: var(--text-sm); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.spacer { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* Buttons */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    height: 36px; padding: 0 var(--space-4);
    border: 1px solid transparent; border-radius: 999px;
    font-size: var(--text-md); font-weight: 500; line-height: 1; white-space: nowrap;
    cursor: pointer; text-decoration: none;
    transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--text); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--surface); border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-block { width: 100%; }
.btn-icon { width: 32px; height: 32px; padding: 0; }

/* Fields */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.label { font-size: var(--text-sm); font-weight: 500; color: var(--text); padding: 0; }
legend.label { margin-bottom: 6px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.hint { font-size: var(--text-xs); color: var(--text-3); }
.input, .select, .textarea {
    width: 100%; min-height: 36px; padding: 7px 10px;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    transition: border-color .12s, box-shadow .12s;
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--text); box-shadow: var(--focus); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.is-invalid { border-color: var(--danger); }
.checkbox { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* Chips: checkbox multi-select */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
    display: inline-block; padding: 4px 10px;
    border: 1px solid var(--border-strong); border-radius: 999px;
    font-size: var(--text-sm); color: var(--text-2); background: var(--surface);
    transition: background-color .12s, border-color .12s, color .12s;
}
.chip:hover span { border-color: var(--text-3); }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.chip input:focus-visible + span { box-shadow: var(--focus); }

/* Alerts and notice */

.alert { padding: 10px var(--space-3); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.notice {
    display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    background: var(--warning-soft); color: #6d4300; font-size: var(--text-sm);
    border-bottom: 1px solid #f3e1bd;
}

/* Cards */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-header {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--text-md); font-weight: 600; }
.card-body { padding: var(--space-5); }
.card-footer {
    display: flex; justify-content: flex-end; gap: var(--space-2);
    padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Badges, dots, avatars */

.badge {
    display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px;
    border-radius: 999px; background: var(--surface-2); color: var(--text-2);
    font-size: var(--text-xs); font-weight: 500; white-space: nowrap;
}
.badge-lang { font-family: var(--mono); text-transform: uppercase; letter-spacing: .02em; }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-count { min-width: 20px; justify-content: center; background: var(--accent); color: var(--on-accent); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.dot-available, .dot-online { background: var(--success); }
.dot-away { background: #d9a43a; }
.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
    font-size: var(--text-xs); font-weight: 600;
}

/* Lists */

.list { list-style: none; margin: 0; padding: 0; }
.list-item {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border);
    color: inherit;
}
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, button.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item.is-active { background: var(--accent-soft); }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 500; }
.list-item-meta { font-size: var(--text-sm); color: var(--text-2); }

/* Table */

.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
    text-align: left; font-weight: 500; color: var(--text-2);
    padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

/* Segmented control (status toggle, Map / List switch) */

.segmented { display: flex; padding: 2px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.segmented-option {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 28px; padding: 0 var(--space-2); border: 0; border-radius: 4px; background: transparent;
    font-size: var(--text-sm); color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.segmented-option:hover { color: var(--text); }
.segmented-option.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }

/* Empty state */

.empty {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    max-width: 380px; margin: 0 auto; padding: var(--space-7) var(--space-4);
}
.empty-icon {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-bottom: var(--space-4);
    border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
}
.empty-title { font-size: var(--text-lg); font-weight: 600; }
.empty-text { margin-top: 6px; color: var(--text-2); }
.empty-actions { margin-top: var(--space-5); display: flex; gap: var(--space-2); }

/* Toasts */

.toasts {
    position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 100;
    display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-2);
    pointer-events: none;
}
.toast {
    max-width: 360px; padding: 10px 14px; border-radius: var(--radius);
    background: var(--text); color: #fff; font-size: var(--text-sm); box-shadow: var(--shadow-lg);
    pointer-events: auto; animation: toast-in .16s ease-out;
}
.toast-error { background: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* Brand */

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 28px; height: 28px; border-radius: 9px 9px 9px 3px; background: var(--accent); color: var(--on-accent);
}
.brand-mark .logo { width: 20px; height: auto; }
.brand-name .logo { width: auto; height: 24px; }
.sidebar .brand-mark { display: none; } /* the wordmark already holds the two bubbles; the mark stands in on mobile */
.auth .brand-name .logo { height: 34px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-name { display: flex; font-weight: 600; }

/* Workspace switcher (layout.php): the current workspace, and a menu with the others of the account */

.sites { position: relative; margin-top: calc(-1 * var(--space-3)); min-width: 0; }
.sites-current {
    display: flex; align-items: center; gap: var(--space-2); height: 34px; padding: 0 var(--space-2);
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
    font-weight: 500; color: var(--text); cursor: pointer; list-style: none; user-select: none;
}
.sites-current::-webkit-details-marker { display: none; }
.sites-current:hover, .sites[open] > .sites-current { background: var(--surface-2); }
.sites-current > .truncate { flex: 1; }
.sites-current > .icon { flex-shrink: 0; color: var(--text-3); }
.sites-menu {
    position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(320px, 90vw);
    display: flex; flex-direction: column; gap: 2px; padding: var(--space-1);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.sites-item {
    display: flex; align-items: center; gap: var(--space-2); min-height: 34px; padding: 0 var(--space-2);
    border: 0; border-radius: var(--radius-sm); background: none; font: inherit; color: var(--text-2); text-align: left; cursor: pointer;
}
.sites-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sites-item.is-active { color: var(--text); font-weight: 500; }
.sites-item > .truncate { flex: 1; }
.sites-new { margin-top: 2px; padding-top: 2px; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-sm) var(--radius-sm); }

/* Panel shell: sidebar on desktop */

.app { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar {
    position: sticky; top: 0; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; gap: var(--space-5);
    padding: var(--space-4) var(--space-3);
    background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar > .brand { padding: var(--space-1) var(--space-2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 var(--space-2);
    border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-text); }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-3); }
.sidebar-user { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-1); }
.sidebar-account {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-2);
    margin: calc(-1 * var(--space-1)); padding: var(--space-1); border-radius: var(--radius-sm); color: var(--text);
}
.sidebar-account:hover { background: var(--surface-2); text-decoration: none; }
.sidebar-account.is-active { background: var(--accent-soft); }
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sidebar-user-name, .sidebar-user-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-name { font-size: var(--text-sm); font-weight: 500; }
.sidebar-user-role { font-size: var(--text-xs); color: var(--text-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.page-header {
    display: flex; align-items: center; gap: var(--space-3); min-height: 60px;
    padding: var(--space-3) var(--space-6); border-bottom: 1px solid var(--border); background: var(--surface);
}
.page-title { font-size: var(--text-lg); font-weight: 600; }
.page-heading { min-width: 0; }
.page-subtitle { font-size: var(--text-sm); color: var(--text-2); }
.page-actions { margin-left: auto; display: flex; gap: var(--space-2); }
.page-body { flex: 1; padding: var(--space-6); }
.page-narrow { max-width: 760px; }

/* Public pages */

.auth-main {
    display: flex; flex-direction: column; align-items: center; gap: var(--space-5);
    min-height: 100vh; padding: var(--space-7) var(--space-4);
}
.auth-card { width: 100%; max-width: 420px; padding: var(--space-6); }
.auth-title { font: 700 24px/1.15 var(--font-head); letter-spacing: -.02em; margin-bottom: var(--space-2); }
.auth-lead { color: var(--text-2); margin-bottom: var(--space-5); }
.auth-card .alert { margin-bottom: var(--space-4); }
.auth-card form { margin-top: var(--space-5); }
.auth-lead + form, .auth-lead + .alert + form { margin-top: 0; }
.auth-alt { margin-top: var(--space-5); text-align: center; font-size: var(--text-sm); color: var(--text-2); }
.auth-footer { font-size: var(--text-sm); }
.auth-footer a { color: var(--text-2); }

/* Mobile: top bar with brand, status and logout; navigation as a bottom bar */

@media (max-width: 767px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding-bottom: var(--bottom-bar); }
    .sidebar {
        z-index: 50; height: auto; flex-direction: row; align-items: center; gap: var(--space-3);
        padding: var(--space-2) var(--space-4); border-right: 0; border-bottom: 1px solid var(--border);
    }
    .sidebar > .brand { padding: 0; }
    .brand-name, .sidebar-user-text { display: none; } /* the workspace switcher stands for the name */
    .sidebar .brand-mark { display: flex; }
    .sites { margin-top: 0; flex: 0 1 auto; }
    .sidebar-footer { flex-shrink: 0; } /* the switcher is what gives way: its name truncates */
    .sidebar-account { flex: 0 0 auto; margin: 0; }
    .sidebar-footer { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: var(--space-1); }
    .nav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
        flex-direction: row; gap: 0; height: var(--bottom-bar);
        padding: 0 var(--space-2) env(safe-area-inset-bottom);
        background: var(--surface); border-top: 1px solid var(--border);
    }
    .nav-item {
        flex: 1; flex-direction: column; justify-content: center; gap: 2px; height: 100%;
        font-size: 11px; border-radius: 0;
    }
    .nav-item.is-active { background: transparent; }
    .page-header { padding: var(--space-3) var(--space-4); min-height: 52px; }
    .page-body { padding: var(--space-4); }
    .toasts { left: var(--space-4); right: var(--space-4); bottom: calc(var(--bottom-bar) + var(--space-3)); align-items: stretch; }
    .toast { max-width: none; }
    .auth-main { padding-top: var(--space-6); }
    .auth-card { padding: var(--space-5); }
}
@media (max-width: 420px) {
    .sidebar > .brand { display: none; } /* room for the workspace name */
}
