:root {
    --ink: #20312c;
    --muted: #6f7c77;
    --line: #dce3df;
    --paper: #ffffff;
    --canvas: #f2f5f1;
    --green: #1e6c52;
    --green-dark: #15513e;
    --green-soft: #e5f2eb;
    --amber: #a46813;
    --amber-soft: #fff4d9;
    --red: #a33d37;
    --red-soft: #fff0ef;
    --shadow: 0 18px 48px rgba(29, 53, 44, 0.09);
    font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
code { padding: .12rem .35rem; border-radius: 5px; background: #eef1ef; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
    margin: 0 0 .35rem;
    color: var(--green);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.center-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
    background:
        radial-gradient(circle at 20% 20%, rgba(69, 134, 105, .14), transparent 28rem),
        radial-gradient(circle at 85% 85%, rgba(190, 156, 79, .12), transparent 24rem),
        #eef3ef;
}

.login-card {
    width: min(440px, 100%);
    padding: 2.5rem;
    border: 1px solid rgba(255, 255, 255, .8);
    border-radius: 24px;
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow);
}

.login-card h1 { margin: .25rem 0 .75rem; font-size: 1.75rem; }
.brand-mark {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    margin-bottom: 1rem;
    border-radius: 18px;
    color: white;
    font-family: serif;
    font-size: 1.65rem;
    background: var(--green);
    box-shadow: 0 10px 26px rgba(30, 108, 82, .25);
}
.brand-mark.small { width: 40px; height: 40px; margin: 0; border-radius: 12px; font-size: 1.15rem; }

.login-form { display: grid; gap: 1rem; margin-top: 1.6rem; }
label { display: grid; gap: .38rem; color: #4a5853; font-size: .88rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-width: 0;
    padding: .78rem .82rem;
    border: 1px solid #cfd9d4;
    border-radius: 9px;
    color: var(--ink);
    font-size: 1rem;
    background: #fff;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(30, 108, 82, .12);
}
textarea { resize: vertical; }

.button {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem .9rem;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--ink);
    font-size: .82rem;
    font-weight: 800;
    text-decoration: none;
    background: #fff;
}
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.danger { color: #fff; background: var(--red); }
.button.danger:hover { background: #842d28; }
.button.subtle { border-color: #cfd9d4; background: #fff; }
.button.subtle:hover { border-color: var(--green); color: var(--green); }
.button.ghost { color: var(--muted); background: transparent; }
.button.ghost:hover { color: var(--ink); background: #edf1ef; }
.button.tiny { min-height: 29px; padding: .3rem .58rem; font-size: .72rem; }
.button.wide { width: 100%; }
.button:disabled { opacity: .55; cursor: wait; }

.alert, .global-notice, .status-card {
    padding: .85rem 1rem;
    border-radius: 10px;
    font-size: .83rem;
}
.alert.danger, .status-card.danger { color: #7d2c27; background: var(--red-soft); border: 1px solid #f2c7c3; }
.status-card.warning { color: #80500d; background: var(--amber-soft); border: 1px solid #eed79e; }
.status-card.success { color: var(--green-dark); background: var(--green-soft); border: 1px solid #bfddce; }
.global-notice {
    border-radius: 0;
    color: #75500f;
    text-align: center;
    background: var(--amber-soft);
    border-bottom: 1px solid #ecd598;
}
.setup-steps { padding-left: 1.3rem; line-height: 1.9; }

.app-shell { min-height: 100vh; }
.topbar {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand strong, .brand span { display: block; }
.brand > div span { margin-top: .1rem; color: var(--muted); font-size: .68rem; }
.top-actions { display: flex; align-items: center; gap: .5rem; }
.model-pill {
    padding: .35rem .65rem;
    border-radius: 999px;
    color: var(--green-dark);
    font: 700 .7rem ui-monospace, monospace;
    background: var(--green-soft);
}

.workspace {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 1rem;
    height: calc(100vh - 68px);
    padding: 1rem;
}
.sidebar { display: flex; min-height: 0; flex-direction: column; gap: 1rem; }
.panel, .content-panel {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--paper);
    box-shadow: 0 8px 30px rgba(31, 54, 46, .045);
}
.panel { padding: 1rem; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.panel-heading.compact { align-items: center; }
.panel-heading h2 { margin: 0; font-size: 1rem; }
.step-badge {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    color: var(--green);
    font-size: .74rem;
    font-weight: 900;
    background: var(--green-soft);
}
.upload-panel { flex: 0 0 auto; }
.history-panel { display: flex; min-height: 180px; flex: 1; flex-direction: column; overflow: hidden; }

.drop-zone {
    min-height: 114px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: .28rem;
    padding: 1rem;
    border: 1.5px dashed #aebdb6;
    border-radius: 12px;
    color: var(--green);
    text-align: center;
    background: #f8faf8;
    transition: .15s;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); background: var(--green-soft); }
.drop-zone small { color: var(--muted); font-weight: 500; }
.drop-icon { font-size: 1.25rem; line-height: 1; }

.editor-wrap { margin-top: .85rem; }
.canvas-stage {
    display: grid;
    max-height: 42vh;
    place-items: center;
    overflow: auto;
    border-radius: 10px;
    background: #17201c;
}
#editor-canvas { display: block; max-width: 100%; max-height: 42vh; cursor: crosshair; }
.editor-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-top: .55rem; }
.tool-button, .icon-button {
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #4e5d57;
    background: #fff;
}
.tool-button { padding: .45rem .3rem; font-size: .7rem; font-weight: 800; }
.tool-button:hover, .icon-button:hover { border-color: var(--green); color: var(--green); }
.icon-button { width: 31px; height: 31px; display: inline-grid; place-items: center; padding: 0; }
.range-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin: .7rem 0; }
.range-grid input { padding: 0; }
.hint { margin: .55rem 0 .75rem; color: var(--muted); font-size: .7rem; line-height: 1.55; }

.job-list { min-height: 0; overflow: auto; }
.job-item {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .3rem .6rem;
    padding: .72rem;
    border: 0;
    border-top: 1px solid #edf0ee;
    color: inherit;
    text-align: left;
    background: #fff;
}
.job-item:hover, .job-item.active { background: #f3f8f5; }
.job-name { overflow: hidden; font-size: .78rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.job-meta { color: var(--muted); font-size: .66rem; }
.status-dot { align-self: start; padding: .23rem .48rem; border-radius: 999px; font-size: .62rem; font-weight: 900; }
.status-dot.confirmed { color: var(--green-dark); background: var(--green-soft); }
.status-dot.review, .status-dot.uploaded { color: #795111; background: var(--amber-soft); }
.status-dot.retry_waiting { color: #8b332e; background: var(--red-soft); }
.status-dot.analyzing { color: #375f87; background: #e8f2fb; }
.empty-list { padding: 1.5rem .5rem; color: var(--muted); font-size: .78rem; text-align: center; }

.content-panel { min-width: 0; min-height: 0; overflow: hidden; }
.empty-state {
    height: 100%;
    display: grid;
    place-items: center;
    align-content: center;
    padding: 2rem;
    text-align: center;
}
.empty-state h2 { margin: .5rem 0; font-size: 1.25rem; }
.empty-state p { max-width: 520px; margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.7; }
.empty-illustration { color: #a8bab1; font-family: serif; font-size: 5rem; line-height: 1; }

.review-view { height: 100%; display: flex; min-height: 0; flex-direction: column; }
.review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--line);
}
.review-header h1 { margin: 0; font-size: 1.15rem; }
.review-header p { margin: .2rem 0 0; font-size: .7rem; }
.review-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .45rem; }
#status-banner { padding: .65rem 1rem 0; }
.review-grid {
    display: grid;
    min-height: 0;
    flex: 1;
    grid-template-columns: minmax(320px, .7fr) minmax(740px, 1.6fr);
    gap: 0;
}
.image-pane, .form-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.image-pane { border-right: 1px solid var(--line); background: #222c28; }
.pane-title {
    min-height: 43px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .62rem .8rem;
    border-bottom: 1px solid var(--line);
    font-size: .75rem;
    font-weight: 900;
    background: #fafcfa;
}
.image-pane .pane-title { color: #dce7e2; border-color: #34413b; background: #28332e; }
.image-scroller { flex: 1; min-height: 0; overflow: auto; text-align: center; }
#review-image { max-width: 100%; height: auto; vertical-align: top; }
.form-pane { overflow: hidden; background: #f7f9f7; }
.form-pane.csv-expanded { overflow: auto; }
.form-pane > .warning-list, .form-pane > .record-list, .form-pane > .duplicate-box, .form-pane > .csv-preview { margin-left: 1rem; margin-right: 1rem; }
.record-list { flex: 1; min-height: 360px; padding-bottom: 1rem; overflow: auto; }
.form-pane.csv-expanded .record-list {
    flex: 0 1 auto;
    min-height: 180px;
    max-height: min(42vh, 520px);
}

.warning-list {
    flex: 0 0 auto;
    display: grid;
    gap: .45rem;
    margin-top: .65rem;
    padding: .58rem;
    border: 1px solid #edd28d;
    border-radius: 10px;
    background: #fffaf0;
}
.warning-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
.warning-summary-text {
    min-width: 0;
    display: grid;
    gap: .12rem;
}
.warning-summary-text strong { color: #7b4b0d; font-size: .78rem; }
.warning-summary-text span { color: #85652d; font-size: .68rem; line-height: 1.45; }
.warning-items {
    display: grid;
    gap: .35rem;
    max-height: min(24vh, 180px);
    overflow: auto;
    padding-right: .15rem;
}
.warning-item { padding: .5rem .6rem; border-left: 3px solid #d09534; border-radius: 7px; color: #745016; font-size: .7rem; background: #fff4d9; }
.duplicate-box { margin-top: .65rem; padding: .75rem; border: 1px solid #edd28d; border-radius: 9px; background: var(--amber-soft); font-size: .73rem; }
.duplicate-box ul { margin: .45rem 0; padding-left: 1.2rem; }

.record-card {
    margin-top: .95rem;
    padding: 1.1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(34, 55, 47, .035);
}
.record-card.has-warning { border-color: #ddb969; }
.record-head, .record-head-actions, .detail-heading, .detail-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
}
.record-head { margin-bottom: .75rem; }
.record-number { font-size: 1rem; }
.record-head-actions { justify-content: flex-end; }
.check-label { display: inline-flex; grid-template-columns: auto 1fr; align-items: center; gap: .4rem; font-size: .82rem; }
.check-label input { width: auto; }
.danger-text { color: var(--red); }
.field-grid { display: grid; gap: .75rem; }
.field-grid.five { grid-template-columns: 1.25fr .8fr .9fr .75fr .7fr; }
.field-grid.six { grid-template-columns: 1.15fr .85fr 1fr .85fr .6fr .7fr; }
.field-grid.two { grid-template-columns: 1.25fr .75fr; margin-top: .6rem; }
.inline-check { align-content: end; padding-bottom: .55rem; }
.review-flags { display: grid; grid-template-columns: auto 1fr; gap: .6rem; align-items: center; margin-top: .6rem; }
.review-flags input[type="text"] { padding-block: .5rem; }
.invalid-field { border-color: #cf7b72 !important; background: #fff7f6 !important; }

.detail-block { margin-top: .85rem; padding-top: .75rem; border-top: 1px dashed #ccd8d2; }
.detail-heading { margin-bottom: .5rem; font-size: .76rem; }
.detail-list { display: grid; gap: .55rem; }
.detail-row { padding: .65rem; border: 1px solid #dfe7e3; border-radius: 9px; background: #f9fbfa; }
.detail-main-grid { display: grid; grid-template-columns: .9fr .95fr 1.25fr .7fr .72fr .82fr .66fr .76fr .82fr 1.1fr; gap: .55rem; }
.detail-row label { font-size: .74rem; }
.detail-row input, .detail-row select { padding: .62rem; font-size: .88rem; }
.detail-row > label { margin-top: .45rem; }
.detail-foot { justify-content: flex-start; margin-top: .45rem; }
.detail-foot .detail-review-reason { flex: 1; }
.detail-foot .remove-detail { margin-left: auto; }

.csv-preview {
    flex: 0 0 auto;
    width: calc(100% - 2rem);
    min-width: 0;
    margin-top: .75rem;
    margin-bottom: .8rem;
    padding: .85rem;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}
.csv-preview-head, .csv-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    min-width: 0;
    flex-wrap: wrap;
}
.csv-preview-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.csv-preview-head h2 { margin: 0; font-size: .95rem; }
.csv-preview-grid {
    display: grid;
    gap: .9rem;
    min-width: 0;
    max-height: min(56vh, 640px);
    margin-top: .75rem;
    padding-right: .15rem;
    overflow: auto;
}
.csv-card {
    display: grid;
    gap: .45rem;
    min-width: 0;
}
.csv-card-head strong { font-size: .76rem; }
.csv-card-head div { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
.csv-card textarea {
    width: 100%;
    max-width: 100%;
    height: clamp(170px, 24vh, 280px);
    min-height: 160px;
    overflow: auto;
    font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: rgba(18, 31, 26, .55);
    backdrop-filter: blur(3px);
}
.busy-card { min-width: 250px; padding: 1.5rem; border-radius: 16px; text-align: center; background: #fff; box-shadow: var(--shadow); }
.spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto .8rem;
    border: 4px solid #dbe8e1;
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
    .workspace { grid-template-columns: 300px minmax(0, 1fr); }
    .review-grid { grid-template-columns: 1fr; overflow: auto; }
    .image-pane { min-height: 55vh; border-right: 0; border-bottom: 1px solid var(--line); }
    .form-pane { min-height: 70vh; }
    .detail-main-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 760px) {
    .topbar { align-items: flex-start; }
    .top-actions { justify-content: flex-end; flex-wrap: wrap; }
    .model-pill { display: none; }
    .workspace { display: block; height: auto; padding: .6rem; }
    .sidebar { display: block; }
    .history-panel { margin-top: .6rem; max-height: 260px; }
    .content-panel { min-height: 70vh; margin-top: .6rem; }
    .review-view { height: auto; }
    .review-header { align-items: flex-start; flex-direction: column; }
    .review-grid { display: block; }
    .form-pane, .form-pane.csv-expanded { overflow: visible; }
    .form-pane.csv-expanded .record-list { max-height: none; }
    .csv-preview { width: auto; }
    .csv-preview-grid { max-height: none; overflow: visible; }
    .field-grid.five, .field-grid.six, .field-grid.two { grid-template-columns: repeat(2, 1fr); }
    .detail-main-grid { grid-template-columns: repeat(2, 1fr); }
    .image-pane { min-height: 50vh; }
}
