:root {
    color-scheme: light;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
    background: #f5f6f8;
    color: #17191d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f5f6f8;
}

a {
    color: inherit;
}

.container {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.site-header {
    background: #111318;
    color: white;
    border-bottom: 1px solid #2b2f36;
}

.header-inner {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    color: white;
    text-decoration: none;
    font-weight: 750;
}

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

.header-actions form {
    margin: 0;
}

.header-link {
    color: #d8dbe1;
    text-decoration: none;
}

main.container {
    padding-top: 40px;
    padding-bottom: 56px;
}

.panel {
    background: white;
    border: 1px solid #e1e4e8;
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 8px 28px rgba(20, 25, 35, 0.06);
}

.login-wrap {
    min-height: calc(100vh - 180px);
    display: grid;
    place-items: center;
}

.login-panel {
    width: min(440px, 100%);
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
}

h2 {
    margin-bottom: 6px;
}

.muted {
    color: #646b76;
}

.small {
    font-size: 14px;
}

.lead {
    font-size: 18px;
    color: #4a5059;
}

.eyebrow {
    margin-bottom: 8px;
    color: #717783;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
}

.field {
    margin: 0;
}

.field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 650;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="url"],
.field input[type="password"],
.field input[type="file"],
.field textarea,
.search-form input {
    width: 100%;
    min-height: 44px;
    border: 1px solid #cbd0d8;
    border-radius: 9px;
    padding: 10px 12px;
    background: white;
    font: inherit;
}

.field textarea {
    resize: vertical;
}

.field input:focus,
.field textarea:focus,
.search-form input:focus {
    outline: 2px solid #111318;
    outline-offset: 2px;
}

.field input.ai-uncertain {
    border-color: #d8a600;
    background: #fffbea;
    box-shadow: 0 0 0 2px rgba(216, 166, 0, 0.14);
}

.field-error {
    color: #b42318;
    margin: 6px 0 0;
    font-size: 14px;
}

.field-help {
    color: #69707a;
    font-size: 13px;
    margin-bottom: 8px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 9px;
    border: 1px solid transparent;
    padding: 9px 15px;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

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

.button-primary {
    background: #111318;
    color: white;
}

.button-ai {
    min-height: 48px;
    background: #111318;
    color: white;
    padding-left: 20px;
    padding-right: 20px;
}

.button-secondary {
    background: transparent;
    border-color: #4a4f58;
    color: white;
}

.button-light {
    background: white;
    color: #111318;
}

.button-outline {
    background: white;
    border-color: #c9ced6;
    color: #24272d;
}

.button-danger {
    background: #b42318;
    color: white;
}

.full-width {
    width: 100%;
}

.flash {
    margin-bottom: 20px;
    padding: 12px 14px;
    border-radius: 9px;
}

.flash-error {
    background: #fee4e2;
    color: #912018;
}

.flash-warning {
    background: #fff4cc;
    color: #6d4c00;
}

.flash-success {
    background: #dff5e6;
    color: #176b39;
}

.page-title {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    margin-bottom: 24px;
}

.empty-state {
    text-align: center;
    padding: 56px 24px;
}

.search-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    margin-bottom: 24px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.contact-card {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    min-height: 128px;
    overflow: hidden;
    background: white;
    border: 1px solid #e0e3e7;
    border-radius: 14px;
    text-decoration: none;
    box-shadow: 0 6px 22px rgba(20, 25, 35, 0.04);
}

.contact-card:hover {
    border-color: #aeb4bc;
}

.contact-thumb {
    min-height: 100%;
    background: #eef0f3;
    display: grid;
    place-items: center;
    overflow: hidden;
}

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

.contact-initial {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #111318;
    color: white;
    font-size: 24px;
    font-weight: 800;
}

.contact-card-body {
    padding: 16px;
    overflow: hidden;
}

.contact-card-body h2,
.contact-card-body p {
    overflow-wrap: anywhere;
}

.company {
    margin-bottom: 6px;
    font-weight: 650;
}

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

.ai-capture {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 16px;
    padding-bottom: 24px;
    margin-bottom: 24px;
    border-bottom: 1px solid #e5e7eb;
}

.ai-capture-second {
    padding-bottom: 28px;
}

.capture-step {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: #111318;
    color: white;
    font-weight: 800;
    flex: 0 0 auto;
}

.capture-content h2,
.review-heading h2 {
    margin-bottom: 4px;
    font-size: 19px;
}

.file-input {
    margin-top: 8px;
}

.image-preview-wrap {
    margin-top: 14px;
}

.image-preview {
    display: block;
    width: min(560px, 100%);
    max-height: 340px;
    object-fit: contain;
    background: #eef0f3;
    border: 1px solid #dfe2e6;
    border-radius: 10px;
}

.ai-status {
    min-height: 22px;
    margin-top: 12px;
    font-size: 14px;
    font-weight: 600;
}

.ai-status-working {
    color: #475467;
}

.ai-status-success {
    color: #176b39;
}

.ai-status-warning {
    color: #8a6500;
}

.ai-status-error {
    color: #b42318;
}

.review-heading {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 22px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.field-full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 28px;
}

.current-image {
    margin-top: 14px;
}

.current-image img {
    display: block;
    width: min(420px, 100%);
    max-height: 260px;
    object-fit: contain;
    background: #f2f3f5;
    border-radius: 10px;
    border: 1px solid #e0e3e7;
}

.checkbox-row {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-weight: 500 !important;
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
    gap: 20px;
    align-items: start;
}

.detail-list {
    margin: 0;
}

.detail-list > div {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 20px;
    padding: 14px 0;
    border-bottom: 1px solid #eceef1;
}

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

.detail-list dt {
    color: #646b76;
    font-weight: 650;
}

.detail-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.detail-list .memo {
    white-space: pre-wrap;
}

.image-panel img {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    background: #f2f3f5;
    border-radius: 8px;
}

.danger-zone {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #dddfe3;
}

@media (max-width: 900px) {
    .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detail-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .container {
        width: min(100% - 22px, 1120px);
    }

    .header-inner,
    .page-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-inner {
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

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

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

    .field-full {
        grid-column: auto;
    }

    .contact-card {
        grid-template-columns: 76px minmax(0, 1fr);
    }

    .detail-list > div {
        grid-template-columns: 1fr;
        gap: 6px;
    }

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

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

    .ai-capture {
        grid-template-columns: 36px minmax(0, 1fr);
        gap: 12px;
    }

    .capture-step {
        width: 32px;
        height: 32px;
    }

    .button-ai {
        width: 100%;
    }
}

.cleanup-files {
    max-height: 360px;
    overflow: auto;
    overflow-wrap: anywhere;
    padding-left: 24px;
    line-height: 1.8;
}

.header-inner { flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.header-actions { flex-wrap: wrap; }
.field input[type="number"], .contact-search select {
    min-height: 44px; padding: 10px 12px; border: 1px solid #cbd0d8;
    border-radius: 9px; background: white; font: inherit; max-width: 100%;
}
.field input[type="number"] { width: 100%; }
.contact-search { grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) auto auto; }
.tag-picker { margin: 24px 0 0; border: 1px solid #e1e4e8; border-radius: 10px; padding: 18px; min-width: 0; }
.tag-picker legend { font-weight: 700; }
.tag-options, .tag-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tag-option { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid #cbd0d8; border-radius: 20px; cursor: pointer; overflow-wrap: anywhere; }
.tag-option:has(input:checked) { background: #e6eefb; border-color: #6386bd; }
.tag-option input { accent-color: #315b96; }
.tag-badge { display: inline-block; border-radius: 12px; padding: 3px 9px; background: #edf1f8; color: #345078; font-size: 12px; text-decoration: none; overflow-wrap: anywhere; }
.tag-create { margin-top: 24px; }
.table-scroll { overflow-x: auto; }
.tag-table { border-collapse: collapse; width: 100%; }
.tag-table th, .tag-table td { padding: 12px; border-bottom: 1px solid #e1e4e8; text-align: left; }
.tag-table td:first-child { overflow-wrap: anywhere; min-width: 140px; }
.tag-row-actions { white-space: nowrap; }
.tag-row-actions a + a { margin-left: 12px; }
@media (max-width: 640px) { .contact-search { grid-template-columns: 1fr; } }
