/* ─────────────────────────────────────────────────────────────────────────────
   DataON 프로토타입 UI 스타일 — Phase 6D
   ───────────────────────────────────────────────────────────────────────────── */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: system-ui, -apple-system, sans-serif;
    color: #333;
    background-color: #f5f5f5;
}

/* ── 헤더 ───────────────────────────────────────────────────────────────────── */

.header {
    background-color: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 14px 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 20px;
    font-weight: 700;
    color: #007aff;
}

.header-sub {
    font-weight: 400;
    color: #444;
    font-size: 18px;
}

.header-badge {
    font-size: 11px;
    background-color: #e3f2fd;
    color: #007aff;
    border: 1px solid #007aff;
    border-radius: 4px;
    padding: 2px 7px;
    font-weight: 600;
    white-space: nowrap;
}

/* ── 새로고침 버튼 ───────────────────────────────────────────────────────────── */

.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid #007aff;
    background: #fff;
    color: #007aff;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-refresh:hover { background: #007aff; color: #fff; }
.btn-refresh:disabled { opacity: 0.4; cursor: default; }

.btn-refresh-icon {
    font-size: 14px;
    display: inline-block;
    transition: transform 0.4s ease;
}
.btn-refresh.spinning .btn-refresh-icon {
    transform: rotate(360deg);
}

/* ── 뷰 전환 ─────────────────────────────────────────────────────────────────── */

.view {
    display: none;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ── Landing 화면 ────────────────────────────────────────────────────────────── */

#viewLanding.active {
    display: block;
}

.landing-wrap {
    max-width: 1100px;
    margin: 32px auto;
    padding: 0 24px;
}

.landing-desc {
    font-size: 15px;
    color: #555;
    margin-bottom: 20px;
}

/* ── 워크플로우 카드 그리드 ──────────────────────────────────────────────────── */

.workflow-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.workflow-card {
    background-color: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.2s;
}

.workflow-card:hover {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.workflow-card.unavailable {
    opacity: 0.6;
}

.card-icon {
    font-size: 36px;
    line-height: 1;
}

.card-body {
    flex: 1;
}

.card-code {
    display: inline-block;
    font-size: 11px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    background: #eef3fb;
    color: #2962ff;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
    font-weight: 500;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #222;
}

.card-desc {
    font-size: 13px;
    color: #666;
    min-height: 18px;
}

.card-status {
    font-size: 12px;
    margin-top: 8px;
    font-weight: 500;
}

.card-status.available {
    color: #28a745;
}

.card-status.unavailable {
    color: #999;
}

.card-start {
    width: 100%;
}

/* ── 버튼 ─────────────────────────────────────────────────────────────────────── */

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: #007aff;
    color: #fff;
}

.btn-primary:hover {
    background-color: #0051d5;
}

.btn-secondary {
    background-color: #e9ecef;
    color: #333;
}

.btn-secondary:hover {
    background-color: #dee2e6;
}

.btn-success {
    background-color: #28a745;
    color: #fff;
}

.btn-success:hover {
    background-color: #218838;
}

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

.btn-full {
    width: 100%;
}

/* ── Workflow 채팅 화면 ──────────────────────────────────────────────────────── */

#viewWorkflow.active {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 57px);
}

.workflow-header {
    display: flex;
    align-items: center;
    gap: 16px;
    background-color: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 10px 20px;
}

.workflow-title-label {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

/* ── 채팅 레이아웃 ──────────────────────────────────────────────────────────── */

.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── 채팅 패널 (좌) ─────────────────────────────────────────────────────────── */

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e0e0;
    background-color: #fff;
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 90%;
}

.chat-msg-user {
    align-self: flex-end;
}

.chat-msg-assistant,
.chat-msg-system,
.chat-msg-error {
    align-self: flex-start;
}

.msg-role {
    font-size: 11px;
    font-weight: 600;
    color: #999;
    padding: 0 2px;
}

.chat-msg-user .msg-role {
    text-align: right;
}

.msg-content {
    display: block;
    padding: 9px 13px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-msg-user .msg-content {
    background-color: #007aff;
    color: #fff;
    border-radius: 8px 8px 2px 8px;
}

.chat-msg-assistant .msg-content {
    background-color: #f0f0f0;
    color: #222;
    border-radius: 8px 8px 8px 2px;
}

.chat-msg-system .msg-content {
    background-color: #d4edda;
    color: #155724;
    border-radius: 8px;
    font-size: 13px;
}

.chat-msg-error .msg-content {
    background-color: #f8d7da;
    color: #721c24;
    border-radius: 8px;
    font-size: 13px;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e0e0e0;
    background-color: #fafafa;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
}

.chat-input:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

/* ── 결과 패널 (우) ─────────────────────────────────────────────────────────── */

.result-panel {
    width: 420px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background-color: #fafafa;
    overflow: hidden;
}

.result-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.result-placeholder {
    padding-top: 20px;
}

.submit-area {
    padding: 12px 16px;
    border-top: 1px solid #e0e0e0;
    background-color: #fff;
}

.submit-area.hidden {
    display: none;
}

/* ── DataON 폼 ───────────────────────────────────────────────────────────────── */

.form-wrap {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #444;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 6px;
    margin-bottom: 4px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px 10px;
    border-radius: 5px;
    border-left: 3px solid #ccc;
    background-color: #fff;
}

/* 신뢰도 색상 */
.form-field.field-high {
    border-left-color: #28a745;
    background-color: #f0fdf4;
}

.form-field.field-mid {
    border-left-color: #ffc107;
    background-color: #fffdf0;
}

.form-field.field-low {
    border-left-color: #ccc;
    background-color: #fafafa;
}

.field-label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    gap: 4px;
}

.confidence-tag {
    font-size: 10px;
    font-weight: 700;
    border-radius: 3px;
    padding: 1px 5px;
}

.confidence-tag.conf-high {
    background-color: #d4edda;
    color: #155724;
}

.confidence-tag.conf-mid {
    background-color: #fff3cd;
    color: #856404;
}

.confidence-tag.conf-low {
    background-color: #e9ecef;
    color: #666;
}

.source-tooltip {
    font-size: 11px;
    color: #007aff;
    cursor: help;
    user-select: none;
}

.field-input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    background-color: transparent;
}

.field-input:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
    background-color: #fff;
}

/* ── 고급 필드 접힌 섹션 ─────────────────────────────────────────────────────── */

.advanced-fields {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background-color: #fff;
}

.advanced-fields summary {
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    user-select: none;
}

.advanced-fields summary:hover {
    background-color: #f5f5f5;
}

.advanced-fields .field-group {
    padding: 10px 12px;
    border-top: 1px solid #e0e0e0;
}

/* ── 경고/알림 메시지 ─────────────────────────────────────────────────────────── */

.alert {
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 12px;
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* ── 유틸리티 ─────────────────────────────────────────────────────────────────── */

.hidden {
    display: none !important;
}

.text-muted {
    color: #999;
    font-size: 13px;
}

/* ── 설정 버튼 ──────────────────────────────────────────────────────────────── */

.btn-settings {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid #666;
    background: #fff;
    color: #444;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.btn-settings:hover { background: #444; color: #fff; }

/* ── 모달 공통 ───────────────────────────────────────────────────────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}

.modal-box {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    width: 480px;
    max-width: 96vw;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e8e8e8;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #222;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover { color: #333; }

.modal-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    max-height: 60vh;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid #e8e8e8;
    background: #fafafa;
}

/* ── 설정 폼 ─────────────────────────────────────────────────────────────────── */

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-field-readonly .settings-input {
    background: #f5f5f5;
    color: #999;
}

.settings-label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-input {
    padding: 7px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
}
.settings-input:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.settings-hint {
    font-size: 11px;
    color: #999;
}
.settings-hint code {
    background: #f0f0f0;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
}

.settings-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
}
.settings-badge-override {
    background: #e3f2fd;
    color: #007aff;
    border: 1px solid #90caf9;
}
.settings-badge-default {
    background: #f5f5f5;
    color: #888;
    border: 1px solid #ddd;
}
.settings-badge-dynamic {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
}

/* ── 설정 토스트 ─────────────────────────────────────────────────────────────── */

.settings-toast {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    font-size: 13px;
    padding: 8px 18px;
    border-radius: 20px;
    white-space: nowrap;
    pointer-events: none;
}
.settings-toast-error { background: #c62828; }

/* ── 첫 실행 설정 게이트 ─────────────────────────────────────────────────────── */

#viewSetupGate.active {
    display: block;
}

.setup-gate-box {
    max-width: 520px;
    margin: 48px auto;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 32px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.setup-gate-title {
    font-size: 20px;
    font-weight: 700;
    color: #222;
    margin-bottom: 8px;
}

.setup-gate-desc {
    font-size: 14px;
    color: #666;
    margin-bottom: 24px;
}

.setup-gate-section {
    margin-bottom: 20px;
}

.setup-gate-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #444;
    border-bottom: 1px solid #e8e8e8;
    padding-bottom: 6px;
    margin-bottom: 12px;
}

.setup-gate-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setup-gate-footer {
    margin-top: 24px;
}

/* ── 설정 모달 섹션 분리 ─────────────────────────────────────────────────────── */

.settings-section-title {
    font-size: 12px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.settings-section-divider {
    border-top: 1px solid #e8e8e8;
    margin: 12px 0;
}

/* ── 반응형 ────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .chat-layout {
        flex-direction: column;
    }

    .result-panel {
        width: 100%;
        height: 300px;
        border-top: 1px solid #e0e0e0;
        border-right: none;
    }

    #viewWorkflow.active {
        height: auto;
        min-height: calc(100vh - 57px);
    }
}
