* {
    box-sizing: border-box;
}

:root {
    --background: #f5f6f8;
    --surface: #ffffff;
    --surface-hover: #f9fafb;
    --text: #1d2433;
    --muted: #717b8c;
    --border: #e4e7ec;
    --accent: #405cf5;
    --accent-hover: #3049d8;
    --danger: #d84646;
    --success: #208a5d;
    --shadow: 0 4px 20px rgba(0, 0, 0, .055);
}

body {
    margin: 0;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    background: var(--background);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    height: 68px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 36px;
}

.brand a {
    display: flex;
    align-items: center;
    gap: 12px;

    font-size: 20px;
    font-weight: 700;
}

.brand-icon,
.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--accent);
    color: white;

    font-weight: 800;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
}

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

    font-size: 14px;
}

.topbar-user a {
    color: var(--muted);
}

.page {
    max-width: 1400px;
    margin: auto;
    padding: 38px;
}

.hero {
    margin-bottom: 30px;
}

.hero h1,
.page-header h1 {
    margin: 0;
    font-size: 30px;
}

.hero p,
.page-header p {
    margin: 7px 0 0;
    color: var(--muted);
}

.searchbar {
    margin-bottom: 22px;
}

.searchbar input {
    width: 100%;

    padding: 17px 20px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    font-size: 16px;

    box-shadow: var(--shadow);
}

input:focus {
    outline: 2px solid rgba(64, 92, 245, .15);
    border-color: var(--accent);
}

.category-bar {
    display: flex;
    gap: 9px;

    overflow-x: auto;

    margin-bottom: 32px;
}

.category {
    background: var(--surface);
    border: 1px solid var(--border);

    padding: 9px 15px;

    border-radius: 30px;

    white-space: nowrap;

    color: var(--muted);
    font-size: 14px;
}

.category.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;

    margin-bottom: 16px;
}

.section-heading h2 {
    margin: 0;
}

.section-heading span {
    color: var(--muted);
    font-size: 14px;
}

.app-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(230px, 1fr));

    gap: 18px;
}

.app-card {
    min-height: 150px;

    padding: 22px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;

    box-shadow: var(--shadow);

    display: flex;
    gap: 17px;

    transition: .15s ease;
}

.app-card:hover {
    transform: translateY(-2px);
    border-color: #cbd1dc;
}

.app-icon {
    width: 54px;
    height: 54px;

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;

    background: var(--background);

    border-radius: 14px;

    font-size: 28px;
}

.app-card-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.app-card-content strong {
    font-size: 16px;
}

.app-card-content span {
    font-size: 14px;
    color: var(--muted);
}

.app-card-content small {
    margin-top: auto;
    color: var(--muted);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    margin-bottom: 28px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 10px 15px;

    border: 1px solid var(--border);
    border-radius: 9px;

    background: var(--surface);

    cursor: pointer;

    font: inherit;
    font-size: 14px;
}

.button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.button.primary:hover {
    background: var(--accent-hover);
}

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

.button.full {
    width: 100%;
}

.admin-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(260px, 1fr));

    gap: 18px;
}

.admin-card {
    display: flex;
    align-items: center;
    gap: 17px;

    padding: 23px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    box-shadow: var(--shadow);
}

.admin-card h3,
.admin-card p {
    margin: 0;
}

.admin-card p {
    margin-top: 5px;
    color: var(--muted);
    font-size: 14px;
}

.admin-card.disabled {
    opacity: .55;
}

.admin-icon {
    font-size: 30px;
}

.table-card {
    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    overflow: hidden;
}

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

th,
td {
    padding: 16px;

    text-align: left;

    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-size: 13px;
}

td small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.table-icon {
    width: 55px;
    font-size: 25px;
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.actions form {
    margin: 0;
}

.status {
    display: inline-block;

    padding: 5px 9px;

    border-radius: 20px;

    font-size: 12px;
}

.status.online {
    background: #e7f8ef;
    color: var(--success);
}

.status.offline {
    background: #fdecec;
    color: var(--danger);
}

.form-card {
    max-width: 850px;

    background: var(--surface);

    padding: 28px;

    border: 1px solid var(--border);
    border-radius: 14px;

    box-shadow: var(--shadow);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;

    gap: 20px;
}

.span-2 {
    grid-column: span 2;
}

label {
    display: block;

    margin-bottom: 7px;

    font-size: 14px;
    font-weight: 600;
}

.form-card input {
    width: 100%;

    padding: 12px 13px;

    border: 1px solid var(--border);
    border-radius: 9px;

    font: inherit;
}

.checkbox-row {
    display: flex;
    gap: 28px;

    margin-top: 24px;
}

.checkbox-row label {
    font-weight: 400;
}

.checkbox-row input {
    width: auto;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;

    margin-top: 28px;
}

.login-page {
    min-height: 100vh;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 390px;

    background: var(--surface);

    padding: 38px;

    border: 1px solid var(--border);
    border-radius: 18px;

    box-shadow: var(--shadow);

    text-align: center;
}

.login-logo {
    width: 62px;
    height: 62px;

    margin: auto;

    border-radius: 17px;

    font-size: 29px;
}

.login-card h1 {
    margin-bottom: 5px;
}

.login-card form {
    margin-top: 30px;

    text-align: left;
}

.login-card input {
    width: 100%;

    padding: 12px 13px;

    margin-bottom: 18px;

    border: 1px solid var(--border);
    border-radius: 9px;

    font: inherit;
}

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

.alert {
    margin-bottom: 20px;

    padding: 13px 16px;

    border-radius: 10px;
}

.alert-danger {
    background: #fdecec;
    color: #a62f2f;
}

.alert-success {
    background: #e7f8ef;
    color: #176b48;
}

.alert-info {
    background: #edf2ff;
    color: #3148ac;
}

.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 700px) {
    .page {
        padding: 22px;
    }

    .topbar {
        padding: 0 18px;
    }

    .topbar-user span {
        display: none;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }

    .page-header {
        align-items: flex-start;
        gap: 15px;
        flex-direction: column;
    }
}

.settings-link {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 36px;
    height: 36px;

    border-radius: 9px;

    font-size: 20px;

    transition: background .15s ease;
}

.settings-link:hover {
    background: var(--background);
}

.permission-section {
    margin-top: 30px;
    padding-top: 26px;
    border-top: 1px solid var(--border);
}

.permission-section h3 {
    margin: 0 0 6px;
}

.permission-section > p {
    margin: 0 0 18px;
}

.permission-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.permission-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;

    padding: 14px;

    background: var(--background);

    border: 1px solid var(--border);
    border-radius: 10px;

    cursor: pointer;
}

.permission-card:hover {
    border-color: #c5cad4;
}

.permission-card input {
    width: auto;
    margin-top: 3px;
}

.permission-card strong,
.permission-card small {
    display: block;
}

.permission-card small {
    margin-top: 4px;
    color: var(--muted);
}

.role-badge {
    display: inline-block;

    padding: 5px 9px;
    margin: 2px 3px 2px 0;

    background: #edf2ff;
    color: #3d50b7;

    border-radius: 20px;

    font-size: 12px;
}

.document-section {
    margin-top: 42px;
}

.document-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(310px, 1fr));
    gap: 14px;
}

.document-card {
    min-height: 105px;

    padding: 18px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    box-shadow: var(--shadow);

    display: flex;
    align-items: center;
    gap: 15px;

    transition: .15s ease;
}

.document-card:hover {
    transform: translateY(-2px);
    border-color: #cbd1dc;
}

.document-icon {
    width: 48px;
    height: 48px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 12px;

    background: var(--background);

    font-size: 24px;
}

.document-card-content {
    min-width: 0;

    display: flex;
    flex-direction: column;
    gap: 4px;

    flex: 1;
}

.document-card-content strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 15px;
}

.document-card-content span,
.document-card-content small {
    color: var(--muted);
    font-size: 13px;
}

.document-open {
    color: var(--muted);
    font-size: 18px;

    flex-shrink: 0;
}

.document-card:hover .document-open {
    color: var(--accent);
}

.paperless-error {
    padding: 18px 20px;

    background: #fdecec;
    color: #a62f2f;

    border-radius: 12px;
}

.paperless-error strong,
.paperless-error span {
    display: block;
}

.paperless-error span {
    margin-top: 4px;
    font-size: 14px;
}

.document-empty {
    grid-column: 1 / -1;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;
}

@media (max-width: 700px) {
    .document-grid {
        grid-template-columns: 1fr;
    }
}


/* HomeBase v0.3.2 - Dokumentfilter */

.document-filter-bar {
    display: grid;

    grid-template-columns:
        minmax(260px, 2fr)
        minmax(150px, 1fr)
        minmax(150px, 1fr)
        minmax(210px, 1fr)
        auto;

    gap: 14px;

    align-items: end;

    margin-bottom: 20px;

    padding: 18px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;

    box-shadow: var(--shadow);
}


.document-filter-field label {
    margin-bottom: 7px;

    color: var(--muted);

    font-size: 12px;
    font-weight: 600;
}


.document-filter-field input,
.document-filter-field select {
    width: 100%;
    height: 42px;

    padding: 0 12px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 9px;

    color: var(--text);

    font: inherit;
    font-size: 14px;
}


.document-filter-field select {
    cursor: pointer;
}


.document-filter-reset-wrap {
    display: flex;
    align-items: flex-end;
}


.document-filter-reset-wrap .button {
    height: 42px;
}


.document-card {
    position: relative;
}


.document-tooltip {
    position: absolute;

    left: 18px;
    right: 18px;

    bottom: calc(100% + 9px);

    z-index: 100;

    padding: 10px 12px;

    background: #1d2433;
    color: #ffffff;

    border-radius: 8px;

    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;

    box-shadow:
        0 8px 24px
        rgba(0, 0, 0, .18);

    opacity: 0;
    visibility: hidden;

    transform: translateY(4px);

    pointer-events: none;

    transition:
        opacity .12s ease,
        transform .12s ease,
        visibility .12s ease;

    white-space: normal;
    word-break: break-word;
}


.document-tooltip::after {
    content: "";

    position: absolute;

    top: 100%;
    left: 28px;

    border-width: 6px;
    border-style: solid;

    border-color:
        #1d2433
        transparent
        transparent
        transparent;
}


.document-card:hover .document-tooltip {
    opacity: 1;
    visibility: visible;

    transform: translateY(0);
}


.document-card[hidden] {
    display: none;
}


.document-filter-empty {
    margin-top: 0;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 14px;
}


@media (max-width: 1050px) {

    .document-filter-bar {
        grid-template-columns:
            1fr
            1fr;
    }

    .document-filter-name,
    .document-filter-sort {
        grid-column: span 2;
    }

}


@media (max-width: 700px) {

    .document-filter-bar {
        grid-template-columns: 1fr;
    }

    .document-filter-name,
    .document-filter-sort {
        grid-column: auto;
    }

}


/* HomeBase v0.3.3 - einklappbare Dokumentfilter */

.document-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 20px;

    margin-bottom: 16px;
}


.document-section-header h2 {
    margin: 0;
}


.document-header-actions {
    display: flex;
    align-items: center;

    gap: 14px;

    color: var(--muted);

    font-size: 14px;
}


.document-filter-toggle {
    position: relative;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    gap: 7px;

    min-height: 38px;

    padding: 8px 13px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: 9px;

    color: var(--muted);

    cursor: pointer;

    font: inherit;
    font-size: 14px;

    transition: .15s ease;
}


.document-filter-toggle:hover {
    border-color: #c5cad4;
    color: var(--text);
}


.document-filter-toggle.open {
    color: var(--accent);

    border-color:
        rgba(64, 92, 245, .35);
}


.document-filter-toggle.active {
    color: var(--accent);

    border-color:
        rgba(64, 92, 245, .45);

    background: #f3f5ff;
}


.filter-icon {
    font-size: 15px;
    line-height: 1;
}


.document-filter-badge {
    min-width: 20px;
    height: 20px;

    padding: 0 6px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: var(--accent);
    color: white;

    border-radius: 20px;

    font-size: 11px;
    font-weight: 700;
}


.document-filter-panel {
    margin-bottom: 20px;
}


.document-filter-panel[hidden] {
    display: none;
}


.document-filter-panel .document-filter-bar {
    margin-bottom: 0;
}


@media (max-width: 700px) {

    .document-section-header {
        align-items: flex-start;
    }

    .document-header-actions {
        gap: 8px;
    }

}

/* Fix: aktiven Filter-Badge korrekt ausblenden */
.document-filter-badge[hidden] {
    display: none;
}


/* HomeBase Dokument-Pagination */
.document-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 24px;
}

.document-pagination[hidden] {
    display: none;
}

.document-page-button {
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: .15s ease;
}

.document-page-button:hover:not(:disabled) {
    border-color: #c5cad4;
    background: var(--surface-hover);
}

.document-page-button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.document-page-button:disabled {
    opacity: .4;
    cursor: default;
}

.document-page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 38px;
    color: var(--muted);
}

@media (max-width: 700px) {
    .document-page-button {
        min-width: 34px;
        height: 36px;
        padding: 0 9px;
    }
}


/* HomeBase Application Logos */
.app-logo {
    display: block;
    width: 38px;
    height: 38px;
    object-fit: contain;
}

.app-logo-upload {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.app-logo-upload input[type="file"] {
    padding: 11px;
    background: var(--background);
}

.app-logo-preview {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--background);
}

.app-logo-preview img {
    width: 56px;
    height: 56px;
    padding: 6px;
    object-fit: contain;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.app-logo-preview strong,
.app-logo-preview small {
    display: block;
}

.app-logo-preview small {
    margin-top: 4px;
    color: var(--muted);
}

.app-logo-remove {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    margin: 0;
}

.app-logo-remove input {
    width: auto;
}


/* HomeBase Embedded Applications */

.app-open-mode {
    display: flex;
    flex-direction: column;
    min-width: 230px;
}

.app-open-mode label {
    margin-bottom: 7px;
}

.app-open-mode select {
    min-width: 230px;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.embedded-app-page {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 145px);
}

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

.embedded-app-title {
    display: flex;
    align-items: center;
    gap: 18px;
}

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

.embedded-app-identity h1 {
    margin: 0;
    font-size: 23px;
}

.embedded-app-identity p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.embedded-app-icon {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 25px;
}

.embedded-app-icon img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.embedded-app-frame-wrapper {
    flex: 1;
    min-height: 700px;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.embedded-app-frame {
    display: block;
    width: 100%;
    height: calc(100vh - 190px);
    min-height: 700px;
    border: 0;
    background: white;
}

@media (max-width: 700px) {

    .embedded-app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .embedded-app-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .embedded-app-frame,
    .embedded-app-frame-wrapper {
        min-height: 600px;
    }
}

/* Embedded Apps breiter anzeigen */
.embedded-app-page {
    width: calc(100vw - 80px);
    max-width: none;
    margin-left: 50%;
    transform: translateX(-50%);
}

.embedded-app-frame-wrapper {
    width: 100%;
}

.embedded-app-frame {
    width: 100%;
    height: calc(100vh - 175px);
    min-height: 760px;
}

@media (max-width: 900px) {
    .embedded-app-page {
        width: calc(100vw - 32px);
    }
}


/* HomeBase App Sorting */

.app-sort-hint {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 13px;
}

.app-sort-hint-icon {
    font-size: 17px;
}

.app-sort-status {
    margin-left: auto;
    font-size: 13px;
}

.app-sort-status.saving {
    color: var(--muted);
}

.app-sort-status.saved {
    color: var(--success);
}

.app-sort-status.error {
    color: var(--danger);
}

.drag-column {
    width: 46px;
    text-align: center;
}

.logo-column {
    width: 58px;
}

.drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 38px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 19px;
    letter-spacing: -3px;
    cursor: grab;
    user-select: none;
}

.drag-handle:hover {
    background: var(--background);
    color: var(--text);
}

.drag-handle:active {
    cursor: grabbing;
}

.sortable-app-row {
    transition:
        opacity .12s ease,
        background .12s ease;
}

.sortable-app-row.dragging {
    opacity: .42;
    background: var(--background);
}

.admin-app-icon {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--background);
    font-size: 24px;
}

.admin-app-icon img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}


/* HomeBase System Administration */

.system-grid {
    display: grid;
    grid-template-columns: repeat(
        2,
        minmax(0, 1fr)
    );
    gap: 18px;
    margin-bottom: 34px;
}

.system-card,
.system-coming-soon {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.system-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.system-card-header h2 {
    margin: 0;
    font-size: 18px;
}

.system-card-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.system-card-icon {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    border-radius: 12px;
    font-size: 24px;
}

.system-info-list {
    display: flex;
    flex-direction: column;
}

.system-info-list > div {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--border);
}

.system-info-list > div:last-child {
    border-bottom: 0;
}

.system-info-list span {
    color: var(--muted);
    font-size: 14px;
}

.system-info-list strong {
    font-size: 14px;
    text-align: right;
}

.system-online {
    color: var(--success);
}

.system-offline {
    color: var(--danger);
}

.system-value-wrap {
    max-width: 310px;
    overflow-wrap: anywhere;
}

.system-card-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}

.system-last-backup {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 20px;
    padding: 14px;
    background: var(--background);
    border-radius: 10px;
}

.system-last-backup span {
    color: var(--muted);
    font-size: 13px;
}

.system-last-backup strong {
    font-size: 15px;
}

.system-backup-list {
    margin-top: 10px;
}

.system-backup-list .section-heading > div p {
    margin: 5px 0 0;
}

.system-empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.system-coming-soon {
    margin-top: 30px;
    opacity: .72;
}

.system-coming-soon .system-card-header {
    margin-bottom: 0;
}

@media (max-width: 850px) {

    .system-grid {
        grid-template-columns: 1fr;
    }

}


/* HomeBase Restore */

.system-restore-upload {
    margin-top: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.restore-warning {
    margin-bottom: 20px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--background);
}

.restore-warning strong {
    display: block;
    margin-bottom: 5px;
}

.restore-warning p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.restore-upload-form {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.restore-upload-form input[type="file"] {
    flex: 1;
    min-width: 260px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
}

@media (max-width: 700px) {

    .restore-upload-form {
        align-items: stretch;
        flex-direction: column;
    }

    .restore-upload-form input[type="file"] {
        width: 100%;
        min-width: 0;
    }

}


/* HomeBase Tasks */

.topbar-main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 30px;
    margin-right: auto;
}

.topbar-nav-link {
    padding: 8px 11px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    text-decoration: none;
}

.topbar-nav-link:hover {
    background: var(--background);
    color: var(--text);
}

.task-toolbar {
    display: flex;
    align-items: center;
    margin-bottom: 22px;
}

.task-filters {
    display: inline-flex;
    gap: 5px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
}

.task-filter {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    text-decoration: none;
}

.task-filter span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 20px;
    background: var(--background);
    font-size: 12px;
}

.task-filter.active {
    background: var(--accent);
    color: white;
}

.task-filter.active span {
    background: rgba(255,255,255,.18);
    color: white;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.task-card.completed {
    opacity: .68;
}

.task-check-form {
    margin: 3px 0 0;
}

.task-check {
    width: 27px;
    height: 27px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
}

.task-check:hover {
    border-color: var(--accent);
}

.task-check.checked {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

.task-content {
    flex: 1;
    min-width: 0;
}

.task-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.task-title-row h3 {
    margin: 2px 0 0;
    font-size: 17px;
}

.task-card.completed .task-title-row h3 {
    text-decoration: line-through;
}

.task-badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.task-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 8px;
    border-radius: 7px;
    background: var(--background);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.task-badge.owner {
    background: rgba(64,92,245,.09);
    color: var(--accent);
}

.task-description {
    margin: 8px 0 10px;
    color: var(--muted);
    line-height: 1.55;
    white-space: pre-wrap;
}

.task-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
}

.task-due.today {
    font-weight: 700;
    color: var(--accent);
}

.task-due.overdue {
    font-weight: 700;
    color: var(--danger);
}

.task-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
}

.task-actions form {
    margin: 0;
}

.task-empty {
    padding: 70px 30px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.task-empty-icon {
    width: 58px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    border-radius: 16px;
    background: var(--background);
    font-size: 28px;
}

.task-empty h2 {
    margin: 0;
}

.task-empty p {
    margin: 8px 0 20px;
    color: var(--muted);
}

.task-form-card {
    max-width: 850px;
    padding: 26px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.task-form-card .form-group {
    margin-bottom: 22px;
}

.task-form-card label:not(.task-share-all):not(.task-user-option) {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.task-form-card input[type="text"],
.task-form-card input[type="date"],
.task-form-card textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.task-form-card textarea {
    resize: vertical;
}

.task-form-card input:focus,
.task-form-card textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.task-date-field {
    max-width: 300px;
}

.task-date-field small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
}

.task-sharing-section {
    margin-top: 30px;
    padding-top: 25px;
    border-top: 1px solid var(--border);
}

.task-sharing-heading h2 {
    margin: 0;
    font-size: 18px;
}

.task-sharing-heading p {
    margin: 5px 0 18px;
    color: var(--muted);
}

.task-share-all {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
}

.task-share-all input {
    margin-top: 3px;
}

.task-share-all span,
.task-user-option > span:last-child {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.task-share-all small,
.task-user-option small {
    color: var(--muted);
}

.task-user-share {
    margin-top: 18px;
    transition: opacity .15s ease;
}

.task-user-share.disabled {
    opacity: .38;
}

.task-user-share-title {
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 13px;
}

.task-user-list {
    display: grid;
    grid-template-columns: repeat(
        2,
        minmax(0, 1fr)
    );
    gap: 10px;
}

.task-user-option {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
}

.task-user-option:hover {
    background: var(--background);
}

.task-user-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--background);
    font-weight: 700;
}

.task-user-option input {
    margin: 0;
}

.task-form-card .form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

@media (max-width: 800px) {

    .topbar-main-nav {
        margin-left: 15px;
    }

    .task-card {
        flex-wrap: wrap;
    }

    .task-content {
        width: calc(100% - 50px);
    }

    .task-actions {
        width: 100%;
        justify-content: flex-end;
        margin-left: 43px;
    }

    .task-title-row {
        flex-direction: column;
        gap: 8px;
    }

    .task-badges {
        justify-content: flex-start;
    }

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

}


/* HomeBase Modal */

.homebase-modal[hidden] {
    display: none;
}

.homebase-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.homebase-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 25, 35, .48);
    backdrop-filter: blur(3px);
}

.homebase-modal-dialog {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(0,0,0,.22);
}

.homebase-modal-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
    border-radius: 12px;
    background: var(--background);
    font-size: 24px;
}

.homebase-modal-dialog h2 {
    margin: 0 0 10px;
    font-size: 21px;
}

.homebase-modal-dialog p {
    margin: 0 0 8px;
    line-height: 1.5;
}

.homebase-modal-muted {
    color: var(--muted);
    font-size: 13px;
}

.homebase-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

.homebase-modal-actions form {
    margin: 0;
}

body.modal-open {
    overflow: hidden;
}


/* HomeBase SMTP */

.smtp-test-form {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.smtp-test-form > label {
    display: block;
    margin-bottom: 9px;
    font-size: 13px;
    font-weight: 600;
}

.smtp-test-row {
    display: flex;
    align-items: center;
    gap: 9px;
}

.smtp-test-row input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.task-reminder-field {
    max-width: 420px;
}

.task-reminder-field select {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.task-reminder-field small {
    display: block;
    margin-top: 7px;
    color: var(--muted);
}

@media (max-width: 650px) {

    .smtp-test-row {
        flex-direction: column;
        align-items: stretch;
    }

}


/* HomeBase Calendar v1 */

.calendar-page-header {
    margin-bottom: 20px;
}

.calendar-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-bottom: 14px;
}

.calendar-current-month {
    min-width: 230px;
    text-align: center;
}

.calendar-current-month h2 {
    margin: 0;
}

.calendar-current-month a {
    display: inline-block;
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
    text-decoration: none;
}

.calendar-nav-button {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--muted);
}

.calendar-legend > span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.calendar-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #4f75ff;
}

.calendar-legend-dot.task {
    background: #df9b20;
}

.calendar-legend-dot.completed {
    background: #84909d;
}

.calendar-shell {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border-bottom: 1px solid var(--border);
}

.calendar-weekdays > div {
    padding: 11px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-day {
    min-height: 145px;
    padding: 8px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    min-width: 0;
}

.calendar-day:nth-child(7n) {
    border-right: 0;
}

.calendar-day.outside-month {
    opacity: 0.42;
}

.calendar-day.today {
    background: rgba(80, 115, 255, 0.055);
}

.calendar-day-number {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 26px;
    margin-bottom: 6px;
}

.calendar-day-number > span {
    width: 27px;
    height: 27px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    border-radius: 50%;
}

.calendar-day.today .calendar-day-number > span {
    background: #4f75ff;
    color: white;
}

.calendar-day-number small {
    font-size: 10px;
    color: var(--muted);
}

.calendar-day-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.calendar-item {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    padding: 5px 6px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 11px;
    line-height: 1.3;
}

.calendar-event {
    background: rgba(79, 117, 255, 0.14);
    color: inherit;
}

.calendar-event:hover {
    background: rgba(79, 117, 255, 0.22);
}

.calendar-event.shared-event {
    cursor: default;
}

.calendar-task {
    background: rgba(223, 155, 32, 0.14);
    color: inherit;
}

.calendar-task:hover {
    background: rgba(223, 155, 32, 0.22);
}

.calendar-task.completed {
    opacity: 0.55;
    text-decoration: line-through;
}

.calendar-item-time {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    opacity: 0.75;
}

.calendar-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.calendar-share-icon {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 10px;
}

.calendar-event-form textarea {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
}

.calendar-time-section {
    margin-top: 24px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

.calendar-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 18px;
    font-weight: 600;
}

.calendar-time-section [hidden] {
    display: none !important;
}

.calendar-share-all {
    margin-bottom: 14px;
}

.calendar-share-disabled {
    opacity: 0.45;
}

.calendar-delete-section {
    margin-top: 24px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.calendar-delete-section p {
    margin-bottom: 0;
}

@media (max-width: 900px) {

    .calendar-shell {
        overflow-x: auto;
    }

    .calendar-weekdays,
    .calendar-grid {
        min-width: 850px;
    }

}

@media (max-width: 650px) {

    .calendar-delete-section {
        align-items: stretch;
        flex-direction: column;
    }

}


/* HomeBase Google Calendar v1 */

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

.calendar-google-event {
    background: rgba(66, 133, 244, 0.14);
    color: inherit;
}

.calendar-google-event:hover {
    background: rgba(66, 133, 244, 0.23);
}

.calendar-google-icon {
    margin-left: auto;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 800;
    background: rgba(66, 133, 244, 0.22);
}

.google-connect-card {
    max-width: 720px;
}

.google-account-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 22px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.google-account-card h2 {
    margin: 7px 0 3px;
}

.google-account-status {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 700;
}

.google-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #34a853;
}

.google-calendar-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 18px;
}

.google-calendar-row {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
}

.google-calendar-row:hover {
    background: rgba(127, 127, 127, 0.05);
}

.google-calendar-color {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #4285f4;
}

.google-calendar-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.google-calendar-name small {
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    background: rgba(66, 133, 244, 0.12);
}

@media (max-width: 650px) {

    .calendar-header-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .google-account-card {
        align-items: stretch;
        flex-direction: column;
    }

}


/* HomeBase Google Sync v2 */

.calendar-google-sync-section {
    margin-top: 24px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

.calendar-google-sync-section h3 {
    margin-top: 0;
    margin-bottom: 14px;
}

#google-calendar-selection {
    margin-top: 4px;
    max-width: 520px;
}

#google-calendar-selection[hidden] {
    display: none !important;
}

#google-calendar-selection select {
    width: 100%;
    margin-top: 6px;
}

#google-calendar-selection small {
    display: block;
    margin-top: 8px;
}


/* ==========================================================
   HomeBase Calendar - Multi-day event bars v2
   ========================================================== */

.calendar-grid {
    display: block;
}

.calendar-week {
    position: relative;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    --calendar-multiday-space: 0px;
    --calendar-multiday-top: 42px;
}

.calendar-week .calendar-day {
    min-height: 145px;
}

.calendar-week .calendar-day:nth-child(7n) {
    border-right: 0;
}

.calendar-week .calendar-day-items {
    padding-top: var(--calendar-multiday-space);
}

.calendar-multiday-layer {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
}

.calendar-multiday-bar {
    position: absolute;

    left: calc(
        (
            100% / 7
        ) * var(--calendar-span-start)
        + 8px
    );

    width: calc(
        (
            100% / 7
        ) * var(--calendar-span-length)
        - 16px
    );

    top: calc(
        var(--calendar-multiday-top)
        + (
            var(--calendar-span-lane)
            * 29px
        )
    );

    height: 25px;
    box-sizing: border-box;

    display: flex;
    align-items: center;

    padding: 5px 8px;

    border-radius: 6px;

    overflow: hidden;

    z-index: 5;

    pointer-events: auto;
}

.calendar-multiday-bar .calendar-item-title {
    flex: 1;
}

.calendar-multiday-bar .calendar-google-icon,
.calendar-multiday-bar .calendar-share-icon {
    flex-shrink: 0;
}

