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

:root {
    /* Spoto brand (periwinkle blue) drives interactive elements */
    --spoto-primary: #4f6ef7;
    --spoto-primary-dark: #3f59e0;
    /* UQ institutional purple for headings / accents */
    --uq-purple: #51247a;
    --uq-purple-dark: #3e1b5e;
    --spoto-bg: #f6f7fb;
    --spoto-border: #e6e8ef;
    --spoto-text: #1f2430;
    --spoto-muted: #6b7280;
}

html, body {
    margin: 0;
    font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--spoto-bg);
    color: var(--spoto-text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

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

/* ---- Shell / header ---- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; border-bottom: 1px solid var(--spoto-border);
    padding: 0 1.75rem; height: 72px;
    box-shadow: 0 1px 3px rgba(16,24,40,.05);
    position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; }
.brand:hover { text-decoration: none; opacity: .85; }
.brand-logo { height: 46px; width: auto; display: block; }

.header-right { display: flex; align-items: center; gap: 1rem; }
.signed-in { color: var(--spoto-muted); font-size: .88rem; }
.signed-in strong { color: var(--spoto-text); font-weight: 600; }

.header-divider { width: 1px; height: 28px; background: var(--spoto-border); }

.powered-by { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; line-height: 1; }
.powered-by-label {
    color: var(--spoto-muted); font-size: .68rem; font-weight: 500;
    letter-spacing: .03em; text-transform: none;
}
.powered-by-logo { height: 20px; width: auto; display: block; }

.logout-form { margin: 0; }
.link-button {
    background: none; border: none; color: var(--spoto-primary); cursor: pointer;
    padding: 0; font-size: .88rem; font-weight: 600; font-family: inherit;
}
.link-button:hover { text-decoration: underline; }

/* ---- Body / sidebar ---- */
.app-body { display: flex; flex: 1; min-height: 0; }

.sidebar {
    /* Size to the longest link's text plus its padding, not a fixed width — this
       gives the freed horizontal space back to the content/table area. */
    width: max-content; flex-shrink: 0; background: #fff; border-right: 1px solid var(--spoto-border);
    padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem;
}
.side-link {
    display: flex; align-items: center; padding: .6rem .9rem; border-radius: 8px;
    color: var(--spoto-text); font-weight: 500; font-size: .92rem; text-decoration: none;
    white-space: nowrap;
}
.side-link:hover { background: #f1f5fb; text-decoration: none; }
.side-link.active { background: #eef1fe; color: var(--spoto-primary); }
.side-link.active { box-shadow: inset 3px 0 0 var(--spoto-primary); }

/* ---- Content ---- */
.app-main { flex: 1; padding: 2rem 1.5rem; min-width: 0; }
/* Wide enough for the admin table to render fully when the viewport allows;
   narrower content (forms, landing) is capped by its own inner max-widths. */
.app-container { max-width: 1320px; margin: 0 auto; }
.card.narrow { max-width: 640px; margin-left: auto; margin-right: auto; }

/* ---- Landing ---- */
.landing { max-width: 520px; margin: 3.5rem auto; text-align: center; }
.landing .subtitle { color: var(--spoto-muted); margin-bottom: 1.75rem; }
.landing-actions { display: flex; gap: .75rem; justify-content: center; }

.card {
    background: #fff; border: 1px solid var(--spoto-border); border-radius: 10px;
    padding: 1.5rem; box-shadow: 0 1px 3px rgba(16,24,40,.05);
}

h1, h2, h3 { color: var(--uq-purple); letter-spacing: -.01em; }
h1 { font-size: 1.7rem; margin-top: 0; font-weight: 700; }

/* Blazor's <FocusOnNavigate Selector="h1"> focuses the page heading after every
   navigation (for screen-reader / keyboard users) by giving it tabindex="-1".
   That triggers a visible focus ring on page load. Since a tabindex="-1" element
   can only be focused programmatically — the Tab key never reaches it — hiding the
   ring costs nothing for keyboard navigation while removing the stray box. */
h1:focus { outline: none; }

/* ---- Forms ---- */
.form-row { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .3rem; max-width: 480px; }
.form-row label { font-weight: 500; font-size: .9rem; }
.form-row input, .form-row textarea, .form-row select {
    padding: .55rem .7rem; border: 1px solid var(--spoto-border); border-radius: 7px; font-size: .95rem;
    background: #fff; font-family: inherit; color: var(--spoto-text);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-row input:focus, .form-row textarea:focus, .form-row select:focus {
    outline: none; border-color: var(--spoto-primary);
    box-shadow: 0 0 0 3px rgba(79,110,247,.15);
}
.form-row input[readonly] { background: #f6f7fb; color: var(--spoto-muted); }
.form-row .hint { color: var(--spoto-muted); font-size: .8rem; }
.validation-message { color: #dc2626; font-size: .8rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
    padding: .6rem 1.4rem; border-radius: 999px; border: 1px solid transparent;
    font-size: .9rem; cursor: pointer; font-weight: 600; line-height: 1.2;
    font-family: inherit;
    white-space: nowrap; transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .05s ease;
}
.btn:hover { box-shadow: 0 4px 12px rgba(79,110,247,.22); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--spoto-primary); color: #fff; }
.btn-primary:hover { background: var(--spoto-primary-dark); text-decoration: none; color: #fff; }
.btn-outline { background: #fff; border-color: #d6dae6; color: var(--spoto-text); }
.btn-outline:hover { border-color: var(--spoto-primary); color: var(--spoto-primary); box-shadow: none; }
.btn-success { background: #16a34a; color: #fff; }
.btn-danger { background: #fff; border-color: #fecaca; color: #dc2626; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Home choices ---- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.choice { display: block; padding: 1.3rem; border: 1px solid var(--spoto-border); border-radius: 10px; background: #fff; }
.choice:hover { border-color: var(--spoto-primary); text-decoration: none; box-shadow: 0 2px 8px rgba(16,24,40,.06); }
.choice h3 { margin: 0 0 .4rem; color: var(--spoto-text); }
.choice p { margin: 0; color: var(--spoto-muted); font-size: .9rem; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: .5rem; border-bottom: 1px solid var(--spoto-border); margin-bottom: 1rem; }
.tab { padding: .6rem 1rem; cursor: pointer; border: none; background: none; color: var(--spoto-muted); font-weight: 500; border-bottom: 2px solid transparent; }
.tab.active { color: var(--spoto-primary); border-bottom-color: var(--spoto-primary); }

/* ---- Table ---- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--spoto-border); border-radius: 10px; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
table.grid th, table.grid td { text-align: center; padding: .7rem .8rem; border-bottom: 1px solid var(--spoto-border); font-size: .9rem; vertical-align: top; }
table.grid thead th { color: var(--spoto-muted); font-weight: 600; background: #fafbfd; white-space: nowrap; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: #fafbff; }
table.grid td.nowrap { white-space: nowrap; }
table.grid td.comment-cell { max-width: 240px; color: var(--spoto-muted); }
/* Clamp long comments to a few lines with an ellipsis; full text shown via the title tooltip. */
.comment-cell .clamp {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
    overflow: hidden; word-break: break-word; cursor: help;
}
.submitted-date, .submitted-time { display: block; line-height: 1.2; }
.submitted-date + br { display: none; }
.submitted-time { margin-top: 0; }

/* ---- Admin list controls (status filter + group selector above the table) ---- */
.list-controls {
    display: flex; align-items: flex-end; justify-content: space-between;
    flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem;
}
.list-controls .form-row { margin-bottom: 0; }
.list-controls .group-control { margin-left: auto; }

/* ---- Admin row actions ---- */
.actions-cell { min-width: 220px; }
.action-controls { display: flex; flex-direction: column; gap: .5rem; align-items: stretch; max-width: 240px; margin: 0 auto; }
.action-group { width: 100%; cursor: pointer; text-align: center; text-align-last: center; }
.action-group option { cursor: pointer; text-align: center; }
.action-buttons { display: flex; gap: .5rem; }
.action-buttons .btn { flex: 1 1 0; }   /* Approve / Reject stay equal width and undistorted */
.btn-sm { padding: .4rem .8rem; font-size: .85rem; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fee2e2; color: #b91c1c; }

/* ---- Pager ---- */
.pager { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; }

/* ---- Alerts ---- */
.alert { padding: .8rem 1rem; border-radius: 8px; margin: 1rem 0; font-size: .9rem; }
.alert-info { background: #eff6ff; color: #1e40af; }
.alert-warn { background: #fffbeb; color: #92400e; }
.alert-error { background: #fef2f2; color: #991b1b; }
.alert-success { background: #f0fdf4; color: #166534; }

/* ---- Attachment list (admin view: name + preview/download icons) ---- */
.attach-list { list-style: none; margin: 0 auto; padding: 0; display: flex; flex-direction: column; gap: .4rem; min-width: 220px; }
.attach-item {
    display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    padding: .4rem .4rem .4rem .6rem; border: 1px solid var(--spoto-border); border-radius: 8px; background: #fff;
}
.attach-name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.attach-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
    border-radius: 7px; border: 1px solid var(--spoto-border); background: #fff; color: var(--spoto-muted);
    cursor: pointer; transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.icon-btn:hover { color: var(--spoto-primary); border-color: var(--spoto-primary); background: #f5f7ff; text-decoration: none; }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- Attachment previews (upload form: thumbnails of selected files) ---- */
.preview-grid { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .5rem; }
.preview-item { border: 1px solid var(--spoto-border); border-radius: 8px; padding: .5rem; width: 160px; background: #fff; }
.preview-item img { max-width: 100%; max-height: 110px; display: block; border-radius: 4px; }
.preview-item .name { font-size: .75rem; color: var(--spoto-muted); margin-top: .4rem; word-break: break-all; }

/* ---- Toast notifications ---- */
.app-toast-stack {
    position: fixed; top: 84px; right: 20px; z-index: 1100;
    display: flex; flex-direction: column; gap: .6rem; max-width: 360px;
}
.app-toast {
    display: flex; align-items: flex-start; gap: .75rem;
    padding: .75rem .9rem; border-radius: 10px; color: #fff; font-size: .9rem;
    box-shadow: 0 10px 28px rgba(16,24,40,.18); animation: toast-in .18s ease-out;
}
.app-toast-msg { flex: 1; line-height: 1.35; }
.app-toast-success { background: #16a34a; }
.app-toast-error   { background: #dc2626; }
.app-toast-info    { background: #334155; }
.app-toast-close {
    background: none; border: none; color: inherit; opacity: .8; cursor: pointer;
    font-size: 1.15rem; line-height: 1; padding: 0; margin-top: -1px;
}
.app-toast-close:hover { opacity: 1; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Blazor error UI (template default) ---- */
#blazor-error-ui {
    color-scheme: light only; background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ============================================================
   Responsive / mobile-friendly
   ============================================================ */

/* Tablet and below: collapse the sidebar into a horizontal top bar. */
@media (max-width: 860px) {
    .app-body { flex-direction: column; }
    .sidebar {
        width: 100%; flex-direction: row; flex-wrap: wrap; gap: .4rem;
        border-right: none; border-bottom: 1px solid var(--spoto-border);
        padding: .75rem 1rem; overflow-x: auto;
    }
    .side-link { padding: .5rem .9rem; white-space: nowrap; }
    .side-link.active { box-shadow: inset 0 -2px 0 var(--spoto-primary); border-radius: 8px 8px 0 0; }
    .app-main { padding: 1.5rem 1.1rem; }
}

/* Phones. */
@media (max-width: 560px) {
    .app-header { padding: 0 1rem; height: 60px; }
    .brand-logo { height: 34px; }
    .powered-by-logo { height: 16px; }
    .powered-by-label { font-size: .6rem; }
    .header-right { gap: .6rem; }
    .signed-in { display: none; }            /* keep the header uncluttered on phones */
    .header-divider { display: none; }

    .app-main { padding: 1.1rem .9rem; }
    .card { padding: 1.1rem; border-radius: 10px; }
    h1 { font-size: 1.4rem; }

    .form-row { max-width: none; }           /* inputs span full width on phones */
    .landing { margin: 2.5rem auto; }
    .landing-actions { flex-direction: column; }
    .landing-actions .btn { width: 100%; }

    .choice-grid { grid-template-columns: 1fr; }
    .pager { flex-direction: column; align-items: stretch; text-align: center; }

    .tabs { overflow-x: auto; flex-wrap: nowrap; }
    .tab { white-space: nowrap; }

    .app-toast-stack { top: auto; bottom: 16px; left: 12px; right: 12px; max-width: none; }
}
