:root {
    --nion-blue: #1f6eb4;
    --nion-blue-dark: #0f477a;
    --nion-green: #37d98b;
    --nion-green-dark: #24a974;
    --ink: #172033;
    --muted: #667085;
    --line: #d9e2ec;
    --surface: #ffffff;
    --soft: #f5f8fb;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --success: #067647;
    --success-soft: #ecfdf3;
    --shadow: 0 16px 40px rgba(23, 32, 51, .10);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    background: var(--soft);
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

img {
    display: block;
    max-width: 100%;
}

button,
input,
textarea,
select {
    font: inherit;
}

.site-header {
    order: 0;
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 72px;
    padding: 12px clamp(16px, 4vw, 44px);
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

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

.brand-icon {
    width: 42px;
    height: 46px;
    object-fit: contain;
}

.brand strong,
.brand .app-version {
    display: block;
    line-height: 1;
}

.brand strong {
    font-size: 18px;
}

.brand strong + strong {
    margin-top: 4px;
    color: var(--nion-green-dark);
}

.app-version {
    margin-top: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.main-nav a,
.install-button {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    text-decoration: none;
    font-weight: 700;
}

.main-nav a:hover,
.main-nav .is-active,
.install-button:hover {
    color: var(--nion-blue-dark);
    background: #eaf4ff;
}

.install-button {
    color: #fff;
    background: var(--nion-green-dark);
}

.install-button:hover {
    color: #fff;
    background: #1c8f63;
}

.is-hidden {
    display: none !important;
}

.install-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(23, 32, 51, .48);
}

.install-modal-panel {
    width: min(420px, 100%);
    padding: 22px;
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.install-modal-panel h2 {
    margin: 0 0 10px;
    font-size: 22px;
}

.install-modal-panel p {
    margin: 0 0 12px;
    color: var(--muted);
    line-height: 1.45;
}

.install-steps {
    margin: 0 0 18px;
    padding-left: 20px;
    line-height: 1.55;
}

.page-shell {
    order: 1;
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 30px 0 28px;
}

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

.page-head h1,
.login-panel h1 {
    margin: 0;
    font-size: 32px;
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--nion-green-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.primary-button,
.ghost-button,
.danger-button,
.send-button,
.icon-button,
.search-bar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 800;
    white-space: nowrap;
}

.primary-button,
.send-button {
    color: #fff;
    background: var(--nion-blue);
    box-shadow: 0 10px 24px rgba(31, 110, 180, .18);
}

.primary-button:hover,
.send-button:hover {
    background: var(--nion-blue-dark);
}

.ghost-button,
.search-bar button {
    color: var(--nion-blue-dark);
    background: #fff;
    border-color: var(--line);
}

.ghost-button:hover,
.search-bar button:hover {
    border-color: var(--nion-blue);
}

.danger-button {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: #ffd3cf;
}

.danger-button:hover {
    background: #ffe4e1;
}

.alert {
    margin-bottom: 18px;
    padding: 13px 15px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

.alert-error {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: #ffd3cf;
}

.alert-success {
    color: var(--success);
    background: var(--success-soft);
    border-color: #abefc6;
}

.search-bar {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    margin-bottom: 22px;
}

.search-bar input,
.report-filters input,
.report-filters select,
.stack-form input,
.form-panel input,
.form-panel textarea,
.form-panel select,
.user-row input,
.user-row select,
.chat-form input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
}

.form-panel textarea {
    resize: vertical;
}

.search-bar input:focus,
.report-filters input:focus,
.report-filters select:focus,
.stack-form input:focus,
.form-panel input:focus,
.form-panel textarea:focus,
.form-panel select:focus,
.user-row input:focus,
.user-row select:focus,
.chat-form input:focus {
    outline: 3px solid rgba(55, 217, 139, .24);
    border-color: var(--nion-green-dark);
}

.item-list {
    display: grid;
    gap: 10px;
}

.item-row {
    display: grid;
    grid-template-columns: 74px minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    min-height: 98px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 26px rgba(23, 32, 51, .06);
}

.item-photo {
    display: grid;
    place-items: center;
    width: 74px;
    height: 74px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, #f8fbfd, #eef8f3);
}

.item-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.item-photo .placeholder-logo {
    width: 38px;
    height: 42px;
    object-fit: contain;
    opacity: .72;
}

.photo-preview .placeholder-logo {
    width: 86px;
    height: 92px;
    object-fit: contain;
    opacity: .72;
}

.item-body {
    padding: 0;
    min-width: 0;
}

.item-body h2 {
    margin: 0 0 6px;
    font-size: 18px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.location {
    margin: 0;
    color: var(--nion-blue-dark);
    font-weight: 800;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.notes {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.item-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 0;
}

.item-actions form {
    margin: 0;
}

.empty-state {
    padding: 34px;
    text-align: center;
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.empty-state h2 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0 0 18px;
    color: var(--muted);
}

.empty-state-small {
    padding: 22px;
    text-align: left;
}

.empty-state-small h2 {
    font-size: 18px;
}

.report-filters {
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 26px rgba(23, 32, 51, .06);
}

.report-filter-grid {
    display: grid;
    grid-template-columns: 170px minmax(180px, 1fr) minmax(170px, .8fr) 170px minmax(180px, 1fr);
    gap: 12px;
    align-items: end;
}

.report-filters label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.report-actions {
    justify-content: flex-end;
}

.report-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.report-stat {
    display: grid;
    gap: 7px;
    min-height: 96px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 26px rgba(23, 32, 51, .06);
}

.report-stat span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.report-stat strong {
    color: var(--nion-blue-dark);
    font-size: 34px;
    line-height: 1;
}

.report-section {
    display: grid;
    gap: 12px;
    margin-top: 20px;
}

.report-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.report-section-head h2 {
    margin: 0;
    font-size: 22px;
}

.report-section-head span {
    color: var(--muted);
    font-weight: 800;
}

.report-group {
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 26px rgba(23, 32, 51, .06);
}

.report-group summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 50px;
    padding: 0 16px;
    cursor: pointer;
    color: var(--nion-blue-dark);
    font-weight: 900;
    overflow-wrap: anywhere;
}

.report-group summary strong {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 26px;
    padding: 0 8px;
    border-radius: 999px;
    color: #fff;
    background: var(--nion-blue);
    font-size: 13px;
}

.report-table-wrap {
    overflow-x: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.report-group .report-table-wrap {
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 0;
}

.report-table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
}

.report-table th,
.report-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    line-height: 1.35;
}

.report-table th {
    color: var(--muted);
    background: #f8fbfd;
    font-size: 12px;
    text-transform: uppercase;
}

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

.report-table td small,
.report-item-cell small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.report-item-cell {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-width: 240px;
}

.report-item-cell a {
    color: var(--ink);
    font-weight: 900;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.report-item-cell a:hover {
    color: var(--nion-blue-dark);
    text-decoration: underline;
}

.report-thumb {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, #f8fbfd, #eef8f3);
}

.report-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.report-thumb .placeholder-logo {
    width: 28px;
    height: 32px;
    object-fit: contain;
    opacity: .72;
}

.report-badges {
    min-width: 150px;
}

.report-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    margin: 0 5px 5px 0;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
}

.report-badge-info {
    color: var(--nion-blue-dark);
    background: #eaf4ff;
}

.report-badge-warning {
    color: #92400e;
    background: #fff7ed;
}

.report-badge-muted {
    color: #475467;
    background: #f2f4f7;
}

.editor-layout,
.user-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: start;
}

.form-panel,
.photo-panel,
.user-row,
.login-panel,
.assistant-inner {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 26px rgba(23, 32, 51, .06);
}

.form-panel,
.photo-panel,
.login-panel {
    padding: 22px;
}

.form-panel {
    display: grid;
    gap: 16px;
}

.form-panel label,
.stack-form label,
.photo-panel label,
.user-row label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

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

.photo-panel {
    display: grid;
    gap: 14px;
    min-width: 0;
    overflow: hidden;
}

.photo-preview {
    display: grid;
    place-items: center;
    width: 100%;
    aspect-ratio: 4 / 3;
    padding: 10px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbfd;
}

.photo-preview-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.file-drop {
    position: relative;
    min-width: 0;
}

.file-control {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    color: #fff;
    background: var(--nion-blue);
    font-weight: 800;
    white-space: nowrap;
}

.file-name {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.check-line {
    display: flex !important;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px !important;
    color: var(--ink) !important;
    font-weight: 700 !important;
}

.check-line input,
.voice-toggle input {
    width: 18px;
    height: 18px;
}

.user-layout {
    grid-template-columns: 320px minmax(0, 1fr);
}

.user-create h2 {
    margin: 0;
    font-size: 20px;
}

.users-list {
    display: grid;
    gap: 12px;
}

.user-row {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr) 140px auto;
    gap: 12px;
    align-items: end;
    padding: 16px;
}

.assistant-shell {
    order: 2;
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto 34px;
}

.assistant-inner {
    padding: 18px;
}

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

.assistant-head h2 {
    margin: 0;
    font-size: 22px;
}

.voice-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-weight: 800;
}

.chat-log {
    display: grid;
    align-content: start;
    gap: 10px;
    min-height: 120px;
    max-height: 260px;
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbfd;
}

.chat-message {
    width: fit-content;
    max-width: min(680px, 92%);
    padding: 10px 12px;
    border-radius: 8px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.chat-message.user {
    justify-self: end;
    color: #fff;
    background: var(--nion-blue);
}

.chat-message.bot {
    justify-self: start;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
}

.chat-message-text {
    display: block;
}

.chat-photo-upload {
    display: grid;
    gap: 9px;
    min-width: min(300px, 100%);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.chat-photo-title,
.chat-photo-status {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.chat-photo-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-upload-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 12px;
    overflow: hidden;
    border-radius: 8px;
    color: #fff;
    background: var(--nion-blue);
    cursor: pointer;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
}

.chat-upload-button:hover {
    background: var(--nion-blue-dark);
}

.chat-upload-button input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.chat-photo-upload.is-uploading .chat-upload-button {
    opacity: .62;
    pointer-events: none;
}

.chat-form {
    display: grid;
    grid-template-columns: 46px 1fr auto;
    gap: 10px;
    margin-top: 12px;
}

.icon-button {
    width: 46px;
    padding: 0;
    color: #fff;
    background: var(--nion-green-dark);
}

.icon-button.is-recording {
    background: var(--danger);
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 22px;
    background: linear-gradient(180deg, #ffffff, #eef8f3);
}

.login-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
    gap: 22px;
    width: min(1000px, 100%);
    align-items: center;
}

.login-brand {
    display: grid;
    place-items: center;
    min-height: 300px;
    padding: 24px;
}

.login-brand img {
    width: min(520px, 100%);
}

.login-panel {
    box-shadow: var(--shadow);
}

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

.login-install-button {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
}

.stack-form {
    display: grid;
    gap: 16px;
}

.login-version {
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: center;
}

.env-example {
    padding: 14px;
    overflow: auto;
    border-radius: 8px;
    background: #0f172a;
    color: #e2e8f0;
}

@media (max-width: 900px) {
    .editor-layout,
    .user-layout,
    .login-layout {
        grid-template-columns: 1fr;
    }

    .user-row {
        grid-template-columns: 1fr 1fr;
    }

    .report-filter-grid,
    .report-summary {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    .site-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .main-nav {
        width: 100%;
        justify-content: stretch;
    }

    .main-nav a,
    .install-button {
        flex: 1 1 auto;
        justify-content: center;
    }

    .page-shell,
    .assistant-shell {
        width: min(100% - 20px, 1180px);
    }

    .assistant-shell {
        order: 1;
        margin-top: 10px;
        margin-bottom: 0;
    }

    .page-shell {
        order: 2;
        padding-top: 16px;
    }

    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    .item-row {
        grid-template-columns: 58px minmax(0, 1fr);
        align-items: start;
        gap: 10px;
        min-height: 82px;
        padding: 10px;
    }

    .item-photo {
        width: 58px;
        height: 58px;
    }

    .item-photo .placeholder-logo {
        width: 30px;
        height: 34px;
    }

    .item-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .search-bar,
    .chat-form,
    .report-filter-grid,
    .report-summary,
    .user-row {
        grid-template-columns: 1fr;
    }

    .report-actions {
        justify-content: stretch;
    }

    .report-actions .primary-button,
    .report-actions .ghost-button {
        flex: 1 1 100%;
    }

    .report-section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .icon-button {
        width: 100%;
    }

    .login-page {
        padding: 12px;
    }

    .login-brand {
        min-height: auto;
        padding: 6px 10px;
    }

    .login-panel-head {
        align-items: flex-start;
        flex-direction: column;
    }
}
