/* ===== 기본 리셋 및 변수 ===== */
:root {
    --primary: #1A73E8;
    --primary-light: #E8F0FE;
    --teal: #00897B;
    --teal-light: #E0F2F1;
    --purple: #7B1FA2;
    --purple-light: #F3E5F5;
    --green: #43A047;
    --green-light: #E8F5E9;
    --red: #E53935;
    --red-light: #FFEBEE;
    --orange: #FB8C00;
    --bg: #F5F7FA;
    --card-bg: #FFFFFF;
    --text: #212121;
    --text-secondary: #757575;
    --border: #E0E0E0;
    --sidebar-bg: #1E293B;
    --sidebar-text: #CBD5E1;
    --sidebar-active: #3B82F6;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Noto Sans KR', sans-serif; background: var(--bg); color: var(--text); }

/* ===== 레이아웃 ===== */
.app { display: flex; min-height: 100vh; }

/* ===== 사이드바 ===== */
.sidebar {
    width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: fixed; height: 100vh; z-index: 10;
}
.sidebar-header { padding: 28px 20px 20px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-header .logo { font-size: 40px; margin-bottom: 4px; }
.sidebar-header h2 { font-size: 20px; color: #fff; font-weight: 700; }
.sidebar-header .robot-id { font-size: 12px; color: #94A3B8; letter-spacing: 1px; }
.nav-menu { list-style: none; padding: 12px 0; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 14px 24px;
    cursor: pointer; transition: all 0.2s; font-size: 14px; font-weight: 400;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; border-radius: 0 8px 8px 0; margin-right: 8px; }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }

/* ===== 메인 콘텐츠 ===== */
.content { flex: 1; margin-left: 240px; padding: 32px 40px; max-width: 1100px; }
.page { display: none; }
.page.active { display: block; }
.page h1 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.page-desc { color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }

/* ===== 카드 ===== */
.card {
    background: var(--card-bg); border-radius: var(--radius); padding: 24px;
    box-shadow: var(--shadow); margin-bottom: 20px; border: 1px solid var(--border);
}
.card h3 { font-size: 17px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.card-header { display: flex; justify-content: space-between; align-items: center; }

/* ===== 통계 카드 ===== */
.cards-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card {
    background: var(--card-bg); border-radius: var(--radius); padding: 20px;
    box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px;
    border: 1px solid var(--border);
}
.stat-icon {
    width: 48px; height: 48px; border-radius: 12px; display: flex;
    align-items: center; justify-content: center; font-size: 22px;
}
.stat-icon.purple { background: var(--purple-light); }
.stat-icon.blue { background: var(--primary-light); }
.stat-icon.teal { background: var(--teal-light); }
.stat-icon.green { background: var(--green-light); }
.stat-value { font-size: 24px; font-weight: 700; display: block; }
.stat-label { font-size: 12px; color: var(--text-secondary); }

/* ===== 정보 그리드 ===== */
.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.info-item { display: flex; justify-content: space-between; padding: 10px 16px; background: var(--bg); border-radius: 8px; }
.info-label { font-size: 13px; color: var(--text-secondary); }
.info-value { font-size: 14px; font-weight: 500; }

/* ===== 버튼 ===== */
.btn {
    padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500;
    cursor: pointer; border: none; transition: all 0.2s; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1565C0; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #C62828; }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 12px; }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 20px; }

/* ===== 폼 ===== */
.form-group { margin-bottom: 16px; flex: 1; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-row { display: flex; gap: 16px; }
.input {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; font-family: inherit; background: #fff; transition: border 0.2s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,0.1); }
.textarea { min-height: 80px; resize: vertical; }
.text-muted { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }

/* ===== 토글 ===== */
.toggle { position: relative; display: inline-block; width: 48px; height: 26px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc; border-radius: 26px; transition: 0.3s;
}
.toggle-slider:before {
    content: ""; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%; transition: 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(22px); }

/* ===== 그리드 ===== */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

/* ===== 라이브러리 카드 ===== */
.lib-card {
    background: var(--card-bg); border-radius: var(--radius); padding: 20px;
    box-shadow: var(--shadow); border: 1px solid var(--border); cursor: pointer;
    transition: all 0.2s;
}
.lib-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.lib-card h4 { font-size: 16px; margin-bottom: 6px; }
.lib-card .lib-count { font-size: 12px; color: var(--text-secondary); }
.lib-card .lib-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ===== 지식/로그 아이템 ===== */
.item-card {
    background: var(--card-bg); border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow); margin-bottom: 12px; border: 1px solid var(--border);
}
.item-card .item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.item-card .item-title { font-weight: 600; font-size: 14px; }
.item-card .item-content { font-size: 13px; color: var(--text-secondary); line-height: 1.6; white-space: pre-wrap; }
.item-card .item-meta { font-size: 11px; color: #9E9E9E; margin-top: 8px; }

/* ===== 구분선 입력 (혼잣말 대사) ===== */
.phrase-item {
    display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.phrase-item input { flex: 1; }
.phrase-num { font-size: 12px; color: var(--text-secondary); width: 24px; text-align: right; }

/* ===== 라이브러리 아이템 편집 ===== */
.lib-item-edit {
    background: var(--bg); border-radius: 8px; padding: 14px; margin-bottom: 10px;
    border: 1px solid var(--border);
}
.lib-item-edit .item-header { display: flex; gap: 8px; margin-bottom: 8px; }
.lib-item-edit input { flex: 1; }

/* ===== Toast ===== */
.toast {
    position: fixed; bottom: 24px; right: 24px; padding: 14px 24px; border-radius: 8px;
    background: #323232; color: #fff; font-size: 14px; opacity: 0;
    transition: opacity 0.3s; pointer-events: none; z-index: 1000;
}
.toast.show { opacity: 1; }

/* ===== 반응형 ===== */
@media (max-width: 900px) {
    .sidebar { width: 200px; }
    .content { margin-left: 200px; padding: 24px; }
    .cards-row { grid-template-columns: repeat(2, 1fr); }
    .form-row { flex-direction: column; gap: 0; }
}
@media (max-width: 600px) {
    .sidebar { width: 60px; }
    .sidebar-header h2, .sidebar-header .robot-id, .nav-item span:last-child { display: none; }
    .content { margin-left: 60px; padding: 16px; }
    .cards-row { grid-template-columns: 1fr; }
}
