/* IoT Workshop - admin panel. */

:root {
    --page-bg: #f7f8fa;
    --surface: #ffffff;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --text: #101828;
    --text-muted: #475467;
    --text-soft: #667085;
    --blue: #1a5fbf;
    --blue-dark: #17539f;
    --green: #12855b;
    --green-bg: #a9e8b8;
    --red: #b42318;
    --red-bg: #fdd9d5;
    --grey-bg: #e4e7ec;
}

* { box-sizing: border-box; }

body.admin-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--page-bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Header */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 68px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--blue);
}

/* One brand size across the whole product: these numbers are mirrored by
   .brand / .brand-mark in auth.css, which the sign-in and sign-up pages use. */
.brand-mark {
    width: 22px; height: 22px;
    /* A flex item in the brand row: without this it is squeezed out of
       square when the header gets tight on a small phone. */
    flex: none;
    border-radius: 6px;
    background: var(--blue);
    box-shadow: 7px 7px 0 -1px rgba(26, 95, 191, 0.35);
}

.brand-text { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

.brand-admin {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-left: 4px;
}

.topbar-nav { display: flex; align-items: center; gap: 22px; }

.topnav-link {
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    padding: 4px 0;
}

.topnav-link:hover { color: var(--text); }

.topnav-link.is-current {
    color: var(--blue);
    font-weight: 600;
    border-bottom: 2px solid var(--blue);
}

.icon-button {
    display: inline-flex;
    padding: 6px;
    background: none;
    border: 0;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
}

.icon-button:hover { background: #f2f4f7; }

.icon-button svg, .nav-toggle svg {
    width: 22px; height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Carries the signed-in user's initials, so it centres its text. */
.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--blue);
    border: 0;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    /* Two details keep the initials on the centre of the circle: no
       letter-spacing, whose trailing space after the last letter would be
       counted by the centring and push the text left; and a line box of an
       even height inside the 32px content area, which centres without
       rounding the half pixel to one side. */
    line-height: 16px;
    color: #fff;
    text-decoration: none;
}

.avatar-sm {
    width: 30px; height: 30px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: var(--blue);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-toggle {
    display: none;
    padding: 6px;
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
}

/* Shell */
.admin-shell { display: flex; flex: 1; align-items: stretch; }

.sidebar {
    width: 290px;
    flex: none;
    padding: 26px 20px;
    background: var(--page-bg);
    border-right: 1px solid var(--border);
}

.sidenav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    margin-bottom: 6px;
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 500;
    text-decoration: none;
}

.sidenav-link:hover { background: #eef0f4; color: var(--text); }

.sidenav-link.is-active {
    background: var(--blue);
    color: #fff;
    font-weight: 600;
}

.sidenav-icon {
    width: 21px; height: 21px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.admin-main { flex: 1; min-width: 0; padding: 34px 40px 48px; }

/* Titles */
.page-title {
    margin: 0 0 6px;
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.page-subtitle {
    margin: 0 0 26px;
    color: var(--text-muted);
    font-size: 16px;
}

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 18px;
    margin: 22px 0 30px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px 20px;
}

.stat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.stat-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-icon {
    width: 20px; height: 20px;
    fill: none;
    stroke: var(--blue);
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* One stat size across the product: the admin dashboard tiles and the Project
   visualization cards read the same. */
.stat-value {
    margin: 0 0 8px;
    font-size: 27px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.stat-note { margin: 0; font-size: 14px; color: var(--text-soft); }

/* Panels and tables */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
}

.panel-title { margin: 0; font-size: 19px; font-weight: 700; }

.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
    padding: 14px 22px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 16px 22px;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: 0; }

.col-right { text-align: right; }

.cell-user { display: flex; align-items: center; gap: 12px; }

.user-name { font-weight: 600; }

.cell-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; color: var(--text-muted); }

.state-row td {
    padding: 34px 22px;
    text-align: center;
    color: var(--text-soft);
    font-size: 15px;
}

.panel-foot {
    padding: 16px 22px;
    text-align: center;
    border-top: 1px solid var(--border);
}

.table-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    text-align: left;
    flex-wrap: wrap;
}

.result-count { margin: 0; font-size: 15px; color: var(--text-muted); }

.pagination { display: flex; gap: 8px; }

.page-btn {
    min-width: 40px;
    padding: 8px 12px;
    font: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    cursor: pointer;
}

.page-btn.is-current { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.page-btn[disabled] { color: var(--text-soft); background: #f9fafb; cursor: not-allowed; }

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    background: var(--grey-bg);
    color: var(--text-muted);
}

.badge-active { background: var(--green-bg); color: var(--green); }
.badge-suspended { background: var(--red-bg); color: var(--red); }

/* Filters */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.search { position: relative; flex: 1 1 320px; max-width: 500px; }

.search-icon {
    position: absolute;
    top: 50%; left: 12px;
    transform: translateY(-50%);
    width: 18px; height: 18px;
    fill: none;
    stroke: var(--text-soft);
    stroke-width: 1.8;
    stroke-linecap: round;
    /* Clicking the icon focuses the field under it. */
    pointer-events: none;
}

/* Scoped to .search so it outweighs the padding shorthand on .input below;
   without that the text starts under the icon. */
.search .search-input { padding-left: 40px; }

.filters { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

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

.filter-label { font-size: 14px; color: var(--text-muted); }

.input, .select {
    width: 100%;
    padding: 11px 13px;
    font: inherit;
    font-size: 15px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    outline: none;
}

/* The native arrow sits hard against the border, so the control draws its own
   chevron and insets it from the right edge. */
.select {
    width: auto;
    padding-right: 38px;
    appearance: none;
    -webkit-appearance: none;
    /* A served file, not a data: URI - the Content-Security-Policy is
       default-src 'self', which blocks data: images. */
    background-color: var(--surface);
    background-image: url("../icons/select-chevron.svg");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 14px 14px;
}

.input:focus, .select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 95, 191, 0.12);
}

/* Limits form */
.panel-form { padding: 34px 38px; max-width: 1100px; }

/* Every field inside a form panel stands apart from the next, so a label never
   sits flush against the control above it. Declared once here, in the base
   stylesheet both layouts load, rather than per form. */
.panel-form .field { margin-bottom: 22px; }

.label {
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
    font-weight: 700;
}

.input-suffix { position: relative; }

.input-suffix .input { background: #f9fafb; padding-right: 150px; }

.suffix {
    position: absolute;
    top: 50%; right: 14px;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--text-soft);
    pointer-events: none;
}

.field-help { margin: 8px 0 0; font-size: 14px; color: var(--text-muted); }

.divider { margin: 26px 0; border: 0; border-top: 1px solid var(--border); }

/* Workshop access toggle. One control, one tap, readable across a room. */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f9fafb;
}

.switch-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.switch-title { font-size: 16px; font-weight: 700; }
.switch-note { font-size: 14px; color: var(--text-muted); }

.switch {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.switch-track {
    position: relative;
    width: 62px;
    height: 34px;
    border-radius: 999px;
    background: var(--border-strong);
    transition: background 0.15s ease;
}

.switch-thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.3);
    transition: transform 0.15s ease;
}

.switch[aria-checked="true"] .switch-track { background: var(--green); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(28px); }

.switch-value {
    min-width: 42px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--red);
}

.switch[aria-checked="true"] .switch-value { color: var(--green); }
.switch:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 8px; }
.switch[disabled] { opacity: 0.65; cursor: not-allowed; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 13px 22px;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}

.btn-admin { background: var(--blue-dark); color: #fff; }
.btn-admin:hover { background: #124283; }
.btn[disabled] { opacity: 0.65; cursor: not-allowed; }

.alert {
    margin-bottom: 20px;
    padding: 12px 14px;
    font-size: 14px;
    border: 1px solid transparent;
    border-radius: 8px;
}

.alert-error { color: var(--red); background: #fef3f2; border-color: #fecdca; }
.alert-success { color: var(--green); background: #ecfdf3; border-color: #abefc6; }

.link { color: var(--blue); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Footer */
.admin-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 28px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 14px;
    flex-wrap: wrap;
}

.footer-copy { margin-left: 10px; color: var(--green); }

.footer-right { display: flex; align-items: center; gap: 14px; }

.footer-right a { color: var(--text-muted); font-weight: 600; text-decoration: none; }
.footer-right a:hover { color: var(--text); }

.dot { width: 4px; height: 4px; border-radius: 50%; background: var(--border-strong); }

/* Responsive */
@media (max-width: 980px) {
    .topbar { padding: 0 16px; }
    .nav-toggle { display: inline-flex; order: 3; }
    .topbar-nav { gap: 14px; }
    .topnav-link { display: none; }
    .admin-shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        display: none;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        padding: 14px 16px;
    }

    .sidebar.is-open { display: block; }
    .admin-main { padding: 24px 16px 36px; }
    .page-title { font-size: 30px; }
    .panel-form { padding: 22px 18px; }
    .switch-row { align-items: flex-start; }
    .input-suffix .input { padding-right: 120px; }
}

@media (max-width: 720px) {
    .brand-admin { font-size: 21px; }
    .stat-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
    .panel { overflow-x: auto; }
    .data-table { min-width: 720px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .search { max-width: none; }
}

/* Admin login */
.admin-shell-plain { justify-content: center; }

.login-main {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.login-card {
    width: 100%;
    max-width: 460px;
    padding: 38px 36px 34px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.login-title { font-size: 30px; }

.btn-block { width: 100%; }

/* Row actions */
.row-actions { position: relative; display: inline-block; }

.actions-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 20;
    min-width: 170px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
}

.menu-item {
    display: block;
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    text-align: left;
    background: none;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

.menu-item:hover { background: #f2f4f7; }
.menu-item[disabled] { color: var(--text-soft); cursor: not-allowed; background: none; }

/* Detail modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(16, 24, 40, 0.45);
}

.modal[hidden] { display: none; }

.modal-card {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border-radius: 10px;
    overflow: hidden;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 22px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
}

.detail-list { margin: 0; padding: 20px 22px; }

.detail-list div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}

.detail-list div:last-child { border-bottom: 0; }

.detail-list dt { color: var(--text-muted); font-size: 14px; }
.detail-list dd { margin: 0; font-size: 14px; font-weight: 600; text-align: right; }

.table-alert { margin: 0; padding: 12px 22px; border-bottom: 1px solid var(--border); }

.field-error { margin: 8px 0 0; font-size: 13px; color: var(--red); }
.input.has-error { border-color: var(--red); }

/* Admin login extras */
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; color: var(--blue); }

.input-group { position: relative; }
.input-group .input { padding-right: 46px; }

.toggle-password {
    position: absolute;
    top: 50%; right: 8px;
    transform: translateY(-50%);
    display: flex;
    padding: 6px;
    background: none;
    border: 0;
    border-radius: 6px;
    color: var(--text-soft);
    cursor: pointer;
}

.toggle-password svg {
    width: 20px; height: 20px;
    fill: none; stroke: currentColor;
    stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

.toggle-password .eye-slash { display: none; }
.toggle-password[aria-pressed="true"] .eye-slash { display: block; }

.login-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 4px 0 20px;
    font-size: 15px;
}

.checkbox.is-disabled, .link.is-disabled { color: var(--text-soft); cursor: default; }
.checkbox.is-disabled input { cursor: default; }
.link.is-disabled:hover { text-decoration: none; }

@media (max-width: 560px) {
    .login-row { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* Dashboard activity pager. Sits in the existing panel foot: the count on the
   left, the two controls on the right, stacked on a narrow screen. */
.activity-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    text-align: left;
}

.activity-count { margin: 0; font-size: 14px; color: var(--text-muted); }
.activity-pager { display: flex; gap: 8px; }
.activity-pager .btn { width: auto; }

@media (max-width: 560px) {
    .activity-foot { justify-content: center; text-align: center; }
    .activity-pager { width: 100%; justify-content: center; }
}

/* ---------------------------------------------------------------------------
   Mobile responsiveness.

   Two rules carry most of it: a table scrolls inside its own container rather
   than widening the page, and the header shrinks its brand before it runs out
   of room. Desktop is untouched - every rule below is either a wrapper with no
   effect at full width, or inside a small-screen media query.
   --------------------------------------------------------------------------- */

/* A table sits in a horizontal scroller. At desktop width the table is
   narrower than the container, so nothing scrolls and nothing changes. */
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Below this the columns would be unreadable, so the container scrolls. */
.table-scroll .data-table { min-width: 620px; }

/* The Projects table carries an icon, a name and a description, so it needs
   a little more before it starts scrolling. */
.table-scroll .project-table { min-width: 680px; }

@media (max-width: 640px) {
    /* Tighter cells, so less of the table is off-screen at any moment. */
    .table-scroll .data-table th,
    .table-scroll .data-table td { padding-left: 16px; padding-right: 16px; }
}

/* The header runs out of room before the content does: the brand, the icon
   controls and the drawer toggle together need more than a small phone has.
   Scale the brand down rather than dropping anything the user needs. */
@media (max-width: 420px) {
    .topbar { padding: 0 12px; gap: 10px; }
    .topbar-brand { gap: 8px; min-width: 0; }

    /* The brand keeps its full size here. It used to scale down for room
       the header no longer needs - measured at 320px there is still more
       than 70px of clear space between the brand and the controls - and
       shrinking it made the logo smaller than the one on the sign-in
       pages, which never scaled. One brand size everywhere. */

    .brand-admin { font-size: 19px; margin-left: 2px; }

    .topbar-nav { gap: 6px; }
    .icon-button { padding: 5px; }
    .icon-button svg, .nav-toggle svg { width: 20px; height: 20px; }
    .avatar { width: 30px; height: 30px; font-size: 12px; line-height: 14px; }
    .nav-toggle { padding: 5px; }

    /* Page furniture follows the same tightening. */
    .admin-main { padding: 22px 14px 34px; }
    .page-title { font-size: 27px; }
    .page-subtitle { font-size: 15px; }
    .panel-head { padding: 14px 16px; }
    .panel-foot { padding: 14px 16px; }
}

/* Very small phones: the bar tightens, but the brand still holds its size. */
@media (max-width: 340px) {
    .topbar { padding: 0 10px; }
}

/* Touch usability. The icon-only controls are 20-30px, which is fine for a
   mouse and small for a finger. The hit area is expanded with a pseudo-element
   rather than by resizing the control: the visual stays identical, the layout
   does not move, and nothing here applies to a mouse. */
@media (pointer: coarse) {
    .icon-button,
    .copy-button,
    .nav-toggle,
    .toggle-password { position: relative; }

    .icon-button::after,
    .copy-button::after,
    .nav-toggle::after,
    .toggle-password::after {
        content: "";
        position: absolute;
        top: 50%; left: 50%;
        width: 44px; height: 44px;
        transform: translate(-50%, -50%);
    }

    /* A checkbox row is tapped by its label, so the row carries the height. */
    .checkbox { min-height: 32px; }
}

@media (max-width: 560px) {
    /* Footer: name and links stack instead of competing for one line. */
    .admin-footer { flex-direction: column; align-items: flex-start; gap: 10px; padding: 18px 16px; }
    .admin-footer .footer-right { flex-wrap: wrap; gap: 12px 16px; }

    /* Modal: less gutter, and the actions go full width so both are easy to
       hit. The body already scrolls internally. */
    .modal { padding: 12px; }
    .modal-card { max-height: calc(100vh - 24px); display: flex; flex-direction: column; }
    .modal-body { max-height: none; flex: 1; }
    .modal-foot { flex-direction: column-reverse; align-items: stretch; }
    .modal-foot .btn { width: 100%; }
}
