:root {
    color-scheme: light;
    --nav-bg: #0c3035;
    --nav-bg-hover: #154248;
    --primary: #006866;
    --primary-dark: #005a57;
    --primary-soft: #e6eff0;
    --surface: #ffffff;
    --surface-subtle: #f8fafb;
    --surface-hover: #f2f6f7;
    --text: #10242d;
    --text-muted: #65747e;
    --border: #d8dee3;
    --border-strong: #c7d0d6;
    --warning: #f29503;
    --warning-soft: #fff8e9;
    --warning-text: #b85d00;
    --danger: #b42318;
    --focus: #0d8e8b;
    --topbar-height: 73px;
    --rail-width: 75px;
    --directory-width: 364px;
    --action-width: 413px;
    font-family:
        "Yu Gothic UI",
        "Hiragino Kaku Gothic ProN",
        "Meiryo",
        system-ui,
        sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 0;
    background: var(--nav-bg);
}

body {
    min-width: 0;
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--surface);
    font-size: 16px;
    line-height: 1.55;
    text-rendering: optimizeLegibility;
}

button,
input,
textarea {
    font: inherit;
}

button,
a,
input,
textarea {
    -webkit-tap-highlight-color: transparent;
}

button {
    color: inherit;
}

a {
    color: var(--primary-dark);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
[role="treeitem"]:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

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

.skip-link {
    position: fixed;
    z-index: 100;
    top: 10px;
    left: 10px;
    padding: 10px 14px;
    color: #fff;
    background: #000;
    border-radius: 6px;
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: translateY(0);
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 27px 0 24px;
    color: #fff;
    background: var(--nav-bg);
}

.brand {
    color: #fff;
    font-size: 22px;
    font-weight: 750;
    letter-spacing: -0.025em;
    text-decoration: none;
}

.brand:hover {
    color: #fff;
}

.button {
    display: inline-flex;
    min-height: 44px;
    padding: 0 18px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.56;
}

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

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

.button-outline {
    color: var(--primary);
    background: var(--surface);
    border-color: var(--primary);
}

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

.button-quiet {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border-strong);
}

.button-quiet:hover {
    background: var(--surface-hover);
}

.topbar-action {
    min-width: 126px;
}

.topbar-action .bi {
    display: none;
}

.app-body {
    display: grid;
    grid-template-columns:
        var(--rail-width)
        var(--directory-width)
        minmax(480px, 1fr)
        var(--action-width);
    min-height: calc(100dvh - var(--topbar-height));
    background: var(--surface);
}

.app-rail,
.directory-pane,
.contact-pane,
.action-pane {
    min-width: 0;
    min-height: 0;
}

.app-rail {
    position: sticky;
    top: var(--topbar-height);
    display: flex;
    height: calc(100dvh - var(--topbar-height));
    padding: 19px 12px 16px;
    flex-direction: column;
    justify-content: space-between;
    color: #c5d4d6;
    background: var(--nav-bg);
}

.rail-list {
    display: grid;
    gap: 12px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.rail-footer {
    display: grid;
    justify-items: center;
    gap: 13px;
}

.rail-button {
    position: relative;
    display: grid;
    width: 52px;
    min-height: 52px;
    padding: 0;
    place-items: center;
    color: #c5d4d6;
    background: transparent;
    border: 0;
    border-radius: 7px;
    cursor: pointer;
}

.rail-button .bi {
    font-size: 22px;
    line-height: 1;
}

.rail-button:hover {
    color: #fff;
    background: var(--nav-bg-hover);
}

.rail-button.is-active {
    color: #fff;
    background: var(--primary);
}

.rail-label {
    position: absolute;
    overflow: hidden;
    width: 1px;
    height: 1px;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.runtime-indicator {
    width: 9px;
    height: 9px;
    background: #62d8a1;
    border: 2px solid var(--nav-bg);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(98, 216, 161, 0.24);
}

.directory-pane,
.contact-pane,
.action-pane {
    overflow-y: auto;
    overscroll-behavior: contain;
}

.directory-pane {
    padding: 29px 27px 32px;
    background: var(--surface-subtle);
    border-top-left-radius: 12px;
    border-right: 1px solid var(--border);
}

.search-field {
    display: grid;
    min-height: 48px;
    padding: 0 10px 0 14px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
}

.search-field:focus-within {
    border-color: var(--focus);
    box-shadow: 0 0 0 2px rgba(13, 142, 139, 0.12);
}

.search-field > .bi {
    font-size: 20px;
}

.search-field input {
    width: 100%;
    min-width: 0;
    height: 46px;
    padding: 0;
    color: var(--text);
    background: transparent;
    border: 0;
    outline: 0;
}

.search-field input::placeholder {
    color: #819099;
}

.search-field kbd {
    padding: 2px 6px;
    color: #7a8991;
    background: #f6f8f9;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.current-company {
    margin-top: 25px;
}

.section-kicker {
    margin: 0 0 4px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.current-company-button {
    display: flex;
    width: 100%;
    min-height: 44px;
    padding: 0;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: var(--text);
    background: transparent;
    border: 0;
    font-size: 18px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.current-company-button:hover {
    color: var(--primary);
}

.directory-tabs {
    display: grid;
    margin-top: 27px;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--border);
}

.tab-button {
    position: relative;
    min-height: 48px;
    padding: 0 8px;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    font-weight: 700;
    cursor: pointer;
}

.tab-button::after {
    position: absolute;
    right: 0;
    bottom: -1px;
    left: 0;
    height: 3px;
    background: transparent;
    content: "";
}

.tab-button:hover {
    color: var(--text);
}

.tab-button.is-active {
    color: var(--primary);
}

.tab-button.is-active::after {
    background: var(--primary);
}

.tab-panel {
    padding-top: 19px;
}

.organization-tree,
.organization-tree ul,
.recent-people-list {
    padding: 0;
    margin: 0;
    list-style: none;
}

.organization-tree ul[role="group"] {
    padding: 0;
    margin: 0;
}

.tree-row {
    display: grid;
    width: 100%;
    min-height: 48px;
    padding: 0 12px;
    grid-template-columns: 18px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    color: var(--text);
    background: transparent;
    border: 0;
    border-left: 4px solid transparent;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
}

.tree-row:hover {
    background: var(--surface-hover);
}

.tree-row.is-selected {
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-left-color: var(--primary);
    font-weight: 700;
}

.tree-row[hidden],
.tree-row.is-filtered {
    display: none;
}

.tree-company {
    grid-template-columns: 18px 18px minmax(0, 1fr);
    font-weight: 700;
}

.tree-department {
    padding-left: 38px;
    grid-template-columns: 18px minmax(0, 1fr);
    font-weight: 650;
}

.tree-person {
    padding-left: 65px;
    grid-template-columns: 18px minmax(0, 1fr) auto auto;
}

.tree-icon,
.tree-chevron {
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
}

.tree-row.is-selected .tree-icon,
.tree-row.is-selected .tree-chevron {
    color: var(--primary);
}

.tree-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-meta {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.tree-more {
    display: grid;
    width: 20px;
    place-items: center;
    color: var(--primary);
}

.no-results {
    padding: 28px 12px;
    margin: 0;
    color: var(--text-muted);
    text-align: center;
}

.recent-people-list {
    display: grid;
    gap: 8px;
}

.recent-person {
    display: grid;
    width: 100%;
    min-height: 66px;
    padding: 9px 10px;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
}

.recent-person:hover {
    background: var(--primary-soft);
}

.recent-person > span:last-child {
    display: grid;
    min-width: 0;
}

.recent-person small {
    overflow: hidden;
    color: var(--text-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-avatar {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    color: var(--primary-dark);
    background: var(--primary-soft);
    border: 1px solid #c8dcde;
    border-radius: 50%;
    font-weight: 800;
}

.contact-pane {
    padding: 34px 35px 40px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.breadcrumb {
    display: flex;
    min-height: 28px;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 650;
}

.breadcrumb .bi {
    color: var(--text-muted);
    font-size: 13px;
}

.person-header {
    margin-top: 12px;
}

.person-name-row {
    display: flex;
    align-items: baseline;
    gap: 28px;
}

.person-name-row h2 {
    margin: 0;
    font-size: clamp(34px, 3.05vw, 44px);
    font-weight: 750;
    letter-spacing: -0.045em;
    line-height: 1.2;
}

.person-title {
    font-size: 20px;
    font-weight: 650;
}

.person-id {
    display: flex;
    margin: 8px 0 0;
    align-items: center;
    gap: 9px;
    color: var(--text-muted);
}

.person-id .bi {
    font-size: 18px;
}

.business-card {
    width: min(100%, 454px);
    aspect-ratio: 1.568 / 1;
    overflow: hidden;
    margin: 18px 0 32px;
    background: #fbfcfd;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
}

.business-card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.business-card-empty {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    align-content: center;
    gap: 10px;
    color: var(--text-muted);
    background: #f5f8f9;
    text-align: center;
}

.business-card-empty .bi {
    color: var(--primary);
    font-size: 32px;
}

.detail-section {
    max-width: 535px;
}

.detail-section h3,
.action-pane h2 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 750;
    line-height: 1.45;
}

.detail-section h3 {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.contact-list {
    margin: 0;
}

.contact-list > div {
    display: grid;
    min-height: 48px;
    padding: 11px 2px;
    grid-template-columns: 142px minmax(0, 1fr);
    align-items: start;
    gap: 4px 14px;
    border-bottom: 1px solid var(--border);
}

.contact-list dt {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-weight: 700;
}

.contact-list dt .bi {
    width: 20px;
    color: var(--primary);
    font-size: 19px;
    text-align: center;
}

.contact-list dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.contact-list dd a {
    color: var(--text);
    text-decoration: none;
}

.contact-list dd a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.memo-section {
    position: relative;
    padding-bottom: 60px;
    margin-top: 34px;
}

.memo-section p {
    margin: 17px 0 0;
    overflow-wrap: anywhere;
}

.edit-person-button {
    position: absolute;
    right: 0;
    bottom: 0;
    min-width: 103px;
}

.action-pane {
    padding: 35px 28px 30px;
    background: var(--surface-subtle);
}

.task-card {
    display: grid;
    width: 100%;
    min-height: 148px;
    padding: 20px 17px;
    margin-top: 15px;
    grid-template-columns: 36px minmax(0, 1fr) 18px;
    align-items: start;
    gap: 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-left: 5px solid var(--warning);
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
}

.task-card:hover {
    border-color: #e8a43c;
    border-left-color: var(--warning);
    background: #fffdf9;
}

.task-icon {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    color: var(--warning-text);
    background: var(--warning-soft);
    border-radius: 7px;
}

.task-icon .bi {
    font-size: 20px;
}

.task-copy {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.task-copy strong {
    font-size: 19px;
}

.task-due {
    color: var(--warning-text);
    font-size: 14px;
    font-weight: 750;
}

.task-copy small {
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.55;
}

.task-chevron {
    align-self: center;
    color: var(--text-muted);
}

.add-task-button {
    width: 100%;
    min-height: 48px;
    margin-top: 22px;
}

.recent-contact-section {
    margin-top: 53px;
}

.recent-contact-section h2 {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.recent-contact {
    display: grid;
    width: 100%;
    min-height: 86px;
    padding: 13px 4px;
    grid-template-columns: 25px minmax(0, 1fr) 18px;
    align-items: start;
    gap: 12px;
    color: var(--text);
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.recent-contact:hover {
    background: var(--surface-hover);
}

.recent-contact > .bi:first-child {
    color: var(--text-muted);
    font-size: 20px;
}

.recent-contact > span {
    display: grid;
    gap: 7px;
}

.recent-contact strong {
    font-weight: 650;
}

.recent-contact small {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.55;
}

.recent-contact > .bi:last-child {
    align-self: center;
    color: var(--text-muted);
}

.preview-note,
.import-status {
    display: flex;
    padding: 12px 14px;
    margin: 32px 0 0;
    align-items: flex-start;
    gap: 9px;
    color: var(--text-muted);
    background: #f0f4f5;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.55;
}

.import-status {
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-color: #c7dcde;
}

.app-dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: min(760px, calc(100dvh - 32px));
    padding: 0;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    box-shadow: 0 22px 70px rgba(10, 36, 45, 0.2);
}

.app-dialog::backdrop {
    background: rgba(5, 26, 31, 0.52);
}

.dialog-form {
    display: grid;
    gap: 20px;
    padding: 24px;
}

.dialog-form header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.dialog-form h2 {
    margin: 0;
    font-size: 25px;
}

.icon-button {
    display: grid;
    width: 44px;
    height: 44px;
    padding: 0;
    place-items: center;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.icon-button:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.dialog-description {
    margin: 0;
    color: var(--text-muted);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-field {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-weight: 700;
}

.form-field-wide {
    grid-column: 1 / -1;
}

.form-field input,
.form-field textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    font-weight: 500;
}

.form-field textarea {
    min-height: 96px;
    resize: vertical;
}

.form-field input:user-invalid,
.form-field textarea:user-invalid,
.form-field [aria-invalid="true"] {
    border-color: var(--danger);
}

.form-field small {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}

.form-error {
    padding: 10px 12px;
    margin: 0;
    color: var(--danger);
    background: #fff1f0;
    border: 1px solid #ffc9c5;
    border-radius: 7px;
}

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

.toast-region {
    position: fixed;
    z-index: 110;
    right: 20px;
    bottom: 20px;
    display: grid;
    max-width: min(420px, calc(100vw - 40px));
    padding: 0;
    pointer-events: none;
}

.toast-region:not(:empty) {
    padding: 13px 16px;
    color: #fff;
    background: var(--nav-bg);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(10, 36, 45, 0.2);
}

[hidden] {
    display: none !important;
}

@media (max-width: 1279px) {
    :root {
        --rail-width: 68px;
        --directory-width: 320px;
    }

    body {
        overflow: auto;
    }

    .app-body {
        grid-template-columns: var(--rail-width) var(--directory-width) minmax(0, 1fr);
        align-items: start;
    }

    .app-rail {
        grid-row: 1 / span 2;
    }

    .directory-pane {
        grid-column: 2;
        grid-row: 1 / span 2;
        min-height: calc(100dvh - var(--topbar-height));
    }

    .contact-pane {
        grid-column: 3;
        border-right: 0;
    }

    .action-pane {
        grid-column: 3;
        border-top: 1px solid var(--border);
    }

    .directory-pane,
    .contact-pane,
    .action-pane {
        overflow: visible;
    }
}

@media (max-width: 900px) {
    .app-body {
        grid-template-columns: var(--rail-width) minmax(0, 1fr);
    }

    .app-rail {
        grid-column: 1;
        grid-row: 1 / span 3;
    }

    .directory-pane,
    .contact-pane,
    .action-pane {
        grid-column: 2;
        grid-row: auto;
    }

    .directory-pane {
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
    }

    .contact-pane {
        border-right: 0;
    }
}

@media (max-width: 767px) {
    :root {
        --topbar-height: 64px;
    }

    .topbar {
        height: var(--topbar-height);
        padding: 0 16px;
    }

    .brand {
        font-size: 19px;
    }

    .topbar-action {
        min-width: 0;
        padding: 0 13px;
    }

    .topbar-action .bi {
        display: inline-block;
    }

    .app-body {
        display: block;
    }

    .app-rail {
        position: sticky;
        z-index: 15;
        top: var(--topbar-height);
        display: flex;
        width: 100%;
        height: auto;
        min-height: 56px;
        padding: 4px 10px;
        flex-direction: row;
        align-items: center;
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }

    .rail-list,
    .rail-footer {
        display: flex;
        gap: 4px;
        align-items: center;
    }

    .rail-button {
        width: 48px;
        min-height: 48px;
    }

    .runtime-indicator {
        margin-left: 4px;
    }

    .directory-pane,
    .contact-pane,
    .action-pane {
        padding-right: 16px;
        padding-left: 16px;
    }

    .directory-pane {
        padding-top: 21px;
        padding-bottom: 24px;
    }

    .contact-pane {
        padding-top: 25px;
        padding-bottom: 32px;
    }

    .action-pane {
        padding-top: 28px;
        padding-bottom: 32px;
    }

    .search-field kbd {
        display: none;
    }

    .person-name-row {
        flex-wrap: wrap;
        gap: 6px 16px;
    }

    .person-name-row h2 {
        font-size: 32px;
    }

    .person-title {
        font-size: 18px;
    }

    .business-card {
        width: 100%;
    }

    .contact-list > div {
        grid-template-columns: 104px minmax(0, 1fr);
    }

    .recent-contact-section {
        margin-top: 40px;
    }

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

    .form-field-wide {
        grid-column: auto;
    }

    .dialog-actions {
        flex-direction: column-reverse;
    }

    .dialog-actions .button {
        width: 100%;
    }
}

@media (max-width: 380px) {
    .topbar-action span {
        font-size: 0;
    }

    .topbar-action span::after {
        font-size: 14px;
        content: "名刺追加";
    }

    .tree-person {
        padding-left: 45px;
    }

    .contact-list > div {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .button,
    .rail-button,
    .tree-row,
    .tab-button,
    .task-card,
    .recent-contact,
    .recent-person {
        transition:
            color 120ms ease,
            background-color 120ms ease,
            border-color 120ms ease;
    }
}

@media (forced-colors: active) {
    .rail-button.is-active,
    .tree-row.is-selected,
    .task-card {
        border: 2px solid CanvasText;
    }

    .runtime-indicator {
        forced-color-adjust: none;
    }
}

/* Authentication */

.auth-page {
    display: grid;
    min-height: 100dvh;
    grid-template-rows: var(--topbar-height) minmax(0, 1fr);
    background: var(--surface-subtle);
}

.auth-brandbar {
    display: flex;
    min-width: 0;
    padding: 0 24px;
    align-items: center;
    background: var(--nav-bg);
}

.auth-shell {
    display: grid;
    min-width: 0;
    padding: 44px 20px;
    place-items: center;
}

.auth-card {
    width: min(460px, 100%);
    padding: 34px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 18px 48px rgba(10, 36, 45, 0.11);
}

.auth-card-wide {
    width: min(520px, 100%);
}

.auth-heading {
    display: flex;
    align-items: center;
    gap: 16px;
}

.auth-heading h1 {
    margin: 2px 0 0;
    color: var(--text);
    font-size: clamp(28px, 5vw, 34px);
    line-height: 1.2;
    letter-spacing: -0.03em;
}

.auth-icon {
    display: grid;
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    place-items: center;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 10px;
    font-size: 25px;
}

.auth-description {
    margin: 20px 0 0;
    color: var(--text-muted);
}

.auth-form {
    display: grid;
    gap: 18px;
    margin-top: 26px;
}

.auth-submit {
    width: 100%;
    margin-top: 3px;
}

.auth-support {
    padding-top: 20px;
    margin: 24px 0 0;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    font-size: 13px;
    text-align: center;
}

.form-error-summary {
    padding: 13px 15px;
    margin-top: 20px;
    color: var(--danger);
    background: #fff1f0;
    border: 1px solid #ffc9c5;
    border-radius: 8px;
}

.form-error-summary p {
    margin: 0;
    font-weight: 700;
}

.form-error-summary ul {
    padding-left: 20px;
    margin: 6px 0 0;
    font-size: 14px;
}

.field-error {
    color: var(--danger) !important;
    font-weight: 600 !important;
}

.password-guidance {
    display: flex;
    padding: 12px 14px;
    align-items: flex-start;
    gap: 9px;
    color: var(--text-muted);
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.password-guidance .bi {
    margin-top: 2px;
    color: var(--primary);
}

/* User administration */

.rail-button[href] {
    text-decoration: none;
}

.rail-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.topbar-authenticated {
    gap: 20px;
}

.topbar-account,
.current-user {
    display: flex;
    align-items: center;
}

.topbar-account {
    min-width: 0;
    gap: 16px;
}

.current-user {
    gap: 9px;
}

.current-user-icon {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    color: #dce9ea;
    font-size: 24px;
}

.current-user-copy {
    display: grid;
    min-width: 0;
    line-height: 1.25;
}

.current-user-copy strong {
    overflow: hidden;
    max-width: 180px;
    color: #fff;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.current-user-copy small {
    color: #b8ccce;
    font-size: 11px;
}

.logout-form {
    margin: 0;
}

.button-topbar {
    min-height: 44px;
    padding: 0 14px;
    color: #fff;
    border-color: rgba(255, 255, 255, 0.34);
}

.button-topbar:hover {
    color: #fff;
    background: var(--nav-bg-hover);
    border-color: rgba(255, 255, 255, 0.58);
}

.admin-page {
    background: var(--surface-subtle);
}

.admin-app-shell {
    display: grid;
    min-height: calc(100dvh - var(--topbar-height));
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
}

.admin-main {
    min-width: 0;
    padding: 38px clamp(24px, 4vw, 56px) 56px;
}

.admin-container {
    width: min(1220px, 100%);
    margin: 0 auto;
}

.admin-header {
    display: flex;
    margin-bottom: 28px;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
}

.admin-header h1 {
    margin: 3px 0 4px;
    color: var(--text);
    font-size: clamp(30px, 4vw, 38px);
    line-height: 1.2;
    letter-spacing: -0.035em;
}

.admin-header p:not(.section-kicker) {
    margin: 0;
    color: var(--text-muted);
}

.one-time-setup {
    display: grid;
    padding: 18px 20px;
    margin-bottom: 24px;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 15px;
    color: var(--primary-dark);
    background: var(--primary-soft);
    border: 1px solid #b9d4d5;
    border-radius: 10px;
}

.one-time-setup-icon {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    color: #fff;
    background: var(--primary);
    border-radius: 8px;
    font-size: 20px;
}

.one-time-setup h2 {
    margin: 0;
    font-size: 18px;
}

.one-time-setup p {
    margin: 4px 0 12px;
    color: var(--text);
    font-size: 14px;
}

.token-field {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
}

.token-field input {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    color: var(--text);
    background: #fff;
    border: 1px solid #9ebfc0;
    border-radius: 7px;
    font-family: ui-monospace, "Cascadia Mono", "Meiryo", monospace;
    font-size: 13px;
}

.admin-users-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(330px, 380px);
    align-items: start;
    gap: 24px;
}

.admin-panel {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 26px rgba(10, 36, 45, 0.055);
}

.panel-header {
    display: flex;
    padding: 22px 24px 18px;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    margin: 0;
    font-size: 21px;
    line-height: 1.3;
}

.panel-header p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.panel-header .section-kicker {
    margin: 0 0 3px;
    color: var(--primary);
}

.user-table-wrapper {
    overflow-x: auto;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.user-table th {
    padding: 12px 18px;
    color: var(--text-muted);
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.user-table td {
    padding: 16px 18px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

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

.user-table tbody tr:hover {
    background: var(--surface-hover);
}

.user-identity {
    display: flex;
    min-width: 180px;
    align-items: center;
    gap: 11px;
}

.user-identity > span:last-child {
    display: grid;
    min-width: 0;
}

.user-identity strong {
    overflow-wrap: anywhere;
}

.user-identity small {
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

.user-avatar {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 50%;
}

.role-badge,
.status-badge {
    display: inline-flex;
    min-height: 28px;
    padding: 4px 9px;
    align-items: center;
    gap: 5px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.role-badge {
    color: #3f5960;
    background: #edf2f3;
}

.role-admin {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.status-active {
    color: #17663c;
    background: #e8f6ee;
}

.status-pending {
    color: var(--warning-text);
    background: var(--warning-soft);
}

.status-suspended {
    color: var(--danger);
    background: #fff1f0;
}

.login-limit-note {
    display: flex;
    margin-top: 6px;
    align-items: center;
    gap: 4px;
    color: var(--warning-text);
    font-size: 12px;
    line-height: 1.35;
    white-space: nowrap;
}

.table-empty-value {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
}

.user-row-action {
    margin: 0;
}

.button-compact {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
}

.admin-empty-state {
    display: grid;
    min-height: 300px;
    padding: 36px 24px;
    place-items: center;
    align-content: center;
    color: var(--text-muted);
    text-align: center;
}

.admin-empty-state .bi {
    color: #9db0b5;
    font-size: 36px;
}

.admin-empty-state h3 {
    margin: 12px 0 3px;
    color: var(--text);
    font-size: 17px;
}

.admin-empty-state p {
    margin: 0;
    font-size: 14px;
}

.create-user-panel {
    scroll-margin-top: calc(var(--topbar-height) + 18px);
}

.create-user-form {
    display: grid;
    gap: 18px;
    padding: 22px 24px 24px;
}

.create-user-panel .form-error-summary {
    margin: 20px 24px 0;
}

.role-fieldset {
    min-width: 0;
    padding: 0;
    margin: 0;
    border: 0;
}

.role-fieldset legend {
    padding: 0;
    margin-bottom: 8px;
    font-weight: 700;
}

.role-options {
    display: grid;
    gap: 10px;
}

.role-choice {
    display: grid;
    min-height: 72px;
    padding: 12px;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    cursor: pointer;
}

.role-choice:hover {
    background: var(--surface-hover);
}

.role-choice:has(input:checked) {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.role-choice:has(input:focus-visible) {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.role-choice input {
    width: 18px;
    height: 18px;
    margin: 3px 0 0;
    accent-color: var(--primary);
}

.role-choice > span {
    display: grid;
    gap: 3px;
}

.role-choice small {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
}

.create-user-submit {
    width: 100%;
    margin-top: 2px;
}

@media (max-width: 1000px) {
    .admin-users-grid {
        grid-template-columns: 1fr;
    }

    .create-user-panel {
        width: min(600px, 100%);
    }
}

@media (max-width: 767px) {
    .auth-page {
        grid-template-rows: var(--topbar-height) minmax(0, 1fr);
    }

    .auth-brandbar {
        padding: 0 16px;
    }

    .auth-shell {
        padding: 28px 16px 40px;
        place-items: start center;
    }

    .auth-card {
        padding: 26px 22px;
    }

    .admin-app-shell {
        display: block;
    }

    .admin-main {
        padding: 28px 16px 42px;
    }

    .admin-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 16px;
    }

    .admin-header > .button {
        width: 100%;
    }

    .current-user-copy {
        display: none;
    }

    .topbar-account {
        gap: 6px;
    }

    .button-topbar span {
        position: absolute;
        overflow: hidden;
        width: 1px;
        height: 1px;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .button-topbar {
        width: 44px;
        padding: 0;
    }

    .one-time-setup {
        grid-template-columns: 1fr;
    }

    .one-time-setup-icon {
        width: 38px;
        height: 38px;
    }

    .panel-header,
    .create-user-form {
        padding-right: 18px;
        padding-left: 18px;
    }

    .create-user-panel .form-error-summary {
        margin-right: 18px;
        margin-left: 18px;
    }

    .user-table-wrapper {
        overflow: visible;
        padding: 12px;
    }

    .user-table,
    .user-table tbody,
    .user-table tr,
    .user-table td {
        display: block;
        width: 100%;
    }

    .user-table thead {
        position: absolute;
        overflow: hidden;
        width: 1px;
        height: 1px;
        margin: -1px;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .user-table tbody {
        display: grid;
        gap: 12px;
    }

    .user-table tbody tr {
        padding: 8px 12px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 9px;
    }

    .user-table td {
        display: grid;
        padding: 9px 0;
        grid-template-columns: 108px minmax(0, 1fr);
        align-items: center;
        gap: 12px;
        border-bottom: 1px solid var(--border);
    }

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

    .user-table td::before {
        color: var(--text-muted);
        content: attr(data-label);
        font-size: 12px;
        font-weight: 700;
    }

    .user-identity {
        min-width: 0;
    }
}

@media (max-width: 380px) {
    .auth-shell {
        padding-right: 12px;
        padding-left: 12px;
    }

    .auth-card {
        padding: 24px 18px;
    }

    .auth-heading {
        align-items: flex-start;
    }

    .auth-icon {
        width: 46px;
        height: 46px;
        font-size: 22px;
    }

    .admin-page .app-rail {
        padding-right: 6px;
        padding-left: 6px;
    }

    .admin-page .rail-button {
        width: 44px;
        min-height: 44px;
    }

    .admin-page .rail-list,
    .admin-page .rail-footer {
        gap: 2px;
    }

    .admin-main {
        padding-right: 12px;
        padding-left: 12px;
    }

    .user-table td {
        grid-template-columns: 94px minmax(0, 1fr);
    }
}

@media (forced-colors: active) {
    .auth-card,
    .admin-panel,
    .one-time-setup,
    .role-choice,
    .user-table tbody tr {
        border: 1px solid CanvasText;
    }

    .role-choice:has(input:checked) {
        border: 3px solid Highlight;
    }
}

/* Administrator AI integration settings */
.ai-settings-panel {
    max-width: 920px;
}

.ai-settings-panel .panel-header {
    align-items: flex-start;
    gap: 20px;
}

.ai-settings-panel .panel-header > .status-badge {
    flex: 0 0 auto;
    margin-top: 4px;
}

.ai-settings-body {
    padding: 24px;
}

.ai-setting-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.ai-setting-summary > div {
    display: grid;
    gap: 5px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-subtle);
}

.ai-setting-label {
    color: var(--text-muted);
    font-size: 11px;
}

.ai-setting-summary strong {
    color: var(--text);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.ai-setting-summary code {
    color: var(--primary);
    font-size: 12px;
}

.ai-settings-form {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.ai-settings-form .form-field {
    flex: 1;
    min-width: 0;
}

.ai-settings-form .button {
    flex: 0 0 auto;
}

.ai-settings-clear {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.ai-settings-clear p {
    margin: 0;
    color: var(--text-muted);
    font-size: 12px;
}

.button-outline-danger {
    color: var(--danger);
    border-color: #e4b9be;
    background: #fff;
}

.form-notice {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 920px;
    margin: 0 0 16px;
    padding: 12px 16px;
    border: 1px solid #b9dfcc;
    border-radius: 9px;
    background: #effaf4;
    color: #126b49;
    font-size: 12px;
    font-weight: 700;
}

.admin-help-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 920px;
    margin-top: 16px;
    padding: 16px 18px;
    border: 1px solid #d7e3f5;
    border-radius: 10px;
    background: #f5f9ff;
    color: #31547d;
}

.admin-help-card > i {
    margin-top: 2px;
    color: var(--primary);
    font-size: 18px;
}

.admin-help-card strong,
.admin-help-card p {
    display: block;
}

.admin-help-card strong {
    font-size: 12px;
}

.admin-help-card p {
    margin: 4px 0 0;
    font-size: 11px;
    line-height: 1.7;
}

@media (max-width: 650px) {
    .ai-setting-summary {
        grid-template-columns: 1fr;
    }

    .ai-settings-form,
    .ai-settings-clear {
        align-items: stretch;
        flex-direction: column;
    }

    .ai-settings-form .button,
    .ai-settings-clear .button {
        width: 100%;
    }
}
