:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #17202a;
    --muted: #667085;
    --line: #d8dee6;
    --line-soft: #e8edf3;
    --primary: #0b6bcb;
    --primary-dark: #084f96;
    --primary-soft: #e8f2ff;
    --danger: #b42318;
    --ok: #067647;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: var(--primary);
}

a:hover {
    color: var(--primary-dark);
}

:focus-visible {
    outline: 3px solid rgba(11, 107, 203, 0.28);
    outline-offset: 2px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: #111827;
    color: #fff;
    box-shadow: 0 12px 28px rgba(17, 24, 39, 0.18);
}

.admin-frame {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 20px 16px;
    background: #111827;
    color: #fff;
    box-shadow: 12px 0 28px rgba(17, 24, 39, 0.12);
}

.sidebar-brand {
    padding: 4px 8px 14px;
    font-size: 18px;
    font-weight: 800;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-nav {
    display: grid;
    gap: 6px;
    align-items: stretch;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    min-height: 40px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
    font-weight: 700;
    white-space: nowrap;
}

.nav {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.nav a {
    color: #dbeafe;
    text-decoration: none;
    border-radius: 6px;
    padding: 7px 9px;
    font-size: 14px;
    font-weight: 700;
    transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.nav a:hover,
.nav a:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.nav a[aria-current="page"] {
    background: #fff;
    color: #111827;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.36);
}

.sidebar .nav {
    display: grid;
    gap: 6px;
    align-items: stretch;
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 24px auto 48px;
}

.admin-shell {
    width: calc(100% - 48px);
    max-width: none;
    margin: 28px 24px 56px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.page-header .button {
    flex: 0 0 auto;
}

.page-header h1 {
    margin: 0;
}

.grid {
    display: grid;
    gap: 16px;
}

.stats {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat,
.panel,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.stat strong {
    display: block;
    font-size: 30px;
    line-height: 1.05;
}

.muted {
    color: var(--muted);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.direct-link {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.direct-link code,
.direct-link .direct-link-text {
    flex: 1;
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--muted);
    font-size: 13px;
}

.copy-button {
    position: relative;
    flex: 0 0 auto;
    width: 38px;
    min-height: 34px;
    padding: 0;
}

.copy-button::before,
.copy-button::after {
    content: "";
    position: absolute;
    border: 2px solid currentColor;
    border-radius: 3px;
    width: 13px;
    height: 15px;
}

.copy-button::before {
    left: 11px;
    top: 11px;
    background: #fff;
}

.copy-button::after {
    left: 15px;
    top: 7px;
    background: #fff;
}

.copy-button.copied {
    border-color: var(--ok);
    color: var(--ok);
}

.copy-button.compact {
    width: 30px;
    min-height: 28px;
}

.copy-button.compact::before {
    left: 8px;
    top: 9px;
    width: 10px;
    height: 12px;
}

.copy-button.compact::after {
    left: 11px;
    top: 5px;
    width: 10px;
    height: 12px;
}

.inline-copy {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.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;
}

.app-identity {
    display: flex;
    gap: 12px;
    align-items: center;
}

.app-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 8px;
    border: 1px solid var(--line);
    object-fit: cover;
    background: #eef2f7;
}

.app-icon.placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-weight: 700;
    font-size: 11px;
    overflow: hidden;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) minmax(180px, 220px);
    gap: 12px;
    margin-bottom: 16px;
}

.assignment-board {
    display: grid;
    gap: 18px;
}

.assignment-group-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.assignment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 560px));
    gap: 12px;
    justify-content: start;
}

.assignment-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #fff;
    display: grid;
    gap: 10px;
    width: 100%;
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.assignment-card:hover {
    border-color: #b9c7d8;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.split {
    display: grid;
    grid-template-columns: minmax(260px, 360px) 1fr;
    gap: 20px;
    align-items: start;
}

.form-panel {
    max-width: 760px;
}

.email-compose-panel {
    max-width: min(1280px, 100%);
}

.email-compose-panel form {
    max-width: 1120px;
}

.email-body {
    min-height: 440px;
    line-height: 1.55;
    resize: vertical;
    white-space: pre-wrap;
}

.email-log-body {
    max-width: 520px;
    max-height: 180px;
    overflow: auto;
    margin: 0;
    white-space: pre-wrap;
    font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

table[data-grid] {
    font-size: 14px;
}

th,
td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    vertical-align: top;
}

th {
    background: #eef2f7;
    font-size: 13px;
    color: #344054;
    position: relative;
}

.grid-sort {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 800;
    justify-content: flex-start;
    width: 100%;
    cursor: pointer;
    transition: color 140ms ease;
}

.grid-sort:hover {
    color: var(--primary);
}

th[data-sort-dir="asc"] .grid-sort::after {
    content: " ↑";
    color: var(--primary);
    font-size: 11px;
}

th[data-sort-dir="desc"] .grid-sort::after {
    content: " ↓";
    color: var(--primary);
    font-size: 11px;
}

.grid-filters th {
    background: #f8fafc;
    padding: 6px 8px;
}

.grid-filter {
    min-height: 32px;
    padding: 6px 8px;
    font-size: 13px;
}

tbody tr {
    transition: background 120ms ease;
}

tbody tr:hover td {
    background: #f8fafc;
}

tr:last-child td {
    border-bottom: 0;
}

form.stack,
.stack {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    font: inherit;
    background: #fff;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:hover,
select:hover,
textarea:hover {
    border-color: #b9c7d8;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(11, 107, 203, 0.14);
    outline: none;
}

.checkbox-label {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 8px;
}

.checkbox-label input {
    width: auto;
}

textarea {
    min-height: 90px;
}

.android-import {
    display: grid;
    gap: 10px;
}

.android-dropzone {
    border: 1px dashed #9fb2c8;
    border-radius: 8px;
    background: #f8fafc;
    color: #52637a;
    padding: 18px;
    text-align: center;
    font-weight: 700;
    transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.android-dropzone.dragover {
    border-color: var(--primary);
    background: #eef6ff;
    color: var(--primary);
    box-shadow: 0 0 0 3px rgba(11, 107, 203, 0.12);
}

.android-import-preview {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.android-import-preview[hidden] {
    display: none;
}

.android-import-preview .app-icon {
    flex: 0 0 auto;
}

.android-missing {
    margin: 6px 0 0;
    padding-left: 18px;
    color: #52637a;
    font-size: 13px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    min-height: 40px;
    padding: 9px 13px;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.button:hover,
button:hover {
    border-color: #b9c7d8;
    background: #f8fafc;
    color: var(--ink);
}

.button:active,
button:active {
    transform: translateY(1px);
}

.button.primary,
button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button.primary:hover,
button.primary:hover {
    border-color: var(--primary-dark);
    background: var(--primary-dark);
    color: #fff;
}

.button.danger,
button.danger {
    color: var(--danger);
}

.button.danger:hover,
button.danger:hover {
    border-color: #fecdca;
    background: #fef3f2;
    color: var(--danger);
}

.flash {
    margin-bottom: 16px;
    border-radius: 8px;
    padding: 12px 14px;
    background: #eff8ff;
    border: 1px solid #b2ddff;
}

.flash.error {
    background: #fef3f2;
    border-color: #fecdca;
    color: var(--danger);
}

.flash.success {
    background: #ecfdf3;
    border-color: #abefc6;
    color: var(--ok);
}

.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.auth-shell {
    width: min(440px, calc(100% - 32px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 26px;
    box-shadow: var(--shadow);
}

.setup-shell {
    width: min(720px, calc(100% - 32px));
    margin: 32px 0;
}

.portal-header {
    background: #111827;
    color: #fff;
    padding: 28px 24px;
}

.portal-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.portal-topline p {
    margin: 0;
}

.portal-nav {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    align-items: center;
    margin-left: auto;
}

.portal-nav a {
    color: #dbeafe;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    transition: background 140ms ease, color 140ms ease;
}

.portal-nav a:hover,
.portal-nav a:focus-visible,
.portal-nav a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.portal-header .inner,
.portal-main {
    width: min(960px, calc(100% - 32px));
    margin: 0 auto;
}

.portal-main {
    padding: 24px 0 48px;
}

.app-card {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: stretch;
    min-height: 240px;
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.app-card:hover {
    border-color: #b9c7d8;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.app-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    align-items: stretch;
}

.app-card-main,
.app-card-actions {
    display: grid;
    gap: 12px;
}

.app-card-main {
    align-content: start;
    min-width: 0;
}

.app-card-actions {
    align-items: center;
    grid-template-columns: minmax(0, 1fr) auto;
    margin-top: auto;
}

.app-card .button {
    width: 100%;
}

.app-card-actions .direct-link {
    margin: 0;
}

.app-identity h2 {
    margin: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.app-meta span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 10px;
    color: #344054;
    background: #f8fafc;
    font-size: 13px;
    font-weight: 700;
}

.app-meta .status {
    border-color: transparent;
}

.app-notes {
    margin: 0;
    color: var(--muted);
    min-height: 22px;
}

.mono {
    font-family: Menlo, Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
}

.status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 700;
    background: #eef2f7;
    color: #344054;
}

.status.installed {
    background: #ecfdf3;
    color: #067647;
}

.status.update_available {
    background: #fffaeb;
    color: #b54708;
}

.status.not_installed {
    background: #fef3f2;
    color: #b42318;
}

@media (max-width: 780px) {
    .topbar,
    .split {
        display: grid;
        grid-template-columns: 1fr;
    }

    .admin-frame {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .sidebar-nav {
        grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    }

    .shell {
        width: min(100% - 20px, 1180px);
        margin-top: 14px;
    }

    .admin-shell {
        width: min(100% - 20px, 1180px);
        margin: 14px auto 40px;
    }

    .portal-topline {
        display: grid;
        grid-template-columns: 1fr;
    }

    .portal-nav {
        justify-content: flex-start;
        flex-wrap: wrap;
        margin-left: 0;
    }

    .page-header {
        align-items: stretch;
        display: grid;
        grid-template-columns: 1fr;
    }

    table {
        display: block;
        overflow-x: auto;
    }
}

@media (max-width: 820px) {
    .toolbar,
    .app-grid {
        grid-template-columns: 1fr;
    }

    .app-card-actions {
        grid-template-columns: minmax(0, 1fr) auto;
    }
}
