/* ============================================================
   UURES Web · 테마 (Light / Dark) · 모던 바이올렛
   - Light: 라벤더 배경 + 화이트 카드 + 밝은 사이드바 + 바이올렛 포인트
   - Dark : 딥 인디고 배경 + 바이올렛/시안 포인트
   ============================================================ */

/* ---------- LIGHT (기본) ---------- */
:root,
[data-theme="light"] {
    /* 브랜드 / 포인트 컬러 (하늘색) */
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --primary-soft: #e2f4fd;
    --secondary: #38bdf8;
    --glow: rgba(14, 165, 233, .34);
    --success: #28c76f;
    --success-soft: #e6f9ef;
    --success-text: #1fa85c;
    --warning: #ff9f43;
    --warning-soft: #fff2e3;
    --warning-text: #e07f1e;
    --error: #ea5455;
    --error-soft: #fdeaea;
    --error-text: #d43b3c;
    --info: #00cfe8;
    --info-soft: #e2fbfe;
    --purple: #7c4dff;
    --purple-soft: #f0eaff;

    /* 표면 / 텍스트 / 보더 */
    --bg: #f5f4fb;
    --card: #ffffff;
    --surface-2: #f7f6fd;
    --surface-3: #efedf9;
    --hover: #f3f1fd;
    --text: #2f2b50;
    --text-muted: #6b6890;
    --text-light: #9c99bd;
    --border: #ecebf6;
    --border-soft: #f3f2fb;
    --input-bg: #f6f5fc;
    --chart-grid: #efedf9;

    /* 사이드바 (밝은 모던) */
    --sidebar-bg: #ffffff;
    --sidebar-bg2: #fbfaff;
    --sidebar-text: #6b6890;
    --sidebar-muted: #a7a4c6;
    --sidebar-section: #b0adcf;
    --sidebar-hover: #f1eeff;
    --sidebar-border: #f0eef9;
    --sidebar-brand: #2f2b50;

    /* 그림자 / 형태 */
    --sidebar-w: 264px;
    --sidebar-w-collapsed: 82px;
    --header-h: 72px;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(30, 90, 140, .04), 0 8px 24px rgba(30, 90, 140, .07);
    --shadow-hover: 0 12px 30px rgba(14, 165, 233, .18);
    --shadow-pop: 0 16px 40px rgba(20, 70, 110, .18);
    --accent-grad: linear-gradient(135deg, #0ea5e9, #38bdf8);
}

/* ---------- DARK ---------- */
[data-theme="dark"] {
    --primary: #ff5ea0;          /* 핫핑크 */
    --primary-dark: #f43f8e;
    --primary-soft: rgba(255, 94, 160, .18);
    --secondary: #ff9ec7;        /* 라이트핑크 */
    --glow: rgba(255, 94, 160, .38);
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, .16);
    --success-text: #34d399;
    --warning: #fbbf5c;
    --warning-soft: rgba(251, 191, 92, .16);
    --warning-text: #fbbf5c;
    --error: #f87171;
    --error-soft: rgba(248, 113, 113, .16);
    --error-text: #fca5a5;
    --info: #22d3ee;
    --info-soft: rgba(34, 211, 238, .15);
    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, .18);

    --bg: #0f0f1a;
    --card: #181826;
    --surface-2: #1f1f30;
    --surface-3: #26263a;
    --hover: #232338;
    --text: #e9e8f5;
    --text-muted: #a6a3c8;
    --text-light: #6f6c94;
    --border: #2a2a42;
    --border-soft: #222236;
    --input-bg: #1f1f30;
    --chart-grid: #2a2a42;

    --sidebar-bg: #14141f;
    --sidebar-bg2: #14141f;
    --sidebar-text: #b6b3d6;
    --sidebar-muted: #6f6c94;
    --sidebar-section: #5b5884;
    --sidebar-hover: rgba(255, 255, 255, .05);
    --sidebar-border: rgba(255, 255, 255, .06);
    --sidebar-brand: #ffffff;

    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 8px 24px rgba(0, 0, 0, .4);
    --shadow-hover: 0 12px 30px rgba(255, 94, 160, .30);
    --shadow-pop: 0 16px 42px rgba(0, 0, 0, .55);
    --accent-grad: linear-gradient(135deg, #ff5ea0, #ff9ec7);
}

* { box-sizing: border-box; }

html, body {
    font-family: 'Noto Sans KR', 'Segoe UI', 'Malgun Gothic', 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    transition: background-color .25s ease, color .25s ease;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4, h5 { color: var(--text); }

/* ---------- 레이아웃 골격 ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg2));
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 30;
    transition: width .22s ease;
}

.main-area {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left .22s ease;
}

/* ---------- 사이드바 접힘 ---------- */
.app-shell.collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.app-shell.collapsed .main-area { margin-left: var(--sidebar-w-collapsed); }
.app-shell.collapsed .sidebar-brand { padding: 0; justify-content: center; }
.app-shell.collapsed .brand-text,
.app-shell.collapsed .nav-section,
.app-shell.collapsed .nav-item span,
.app-shell.collapsed .nav-item .badge-soft,
.app-shell.collapsed .nav-fav,
.app-shell.collapsed .user-box > div:not(.user-avatar),
.app-shell.collapsed .logout-btn span { display: none; }
.app-shell.collapsed .nav-item { justify-content: center; padding: 11px 0; }
.app-shell.collapsed .nav-item i { margin: 0; font-size: 16px; }
.app-shell.collapsed .sidebar-nav { padding: 12px 12px 20px; }
.app-shell.collapsed .sidebar-footer { padding: 12px 12px; }
.app-shell.collapsed .user-box { justify-content: center; padding: 8px 0; }
.app-shell.collapsed .logout-btn { padding: 9px 0; }
/* 사이드바 접힘 시 상단바 즐겨찾기 숨김 */
.app-shell.collapsed .fav-bar { display: none; }

/* ---------- 사이드바 ---------- */
.sidebar-brand {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    border-bottom: 1px solid var(--sidebar-border);
    cursor: pointer;
    user-select: none;
    transition: background-color .15s;
}
.sidebar-brand:hover { background: var(--sidebar-hover); }
.brand-mark {
    width: 40px; height: 40px;
    border-radius: 13px;
    background: var(--accent-grad);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800;
    box-shadow: 0 8px 18px var(--glow);
    flex-shrink: 0;
}
.brand-mark.has-img { background: var(--card); overflow: hidden; padding: 0; }
/* contain — 로고가 정사각형이 아니어도 잘리지 않고 전체가 보이게 */
.brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 3px; border-radius: inherit; display: block; }
.brand-text { font-weight: 800; font-size: 18px; letter-spacing: -.3px; color: var(--sidebar-brand); white-space: nowrap; }
.brand-text small { display: block; font-size: 10.5px; font-weight: 600; color: var(--sidebar-muted); letter-spacing: 0; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 14px 20px; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

/* 전체 접기/펼치기 바 */
.nav-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px 6px 12px; margin-bottom: 4px;
}
.nav-topbar-label { font-size: 10.5px; font-weight: 800; letter-spacing: 1px; color: var(--sidebar-section); text-transform: uppercase; }
.nav-collapse-all {
    border: none; background: transparent; cursor: pointer;
    color: var(--sidebar-muted); font-size: 12px; padding: 5px 8px; border-radius: 8px;
    display: inline-flex; align-items: center; gap: 6px; transition: all .15s;
}
.nav-collapse-all:hover { background: var(--sidebar-hover); color: var(--primary); }

/* 그룹(드롭다운) */
.nav-group { margin-bottom: 2px; }
.nav-group-head {
    display: flex; align-items: center; gap: 8px;
    margin: 8px 6px 4px; padding: 7px 10px;
    font-size: 11px; font-weight: 800; letter-spacing: .5px;
    color: var(--sidebar-section); text-transform: uppercase;
    cursor: pointer; border-radius: 9px; user-select: none;
    transition: background .15s, color .15s;
}
.nav-group-head:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-group-head .nav-group-ico { font-size: 12px; width: 15px; text-align: center; opacity: .9; }
.nav-group-head .chev { font-size: 10px; transition: transform .2s ease; margin-left: auto; }
.nav-group.collapsed .nav-group-head .chev { transform: rotate(-90deg); }
.nav-group-body { overflow: hidden; }
.nav-group.collapsed .nav-group-body { display: none; }

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin: 3px 0;
    border-radius: 11px;
    color: var(--sidebar-text);
    font-weight: 600; font-size: 13.5px;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
}
.nav-item i { width: 18px; text-align: center; font-size: 15px; color: var(--sidebar-muted); transition: color .15s; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--primary); }
.nav-item:hover i { color: var(--primary); }
.nav-item.active { background: var(--accent-grad); color: #fff; box-shadow: 0 8px 18px var(--glow); }
.nav-item.active i { color: #fff; }
.nav-item .badge-soft { margin-left: auto; }

/* 접힌 사이드바(아이콘 모드)에서는 그룹 헤더/전체바 숨기고 항목은 항상 표시 */
.app-shell.collapsed .nav-topbar,
.app-shell.collapsed .nav-group-head { display: none; }
.app-shell.collapsed .nav-group.collapsed .nav-group-body { display: block; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--sidebar-border); }
.user-box { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 12px; background: var(--sidebar-hover); }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--accent-grad);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.user-box .uname { font-weight: 700; font-size: 13px; line-height: 1.2; color: var(--sidebar-brand); }
.user-box .urole { font-size: 11px; color: var(--sidebar-muted); }
.logout-btn {
    margin-top: 10px; width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px; border-radius: 11px;
    border: 1px solid var(--border); background: transparent;
    color: var(--error-text); font-weight: 600; font-size: 13px; cursor: pointer;
    transition: all .15s;
}
.logout-btn:hover { background: var(--error-soft); border-color: var(--error); color: var(--error-text); }

/* ---------- 상단 헤더 ---------- */
.topbar {
    height: var(--header-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 26px;
    /* AI 패널(z-26)보다 위에 두어 유저/알림 드롭다운이 패널에 가려지지 않게 한다 */
    position: sticky; top: 0; z-index: 28;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar .page-title { font-size: 19px; font-weight: 700; }
.topbar .page-sub { font-size: 12px; color: var(--text-light); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-icon {
    position: relative; color: var(--text-muted); font-size: 16px; cursor: pointer;
    width: 40px; height: 40px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface-2); border: 1px solid var(--border);
    transition: all .15s;
}
.topbar-icon:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.topbar-icon .dot { position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--error); border: 2px solid var(--card); }
.topbar-user { display: flex; align-items: center; gap: 9px; padding-left: 6px; }
.topbar-user .uname { font-weight: 700; font-size: 13px; }
.topbar-user .urole { font-size: 11px; color: var(--text-light); }

/* ---------- 상단바: 즐겨찾기 / 검색 / 알림 / 유저 드롭다운 ---------- */
.topbar-left { flex: 1; min-width: 0; }
.topbar-titles { flex-shrink: 0; }
.mobile-menu-btn { display: none; width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: 16px; cursor: pointer; align-items: center; justify-content: center; }

.fav-bar { display: flex; align-items: center; gap: 8px; margin-left: 8px; overflow: visible; flex-wrap: nowrap; }
.fav-more { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text-muted); font-size: 12.5px; font-weight: 800; cursor: pointer; white-space: nowrap; transition: all .15s; flex-shrink: 0; }
.fav-more:hover, .fav-more.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.fav-chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text-muted); font-size: 12.5px; font-weight: 700; cursor: pointer; white-space: nowrap; transition: all .15s; }
.fav-chip i { color: var(--warning); font-size: 12px; }
.fav-chip:hover { border-color: var(--primary); color: var(--primary); }
.fav-chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.fav-chip-x { border: none; background: transparent; color: inherit; opacity: .45; cursor: pointer; width: 16px; height: 16px; margin-left: 1px; border-radius: 50%; font-size: 10px; display: inline-flex; align-items: center; justify-content: center; transition: all .12s; }
.fav-chip:hover .fav-chip-x { opacity: .7; }
.fav-chip-x:hover { opacity: 1; background: var(--error-soft); color: var(--error-text); }
.fav-add { width: 32px; height: 32px; border-radius: 50%; border: 1px dashed var(--border); background: var(--card); color: var(--text-muted); cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; transition: all .15s; flex-shrink: 0; }
.fav-add:hover, .fav-add.active { border-style: solid; border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.drop-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-star { border: none; background: transparent; cursor: pointer; color: var(--text-light); font-size: 13px; padding: 3px 5px; border-radius: 7px; }
.drop-star.on { color: var(--warning); }
.drop-star:hover { color: var(--warning); background: var(--warning-soft); }

.drop-adm { margin: 6px 16px 0; padding: 11px; border: 1px solid var(--border); background: var(--primary-soft); color: var(--primary); border-radius: 11px; font-weight: 700; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; width: calc(100% - 32px); transition: all .15s; }
.drop-adm:hover { background: var(--primary); color: #fff; }

.topbar-drop { position: relative; }
.drop-overlay { position: fixed; inset: 0; z-index: 40; }
.drop-panel { position: absolute; top: calc(100% + 10px); right: 0; z-index: 50; background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop); min-width: 260px; overflow: hidden; animation: drop-in .16s ease; }
@keyframes drop-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.drop-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 700; }
.drop-head b { color: var(--primary); }
.drop-clear { border: none; background: none; color: var(--text-light); font-size: 12px; cursor: pointer; }
.drop-clear:hover { color: var(--primary); }
.drop-list { max-height: 340px; overflow: auto; padding: 6px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.drop-list::-webkit-scrollbar { width: 8px; }
.drop-list::-webkit-scrollbar-track { background: transparent; margin: 4px; }
.drop-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid var(--card); }
.drop-list::-webkit-scrollbar-thumb:hover { background: var(--text-light); }
.drop-empty { padding: 22px; text-align: center; color: var(--text-light); font-size: 13px; }

.drop-search { width: 320px; }
.drop-fav { left: 0; right: auto; }
.drop-fav .drop-list { max-height: 420px; }
.drop-search-box { display: flex; align-items: center; gap: 9px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.drop-search-box i { color: var(--text-light); }
.drop-search-box input { flex: 1; border: none; outline: none; background: transparent; font-size: 14px; color: var(--text); font-family: inherit; }
.drop-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 13px; color: var(--text); }
.drop-item:hover { background: var(--primary-soft); color: var(--primary); }
.drop-item i { width: 16px; text-align: center; color: var(--text-light); }
.drop-item:hover i { color: var(--primary); }
.drop-item-code { margin-left: auto; font-size: 11px; color: var(--text-light); font-family: 'Consolas', monospace; }
.drop-group-label { padding: 9px 12px 4px; font-size: 10.5px; font-weight: 800; letter-spacing: .5px; color: var(--text-light); text-transform: uppercase; }
.drop-item.picked { background: var(--primary-soft); }
.drop-item.picked .drop-item-name { color: var(--primary); font-weight: 700; }

.drop-noti { width: 330px; }
.noti-item { display: flex; gap: 11px; padding: 11px 12px; border-radius: 10px; cursor: pointer; }
.noti-item:hover { background: var(--hover); }
.noti-ico { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.noti-ico.warn { background: var(--warning-soft); color: var(--warning-text); }
.noti-ico.err { background: var(--error-soft); color: var(--error-text); }
.noti-ico.ok { background: var(--success-soft); color: var(--success-text); }
.noti-ico.info { background: var(--info-soft); color: var(--info); }
.noti-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
.noti-time { font-size: 11px; color: var(--text-light); margin-top: 2px; }

.topbar-user { cursor: pointer; border-radius: 12px; padding: 5px 8px 5px 5px; transition: background .15s; }
.topbar-user:hover, .topbar-user.active { background: var(--surface-2); }
.topbar-user-chev { font-size: 10px; color: var(--text-light); margin-left: 2px; }
.drop-user { width: 280px; }
.drop-user-head { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--border); }
.drop-user-name { font-size: 15px; font-weight: 800; color: var(--text); }
.drop-user-role { font-size: 12px; color: var(--text-light); }
.drop-user-info { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.drop-user-info > div { display: flex; justify-content: space-between; font-size: 12.5px; }
.drop-user-info span { color: var(--text-light); }
.drop-user-info b { color: var(--text); font-weight: 700; }
.text-ok { color: var(--success-text); }
.drop-logout { margin: 6px 16px 16px; padding: 11px; border: 1px solid var(--border); background: transparent; color: var(--error-text); border-radius: 11px; font-weight: 700; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; width: calc(100% - 32px); transition: all .15s; }
.drop-logout:hover { background: var(--error-soft); border-color: var(--error); }

/* 사이드바 즐겨찾기 별 */
.nav-fav { border: none; background: transparent; color: var(--sidebar-muted); cursor: pointer; font-size: 13px; padding: 2px 4px; margin-left: auto; opacity: 0; transition: opacity .15s, color .15s; }
.nav-item:hover .nav-fav { opacity: 1; }
.nav-fav.on { opacity: 1; color: var(--warning); }
.nav-fav:hover { color: var(--warning); }
.nav-item.active .nav-fav { color: #fff; opacity: 1; }
.nav-item .badge-soft + .nav-fav { margin-left: 6px; }

/* ---------- AI 어시스턴트 ---------- */
/* AI 전용 그라디언트 토큰 (라이트: 바이올렛→블루 파스텔 / 다크: 핑크→바이올렛)
   :root 기본값 = 라이트 (data-theme 속성이 아직 없어도 변수가 항상 해석되도록) */
:root,
[data-theme="light"] {
    --ai-grad: linear-gradient(135deg, #8b7cf6 0%, #5da8ff 55%, #67e8f9 100%);
    --ai-glow: rgba(124, 108, 240, .32);
    --ai-bg:
        radial-gradient(560px 300px at 18% -8%, rgba(139, 124, 246, .16), transparent 62%),
        radial-gradient(480px 280px at 102% 12%, rgba(103, 232, 249, .16), transparent 60%),
        radial-gradient(520px 320px at 55% 108%, rgba(244, 114, 182, .12), transparent 62%),
        linear-gradient(180deg, #f6f5ff 0%, #f2f6ff 55%, #fdf4fb 100%);
    --ai-card: rgba(255, 255, 255, .82);
    --ai-card-border: rgba(139, 124, 246, .18);
}
[data-theme="dark"] {
    --ai-grad: linear-gradient(135deg, #ff5ea0 0%, #a78bfa 55%, #5da8ff 100%);
    --ai-glow: rgba(255, 94, 160, .34);
    --ai-bg:
        radial-gradient(560px 300px at 18% -8%, rgba(255, 94, 160, .17), transparent 62%),
        radial-gradient(480px 280px at 102% 12%, rgba(167, 139, 250, .16), transparent 60%),
        radial-gradient(520px 320px at 55% 108%, rgba(93, 168, 255, .13), transparent 62%),
        linear-gradient(180deg, #171225 0%, #151327 55%, #1a1226 100%);
    --ai-card: rgba(34, 30, 54, .78);
    --ai-card-border: rgba(167, 139, 250, .22);
}

/* AI 버튼은 다른 상단바 아이콘과 동일한 배경/보더(주변과 자연스럽게 어울리도록),
   브랜딩은 그라디언트 뇌 아이콘 + AI 배지가 담당한다 */
.topbar-icon.ai-icon:hover, .topbar-icon.ai-icon.active { background: var(--ai-grad); border-color: transparent; color: #fff; box-shadow: 0 4px 12px var(--ai-glow); }
/* 다크모드: 보더/글로우 없이 2색 그라디언트만 (파란 테두리처럼 보이는 현상 제거) */
[data-theme="dark"] .topbar-icon.ai-icon { border-color: transparent; }
[data-theme="dark"] .topbar-icon.ai-icon:hover,
[data-theme="dark"] .topbar-icon.ai-icon.active {
    background: linear-gradient(135deg, #ff5ea0, #c084fc);
    border-color: transparent; box-shadow: none;
}
/* 상단바 로고: 뇌 아이콘 + "AI" 미니 배지 조합 */
.ai-logo { position: relative; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
/* 뇌 아이콘 전용 그라디언트: 3색(--ai-grad)은 작은 글리프에서 중간~끝 색만 샘플링되어
   다크모드에서 파랗게 보이므로, 테마 주색 계열 2색으로 별도 지정한다 */
.ai-logo i {
    font-size: 15px;
    background: linear-gradient(135deg, #8b7cf6, #5da8ff);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
[data-theme="dark"] .ai-logo i { background: linear-gradient(135deg, #ff5ea0, #c084fc); -webkit-background-clip: text; background-clip: text; }
.topbar-icon.ai-icon:hover .ai-logo i, .topbar-icon.ai-icon.active .ai-logo i {
    background: #fff; -webkit-background-clip: text; background-clip: text;
}
/* 배지 테두리는 버튼 배경색과 동일하게 → 어떤 테마에서도 링이 도드라지지 않는다 */
.ai-logo-badge {
    position: absolute; bottom: -8px; right: -11px;
    font-size: 7.5px; font-weight: 900; letter-spacing: .3px; color: #fff;
    background: var(--ai-grad); padding: 2px 4px; border-radius: 6px;
    border: 1.5px solid var(--surface-2); box-shadow: 0 2px 6px var(--ai-glow);
}
.topbar-icon.ai-icon:hover .ai-logo-badge, .topbar-icon.ai-icon.active .ai-logo-badge {
    background: #fff; color: var(--primary); border-color: transparent;
}

/* 우측 패널 (side 모드) — 핀 고정 시 도킹된 것처럼 유지 */
.ai-panel {
    position: fixed; top: var(--header-h); right: 0; bottom: 0; z-index: 26;
    width: 400px; display: flex; flex-direction: column;
    background: var(--ai-bg); border-left: 1px solid var(--ai-card-border);
    box-shadow: -12px 0 36px var(--ai-glow);
    animation: ai-in .24s ease;
}
@keyframes ai-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
/* 상단바는 전체 폭 유지, 본문만 패널 폭만큼 줄어든다 */
.app-shell.ai-open .main-body { margin-right: 400px; transition: margin-right .22s ease; }

.ai-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; flex: 0 0 auto;
    background: var(--ai-card); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--ai-card-border);
}
.ai-panel-title { font-weight: 800; font-size: 14px; color: var(--text); display: inline-flex; align-items: center; gap: 9px; }
.ai-title-mark {
    width: 28px; height: 28px; border-radius: 9px; background: var(--ai-grad); color: #fff;
    font-size: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px var(--ai-glow);
}
.ai-panel-btns { display: flex; gap: 6px; }
/* 패널 버튼은 보더 없이 배경만으로 구분 (다크모드에서 보더가 이질감을 주는 문제 방지) */
.ai-panel-btns button {
    width: 30px; height: 30px; border-radius: 9px; border: none;
    background: var(--ai-card); color: var(--text-muted); cursor: pointer; font-size: 12px;
    display: inline-flex; align-items: center; justify-content: center; transition: all .15s;
}
.ai-panel-btns button:hover { color: var(--primary); box-shadow: 0 3px 8px var(--ai-glow); }
/* 핀 버튼: 고정 상태에선 테마 주색 2색 그라디언트로 강조 + 기울임 */
.ai-pin-btn i { transition: transform .18s; }
.ai-pin-btn.on { background: linear-gradient(135deg, #8b7cf6, #5da8ff); color: #fff; box-shadow: 0 4px 10px var(--ai-glow); }
[data-theme="dark"] .ai-pin-btn.on { background: linear-gradient(135deg, #ff5ea0, #c084fc); }
.ai-pin-btn.on:hover { color: #fff; filter: brightness(1.08); }
.ai-pin-btn:not(.on) i { transform: rotate(45deg); }
.ai-panel.pinned { box-shadow: -12px 0 40px var(--ai-glow), inset 3px 0 0 transparent; }

/* 채팅 본체 */
.ai-chat { flex: 1; display: flex; flex-direction: column; min-height: 0; height: 100%; }
/* 전체 페이지(탭) 모드: 일반 메뉴처럼 워크스페이스 전체 폭을 사용하고,
   메시지/입력 영역만 화면 폭에 비례한 여백으로 읽기 좋게 유지한다 */
.ai-chat.full { width: 100%; max-width: none; background: var(--ai-bg); }
.ai-chat.full .ai-chat-body { padding: 24px clamp(20px, 8vw, 160px); gap: 15px; }
.ai-chat.full .ai-chat-foot { padding: 14px clamp(20px, 8vw, 160px) 12px; }
.ai-chat.full .ai-msg { max-width: 86%; }
.ai-chat-body {
    flex: 1; min-height: 0; overflow-y: auto;
    display: flex; flex-direction: column-reverse;   /* 최신 메시지가 항상 하단 */
    gap: 13px; padding: 18px 16px;
}
.ai-msg { display: flex; gap: 9px; max-width: 92%; }
.ai-msg.user { align-self: flex-end; }
.ai-msg.ai { align-self: flex-start; }
.ai-msg-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    background: var(--ai-grad); color: #fff; font-size: 13px;
    display: inline-flex; align-items: center; justify-content: center; margin-top: 2px;
    box-shadow: 0 4px 10px var(--ai-glow);
}
.ai-msg-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ai-msg-bubble {
    padding: 11px 15px; border-radius: 16px; font-size: 13.5px; line-height: 1.65;
    word-break: break-word; white-space: normal;
}
.ai-msg.ai .ai-msg-bubble {
    background: var(--ai-card); color: var(--text);
    border: 1px solid var(--ai-card-border); border-top-left-radius: 5px;
    backdrop-filter: blur(8px); box-shadow: 0 4px 16px rgba(70, 60, 140, .08);
}
.ai-msg.user .ai-msg-bubble {
    background: var(--ai-grad); color: #fff; border-top-right-radius: 5px;
    box-shadow: 0 6px 16px var(--ai-glow);
}
.ai-msg-time { font-size: 10.5px; color: var(--text-light); padding: 0 4px; }
.ai-msg.user .ai-msg-time { text-align: right; }

/* AI 응답 마크다운 표/코드 */
.ai-md-table {
    border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 12.5px;
}
.ai-md-table th, .ai-md-table td {
    border: 1px solid var(--ai-card-border); padding: 5px 9px; text-align: left;
}
.ai-md-table th { background: rgba(120, 110, 220, .10); font-weight: 600; white-space: nowrap; }
.ai-md-table tr:nth-child(even) td { background: rgba(120, 110, 220, .04); }
.ai-msg-bubble code {
    background: rgba(120, 110, 220, .12); border-radius: 4px; padding: 1px 5px;
    font-family: Consolas, monospace; font-size: 12px;
}


/* 타이핑 표시 */
.ai-msg.typing .ai-msg-bubble { display: inline-flex; gap: 5px; align-items: center; padding: 13px 16px; }
.ai-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ai-grad); animation: ai-blink 1.2s infinite; }
.ai-dot:nth-child(2) { animation-delay: .2s; }
.ai-dot:nth-child(3) { animation-delay: .4s; }
@keyframes ai-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* 빈 상태 + 추천 카드 */
.ai-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 34px 16px; }
.ai-empty-mark {
    position: relative;
    width: 64px; height: 64px; border-radius: 20px; background: var(--ai-grad); color: #fff;
    font-size: 26px; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 14px 34px var(--ai-glow); margin-bottom: 10px;
    animation: ai-float 3.2s ease-in-out infinite;
}
.ai-spark {
    position: absolute; top: -7px; right: -9px; font-size: 15px; color: #ffd66e;
    text-shadow: 0 0 10px rgba(255, 214, 110, .9); animation: ai-twinkle 1.8s ease-in-out infinite;
}
@keyframes ai-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes ai-twinkle { 0%, 100% { opacity: .5; transform: scale(.85) rotate(0deg); } 50% { opacity: 1; transform: scale(1.15) rotate(20deg); } }
.ai-empty-title { font-size: 17px; font-weight: 800; color: var(--text); }
.ai-empty-title b {
    background: var(--ai-grad); -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
}
.ai-empty-sub { font-size: 12.5px; color: var(--text-light); }
.ai-sugs { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; width: 100%; max-width: 330px; }
.ai-chat.full .ai-sugs { max-width: 560px; display: grid; grid-template-columns: 1fr 1fr; }
.ai-sug {
    display: flex; align-items: center; gap: 11px;
    border: 1px solid var(--ai-card-border); background: var(--ai-card); color: var(--text-muted);
    border-radius: 14px; padding: 11px 13px; font-size: 12.5px; cursor: pointer; text-align: left;
    transition: all .18s; font-family: inherit; backdrop-filter: blur(8px);
}
.ai-sug:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 10px 22px var(--ai-glow); }
.ai-sug-ico {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; color: #fff; font-size: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(120, 100, 240, .25);
}
.ai-sug-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.ai-sug-txt b { font-size: 12.5px; font-weight: 700; color: var(--text); }
.ai-sug-txt small { font-size: 11px; color: var(--text-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-sug-go { font-size: 10px; color: var(--text-light); opacity: 0; transition: all .18s; }
.ai-sug:hover .ai-sug-go { opacity: 1; color: var(--primary); transform: translateX(2px); }

/* 입력 영역 — 그라디언트 보더 필 (Nocra 스타일) */
.ai-chat-foot { flex: 0 0 auto; padding: 12px 14px 10px; }
.ai-input-row {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 5px 5px 16px; border-radius: 18px;
    border: 2px solid transparent;
    background:
        linear-gradient(var(--card), var(--card)) padding-box,
        var(--ai-grad) border-box;
    box-shadow: 0 10px 26px var(--ai-glow);
    transition: box-shadow .18s;
}
.ai-input-row:focus-within { box-shadow: 0 12px 32px var(--ai-glow), 0 0 0 4px var(--primary-soft); }
.ai-input {
    flex: 1; border: none; background: transparent; color: var(--text);
    padding: 9px 0; font-size: 13.5px; outline: none; font-family: inherit; min-width: 0;
}
.ai-input::placeholder { color: var(--text-light); }
.ai-send {
    width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 13px;
    background: var(--ai-grad); color: #fff;
    font-size: 14px; cursor: pointer; box-shadow: 0 6px 14px var(--ai-glow);
    transition: filter .15s, transform .15s;
    display: inline-flex; align-items: center; justify-content: center;
}
.ai-send:hover:not(:disabled) { filter: brightness(1.08); transform: scale(1.05); }
.ai-send:disabled { opacity: .5; cursor: default; }
.ai-foot-hint { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--text-light); padding: 0 4px; }
.ai-foot-hint span { display: inline-flex; align-items: center; gap: 5px; }
.ai-clear { border: none; background: none; color: var(--text-light); font-size: 11px; cursor: pointer; font-family: inherit; }
.ai-clear:hover { color: var(--error-text); }

@media (max-width: 900px) {
    .ai-panel { width: 100%; }
    .app-shell.ai-open .main-body { margin-right: 0; }
    .ai-chat.full .ai-sugs { grid-template-columns: 1fr; }
}

/* 모바일 백드롭 (기본 숨김) */
.mobile-backdrop { display: none; }

.main-body { padding: 24px 26px 40px; flex: 1; }

/* ---------- 모바일 반응형 ---------- */
@media (max-width: 900px) {
    .mobile-menu-btn { display: flex; }
    .sidebar { transform: translateX(-100%); transition: transform .25s ease, width .22s ease; box-shadow: var(--shadow-pop); z-index: 60; }
    .app-shell.mobile-open .sidebar { transform: none; }
    .app-shell .main-area { margin-left: 0; }
    .app-shell.collapsed .main-area { margin-left: 0; }
    .mobile-backdrop { display: block; position: fixed; inset: 0; background: rgba(10, 15, 30, .45); z-index: 55; opacity: 0; visibility: hidden; transition: opacity .25s; }
    .app-shell.mobile-open .mobile-backdrop { opacity: 1; visibility: visible; }
    .fav-bar { display: none; }
    .topbar-user-meta { display: none; }
    .topbar-titles .page-sub { display: none; }
    .topbar { padding: 0 14px; }
    .main-body { padding: 14px; }
    .drop-panel { position: fixed; top: 68px; right: 10px; left: 10px; width: auto; min-width: 0; }
    .drop-search, .drop-noti, .drop-user { width: auto; }
}

/* ---------- 카드 ---------- */
.card-x {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}
.card-x + .card-x { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.card-head h3 { font-size: 16px; font-weight: 700; margin: 0; }
.card-head .sub { font-size: 12px; color: var(--text-light); }

/* 카드 헤더 우측 "관련 화면으로 이동" 버튼 */
.card-go {
    margin-left: auto; flex: 0 0 auto;
    width: 26px; height: 26px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.card-go:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.grid { display: grid; gap: 22px; }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-2-1 { grid-template-columns: 2fr 1fr; }
.grid-1-2 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1200px) { .grid-5 { grid-template-columns: repeat(3,1fr);} .grid-4{grid-template-columns:repeat(2,1fr);} .grid-2-1,.grid-1-2{grid-template-columns:1fr;} }
@media (max-width: 800px) { .grid-5,.grid-4,.grid-3,.grid-2{grid-template-columns:1fr;} }

/* ---------- 통계 카드 ---------- */
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: transparent; }
.stat-icon { width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.stat-foot { font-size: 12px; color: var(--text-light); }

.tone-primary { background: var(--primary-soft); color: var(--primary); }
.tone-success { background: var(--success-soft); color: var(--success-text); }
.tone-warning { background: var(--warning-soft); color: var(--warning-text); }
.tone-error { background: var(--error-soft); color: var(--error-text); }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-purple { background: var(--purple-soft); color: var(--purple); }

/* ---------- 배지 ---------- */
.badge-soft { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-type-p { background: var(--primary-soft); color: var(--primary); }
.badge-type-s { background: var(--purple-soft); color: var(--purple); }
.badge-type-m { background: var(--warning-soft); color: var(--warning-text); }
.badge-type-g { background: var(--success-soft); color: var(--success-text); }
.badge-type-x { background: var(--surface-3); color: var(--text-muted); }
.badge-ok { background: var(--success-soft); color: var(--success-text); }
.badge-no { background: var(--surface-3); color: var(--text-muted); }
.badge-low { background: var(--error-soft); color: var(--error-text); }

.st-wait { background: var(--surface-3); color: var(--text-muted); }
.st-run  { background: var(--info-soft); color: var(--info); }
.st-hold { background: var(--warning-soft); color: var(--warning-text); }
.st-done { background: var(--success-soft); color: var(--success-text); }
.st-x    { background: var(--surface-3); color: var(--text-muted); }

/* ---------- 테이블 ---------- */
.table-x { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-x thead th {
    text-align: left; padding: 11px 14px;
    color: var(--text-light); font-weight: 700; font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .4px;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table-x tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table-x tbody tr:last-child td { border-bottom: none; }
.table-x tbody tr:hover { background: var(--hover); }
.table-x .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.table-x .mono { font-family: 'Consolas','Menlo',monospace; font-size: 12px; color: var(--text-muted); }
.table-wrap { overflow-x: auto; }

/* ---------- 폼/툴바 ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.search-box { position: relative; }
.search-box i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-light); font-size: 13px; }
.search-box input {
    padding: 10px 14px 10px 38px; border: 1px solid var(--border); border-radius: 999px;
    font-size: 13px; width: 280px; background: var(--input-bg); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-box input::placeholder { color: var(--text-light); }
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* 그리드 바로 위에 붙는 소형 검색창(패널 전체 폭) */
.search-box-sm { margin-bottom: 8px; flex: 0 0 auto; }
.search-box-sm input { width: 100%; padding: 7px 12px 7px 34px; border-radius: 9px; box-sizing: border-box; }
.search-box-sm i { left: 12px; font-size: 12px; }

/* 그리드 툴바 안에 끼워 넣는 인라인 검색창(별도 줄 차지하지 않음, DataGrid Toolbar 슬롯용) */
.search-box-inline { margin: 0; flex: 0 0 auto; }
.search-box-inline input { width: 200px; padding: 5px 10px 5px 30px; border-radius: 7px; font-size: 12px; box-sizing: border-box; }
.search-box-inline i { left: 10px; font-size: 11px; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 12px; padding: 4px; gap: 2px; }
.seg button {
    border: none; background: transparent; padding: 7px 16px; border-radius: 9px;
    font-size: 13px; font-weight: 700; color: var(--text-muted); cursor: pointer; transition: all .15s;
}
.seg button.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

.btn-x { padding: 10px 18px; border-radius: 11px; border: none; font-size: 13px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: all .15s; }
.btn-primary-x { background: var(--accent-grad); color: #fff; box-shadow: 0 8px 18px var(--glow); }
.btn-primary-x:hover { filter: brightness(1.05); box-shadow: 0 10px 22px var(--glow); }
.btn-ghost { background: var(--card); border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.pill-count { background: var(--primary-soft); color: var(--primary); border-radius: 20px; padding: 3px 11px; font-size: 12px; font-weight: 700; margin-left: 8px; }

/* ---------- 빈 상태 ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state i { font-size: 42px; opacity: .4; margin-bottom: 14px; display: block; }
.empty-state p { font-size: 14px; margin: 0; }

/* ---------- 진행바 ---------- */
.bar-track { height: 7px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--primary); }

/* ---------- 막대/선 차트 ---------- */
.bars { display: flex; align-items: flex-end; gap: 14px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-val { font-size: 11px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; white-space: nowrap; }
.bar-area { width: 100%; flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 60%; max-width: 38px; min-height: 3px; border-radius: 6px 6px 0 0; transition: height .4s ease; opacity: .92; }
.bar:hover { opacity: 1; }
.bar-lbl { font-size: 11.5px; color: var(--text-light); margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.line-labels { display: flex; justify-content: space-between; padding: 4px 6px 0; font-size: 11px; color: var(--text-light); }
.gauge svg { display: block; margin: 0 auto; }

/* ---------- MDI 탭 드래그 고스트(body 에 부착되므로 전역) ---------- */
.dock-drag-ghost {
    position: fixed; z-index: 9999; pointer-events: none;
    left: -9999px; top: -9999px;
    background: var(--primary); color: #fff; font-size: 12px;
    padding: 5px 12px; border-radius: 6px;
    box-shadow: 0 6px 16px rgba(31,42,68,.35);
    opacity: .94; max-width: 240px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* MDI 워크스페이스를 감싸는 본문 */
.main-body.mdi-body { padding: 5px; height: calc(100vh - var(--header-h)); overflow: hidden; }
.mdi-tb-title { font-weight: 700; font-size: 13.5px; color: var(--text); display: inline-flex; align-items: center; gap: 8px; }
.mdi-tb-title i { color: var(--primary); }

/* 마스터-디테일 화면 헤더 */
.md-head { font-weight: 700; font-size: 13.5px; color: var(--text); margin-bottom: 6px; display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.md-head i { color: var(--primary); }
.md-head-sub { color: var(--text-light); font-weight: 600; font-size: 12.5px; }

/* 거래처 검색 피커(편집 폼) */
.cust-picker { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.cust-picker-cur { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cust-picker-code { font-weight: 700; color: var(--primary); font-size: 13px; }
.cust-picker-name { color: var(--text); font-size: 13px; }
.cust-picker-box { position: relative; display: flex; align-items: center; }
.cust-picker-box i { position: absolute; left: 11px; color: var(--text-light); font-size: 12px; }
.cust-picker-box .dxedit { width: 100%; padding-left: 30px; }
.cust-picker-list { max-height: 180px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; background: var(--card); }
.cust-picker-item { display: flex; align-items: center; gap: 8px; padding: 8px 11px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border-soft); }
.cust-picker-item:last-child { border-bottom: none; }
.cust-picker-item:hover { background: var(--primary-soft); }
.cust-picker-mgr { margin-left: auto; color: var(--text-muted); font-size: 12px; }

/* 그리드 화면: 탭 높이를 가득 채우는 레이아웃 */
.mdi-screen { height: 100%; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.mdi-screen .toolbar { margin-bottom: 0; flex: 0 0 auto; }
.grid-host { flex: 1 1 auto; min-height: 0; display: flex; }
.grid-host > * { width: 100%; }
/* 상단 가운데에서 아래로 내려오는 팝업 토스트 */
.crud-msg {
    position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 2000;
    padding: 13px 24px; border-radius: 12px; font-size: 14px; font-weight: 700;
    display: flex; align-items: center; gap: 10px; white-space: nowrap;
    background: var(--card); border: 1px solid var(--border);
    box-shadow: var(--shadow-pop);
    animation: crud-toast-in .32s cubic-bezier(.2,.85,.3,1);
}
.crud-msg i { font-size: 16px; }
.crud-msg.ok { color: var(--success-text); border-color: rgba(19,222,185,.4); }
.crud-msg.ok i { color: var(--success); }
.crud-msg.err { color: var(--error-text); border-color: rgba(250,137,107,.4); }
.crud-msg.err i { color: var(--error); }
@keyframes crud-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-32px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- 로그인 (좌측 일러스트 + 우측 폼, 하나의 카드) ---------- */
.login-page {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    /* 참조 시안처럼 아주 연한 하늘색 배경 */
    background: linear-gradient(160deg, #e8f1fd 0%, #dbeafe 45%, #cfe3fb 100%);
}

/* 라이트/다크 토글 — 우하단 플로팅 버튼(FAB). 로그인 화면과 로그인 후 화면 공통 사용 */
.login-theme,
.theme-fab {
    position: fixed; right: 26px; bottom: 26px; z-index: 50;
    width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
    border: 1px solid #dbe6f5;
    background: #fff; color: #3b6fd4; font-size: 17px;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 22px rgba(37,72,138,.22);
    transition: transform .15s, box-shadow .15s, background .15s, right .22s;
}
.login-theme:hover,
.theme-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(37,72,138,.3); }
[data-theme="dark"] .login-theme,
[data-theme="dark"] .theme-fab { background: var(--card); color: #fbbf24; border-color: var(--border); box-shadow: 0 8px 22px rgba(0,0,0,.5); }

/* AI 우측 패널이 열려 있으면 패널 폭(400px)만큼 왼쪽으로 피한다 */
.app-shell.ai-open .theme-fab { right: 426px; }
@media (max-width: 900px) {
    .app-shell.ai-open .theme-fab { right: 26px; }   /* 모바일에선 패널이 전체 폭 → 원위치 */
}

/* 카드 셸: 좌(이미지) + 우(폼) */
.login-shell {
    position: relative; z-index: 2;
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    width: 100%; max-width: 980px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 30px 70px rgba(23,44,92,.32);
    overflow: hidden;
}

/* 좌측 일러스트 패널 */
.login-art {
    background: linear-gradient(160deg, #f5f9ff 0%, #e8f1ff 100%);
    padding: 30px 30px 26px;
    display: flex; flex-direction: column; gap: 14px;
    min-width: 0;
}
.login-art-brand { display: flex; align-items: center; gap: 11px; }
.login-art-name { font-size: 16px; font-weight: 800; color: #1e3a8a; letter-spacing: -.3px; }
.login-art-img {
    flex: 1; width: 100%; min-height: 0;
    object-fit: contain; object-position: center;
    border-radius: 12px;
}
.login-art-desc { font-size: 13px; font-weight: 600; color: #64748b; text-align: center; }

/* 좁은 화면에서는 이미지 숨기고 폼만 */
@media (max-width: 820px) {
    .login-shell { grid-template-columns: 1fr; max-width: 420px; }
    .login-art { display: none; }
}

.login-logo-mark {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 19px; box-shadow: 0 8px 18px rgba(14,165,233,.4);
}
.login-logo-img { width: 40px; height: 40px; border-radius: 12px; object-fit: contain; padding: 3px; box-shadow: 0 8px 18px rgba(14,165,233,.35); background: #fff; }
.login-logo-text { font-size: 23px; font-weight: 800; color: #0c4a6e; letter-spacing: -.5px; }

/* 우측 로그인 폼 패널 */
.login-panel { display: flex; align-items: center; background: #fff; min-width: 0; }
.login-card {
    width: 100%;
    padding: 40px 38px;
    box-sizing: border-box;
}
.login-card-head { margin-bottom: 22px; }
/* 입력 라벨 */
.login-label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-muted); margin: 0 0 6px; }
.login-title { margin: 0; font-size: 23px; font-weight: 800; color: #2f2b50; letter-spacing: -.3px; }
.login-sub { margin: 6px 0 0; font-size: 13px; color: #9c99bd; }

/* 입력 필드 — 테마 변수 기반이라 라이트/다크 모두 자동 대응 */
.login-field {
    display: flex; align-items: center; gap: 10px;
    background: var(--input-bg); border: 1px solid var(--border); border-radius: 11px;
    padding: 0 14px; margin-bottom: 13px; transition: border-color .15s, box-shadow .15s, background .15s;
}
.login-field i { color: var(--text-light); font-size: 15px; width: 18px; text-align: center; }
.login-field:focus-within { background: var(--card); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.login-input {
    flex: 1; border: none; background: transparent; outline: none;
    padding: 13px 0; font-size: 14px; color: var(--text); font-family: inherit;
}
.login-input::placeholder { color: var(--text-light); }
/* 비밀번호 보기 토글(눈 아이콘) */
.login-eye {
    border: none; background: transparent; cursor: pointer; padding: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px; transition: background .15s, color .15s;
}
.login-eye i { color: #b4b1cf; font-size: 14px; width: 16px; transition: color .15s; }
.login-eye:hover i { color: #0ea5e9; }
.login-eye:hover { background: rgba(14,165,233,.10); }

.login-btn {
    width: 100%; padding: 14px; border: none; border-radius: 11px; margin-top: 8px;
    background: linear-gradient(135deg, #0ea5e9, #38bdf8); color: #fff;
    font-size: 15px; font-weight: 700; cursor: pointer;
    box-shadow: 0 10px 22px rgba(14,165,233,.35); transition: filter .15s, box-shadow .15s, opacity .15s;
}
.login-btn:hover:not(:disabled) { filter: brightness(1.05); box-shadow: 0 12px 26px rgba(14,165,233,.45); }
.login-btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.login-remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin: 4px 2px 6px; cursor: pointer; user-select: none; }
.login-remember input { width: 15px; height: 15px; accent-color: #0ea5e9; cursor: pointer; }
.login-error { background: var(--error-soft); color: var(--error-text); padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.login-foot { text-align: center; font-size: 12px; color: var(--text-light); margin-top: 22px; }

@media (max-width: 720px) {
    .login-page { padding: 16px; }
    .login-card { padding: 32px 24px; }
}

/* ---------- 로그인: 다크 모드 ---------- */
[data-theme="dark"] .login-page {
    background: linear-gradient(135deg, #16233d 0%, #101a2e 55%, #0b1220 100%);
}
[data-theme="dark"] .login-shell {
    background: var(--card);
    box-shadow: 0 30px 70px rgba(0,0,0,.55);
    border: 1px solid var(--border);
}
[data-theme="dark"] .login-art {
    background: linear-gradient(160deg, var(--surface-2) 0%, var(--surface-3) 100%);
}
[data-theme="dark"] .login-art-name { color: var(--text); }
[data-theme="dark"] .login-art-desc { color: var(--text-muted); }

[data-theme="dark"] .login-panel { background: var(--card); }
[data-theme="dark"] .login-title { color: var(--text); }
[data-theme="dark"] .login-sub { color: var(--text-muted); }

[data-theme="dark"] .login-eye i { color: var(--text-light); }
[data-theme="dark"] .login-eye:hover i { color: var(--primary); }
[data-theme="dark"] .login-eye:hover { background: var(--primary-soft); }

[data-theme="dark"] .login-logo-text { color: var(--text); }

/* ---------- 유틸 ---------- */
.text-muted-x { color: var(--text-muted); }
.text-light-x { color: var(--text-light); }
.fw-7 { font-weight: 700; }
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.mt-3 { margin-top: 12px; } .mt-4 { margin-top: 18px; }
.spin { width: 34px; height: 34px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: sp 0.7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.center-screen { display: flex; align-items: center; justify-content: center; height: 70vh; flex-direction: column; gap: 14px; color: var(--text-light); }

#blazor-error-ui { background: var(--warning-soft); color: var(--text); bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: 0.8rem 1.4rem; position: fixed; width: 100%; z-index: 1000; }
    #blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ---------- 마스터-디테일 분할 패널 + 패널 타이틀/도구 (Scr1202 스타일) ---------- */
.split-v { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.split-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.pane-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 13.5px; color: var(--text); margin-bottom: 8px; flex: 0 0 auto; }
.pane-title i { color: var(--primary); }
.pane-tools { margin-left: auto; display: flex; gap: 6px; }

/* 패널 도구 버튼: 작은 크기 + 선명한 단색 (완전 필(pill) 대신 약간 완화된 라운드) */
.pane-tools .btn-x {
    padding: 6px 13px; border-radius: 10px; font-size: 12.5px; font-weight: 700; gap: 5px;
    box-shadow: none;
}
.pane-tools .btn-x i { display: none; }
.pane-tools .btn-ghost { background: var(--card); border: 1px solid var(--border); color: var(--text-muted); }
.pane-tools .btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.pane-tools .btn-add-x { background: var(--primary); color: #fff; border: none; }
.pane-tools .btn-add-x:hover:not(:disabled) { background: var(--primary-dark); }

.pane-tools .btn-edit-x { background: var(--primary-dark); color: #fff; border: none; }
.pane-tools .btn-edit-x:hover:not(:disabled) { filter: brightness(0.92); }

.pane-tools .btn-del-x { background: linear-gradient(135deg, #f87171, #dc2626); color: #fff; border: none; box-shadow: 0 3px 8px rgba(220, 38, 38, .35); }
.pane-tools .btn-del-x:hover:not(:disabled) { background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 4px 10px rgba(220, 38, 38, .45); }

.pane-tools .btn-primary-x { background: var(--primary); color: #fff; border: none; box-shadow: none; }
.pane-tools .btn-primary-x:hover:not(:disabled) { background: var(--primary-dark); filter: none; box-shadow: none; }

/* 패널 도구 줄에 끼워 넣는 소형 날짜 입력(기간 조회 등) */
.mdl-field-inline {
    border: 1px solid var(--border); border-radius: 7px; padding: 5px 9px;
    font-size: 12.5px; font-family: inherit; color: var(--text); background: var(--card); outline: none;
}
.mdl-field-inline:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* 컬러 액션 버튼 (btn-x 변형, 다른 화면 공용) */
.btn-add-x { background: var(--primary); color: #fff; border-color: transparent; }
.btn-add-x:hover:not(:disabled) { filter: brightness(1.07); }
.btn-edit-x { background: rgba(245,158,11,.12); color: #b45309; border-color: rgba(245,158,11,.35); }
.btn-edit-x:hover:not(:disabled) { background: rgba(245,158,11,.2); }
.btn-del-x { background: rgba(239,68,68,.1); color: #dc2626; border-color: rgba(239,68,68,.3); }
.btn-del-x:hover:not(:disabled) { background: rgba(239,68,68,.18); }
.btn-x:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 편집/확인 모달 ---------- */
.mdl-overlay { position: fixed; inset: 0; z-index: 1600; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; animation: drop-in .14s ease; }
.mdl-box { width: 480px; max-width: 94vw; max-height: 88vh; overflow: auto; background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 24px 60px rgba(15,23,42,.28); }
.mdl-head { display: flex; align-items: center; gap: 9px; padding: 15px 20px 12px; font-weight: 800; font-size: 15px; color: var(--text); border-bottom: 1px solid var(--border); }
.mdl-head i { color: var(--primary); }
.mdl-body { padding: 14px 20px 6px; }
.mdl-field { margin-bottom: 11px; }

/* 모달 내 "추가 정보(선택)" 접기 영역 */
.mdl-more { margin: 4px 0 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
.mdl-more > summary { cursor: pointer; list-style: none; font-size: 12.5px; font-weight: 700; color: var(--text-muted); padding: 4px 2px; user-select: none; display: flex; align-items: center; gap: 6px; }
.mdl-more > summary::-webkit-details-marker { display: none; }
.mdl-more > summary::before { content: "▸"; font-size: 11px; transition: transform .15s; }
.mdl-more[open] > summary::before { transform: rotate(90deg); }
.mdl-more > summary:hover { color: var(--primary); }
.mdl-more[open] > summary { margin-bottom: 8px; }
.mdl-field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-light); margin-bottom: 5px; }
.mdl-field input, .mdl-field select, .mdl-field textarea { width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px; font-size: 13.5px; font-family: inherit; color: var(--text); background: var(--card); outline: none; box-sizing: border-box; }
.mdl-field input:focus, .mdl-field select:focus, .mdl-field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.mdl-field input:disabled { background: var(--border); opacity: .7; }
.mdl-row { display: flex; gap: 10px; }
.mdl-row .mdl-field { flex: 1; }
.mdl-error { margin: 0 20px 4px; padding: 9px 13px; border-radius: 9px; background: rgba(239,68,68,.1); color: #dc2626; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.mdl-error.mdl-ok { background: rgba(34,197,94,.12); color: #15803d; }
.mdl-confirm-msg { padding: 18px 20px 8px; font-size: 14px; color: var(--text); line-height: 1.6; }
.mdl-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }

/* ---------- 모달 내 품목 선택 ---------- */
.item-pick { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.item-pick-search { display: flex; align-items: center; gap: 8px; padding: 7px 11px; border-bottom: 1px solid var(--border); }
.item-pick-search i { color: var(--text-light); font-size: 12px; }
.item-pick-search input { flex: 1; border: none !important; outline: none; padding: 2px 0 !important; font-size: 13.5px; box-shadow: none !important; }
.item-pick-list { max-height: 180px; overflow: auto; }
.item-pick-row { display: flex; align-items: center; gap: 9px; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.item-pick-row:hover { background: var(--primary-soft); }
.item-pick-name { flex: 1; color: var(--text); }
.item-pick-empty { padding: 16px 12px; text-align: center; font-size: 12.5px; color: var(--text-light); }
.item-picked { display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 13.5px; background: var(--primary-soft); }
.item-picked-x { margin-left: auto; border: none; background: transparent; color: var(--text-light); cursor: pointer; font-size: 13px; }
.item-picked-x:hover { color: var(--error); }
.mono { font-family: Consolas, 'Courier New', monospace; font-size: 12.5px; color: var(--text-light); }

/* ══════════════════════════════════════════════════════════════
   서버 연결 끊김 안내 (Blazor 기본 영문 오버레이 대체)
   Blazor 가 #components-reconnect-modal 에 아래 클래스를 붙인다:
     components-reconnect-show    → 재연결 시도 중
     components-reconnect-failed  → 재시도 모두 실패
     components-reconnect-rejected→ 서버가 세션을 거부(만료)
   ══════════════════════════════════════════════════════════════ */
#components-reconnect-modal {
    display: none;
    position: fixed; inset: 0; z-index: 20000;
    align-items: center; justify-content: center;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px);
}
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected { display: flex; }

.uu-rc-card {
    width: min(420px, calc(100vw - 40px));
    padding: 30px 28px 26px;
    text-align: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
    animation: uu-rc-in .18s ease-out;
}

@keyframes uu-rc-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

/* 상태별로 해당 블록만 노출 */
.uu-rc-state { display: none; flex-direction: column; align-items: center; gap: 10px; }
#components-reconnect-modal.components-reconnect-show    .uu-rc-retrying { display: flex; }
#components-reconnect-modal.components-reconnect-failed   .uu-rc-retrying { display: none; }
#components-reconnect-modal.components-reconnect-rejected .uu-rc-retrying { display: none; }
#components-reconnect-modal.components-reconnect-failed   .uu-rc-failed   { display: flex; }
#components-reconnect-modal.components-reconnect-rejected .uu-rc-rejected { display: flex; }

.uu-rc-spin {
    width: 46px; height: 46px; margin-bottom: 4px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: uu-rc-spin .8s linear infinite;
}
@keyframes uu-rc-spin { to { transform: rotate(360deg); } }

.uu-rc-ico {
    width: 54px; height: 54px; margin-bottom: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; border-radius: 50%;
}
.uu-rc-ico.warn { color: var(--error-text, #b91c1c); background: var(--error-soft, #fee2e2); }

.uu-rc-title { font-size: 16.5px; font-weight: 800; color: var(--text); }
.uu-rc-desc  { font-size: 13px; line-height: 1.65; color: var(--text-muted); }
.uu-rc-meta  { font-size: 12px; color: var(--text-light); }
.uu-rc-meta b { color: var(--primary); }

.uu-rc-btns { display: flex; gap: 8px; margin-top: 6px; }
.uu-rc-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; cursor: pointer; font-family: inherit;
    font-size: 13px; font-weight: 700;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--card); color: var(--text);
    transition: all .15s;
}
.uu-rc-btn:hover { border-color: var(--primary); color: var(--primary); }
.uu-rc-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.uu-rc-btn.primary:hover { background: var(--primary-dark); color: #fff; }

/* ══════════════════════════════════════════════════════════════
   스크롤바 전역 스타일
   기본 OS 스크롤바(회색 각진 막대)가 다크 테마에서 특히 튀어서
   얇고 둥근 형태로 통일한다. 마우스를 올리면 진해진다.
   ══════════════════════════════════════════════════════════════ */

/* Firefox */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }

:root {
    --scroll-thumb: rgba(100, 116, 139, .38);
    --scroll-thumb-hover: rgba(100, 116, 139, .62);
}
[data-theme="dark"] {
    --scroll-thumb: rgba(148, 163, 184, .30);
    --scroll-thumb-hover: rgba(148, 163, 184, .55);
}

/* WebKit / Chromium */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 8px;
    /* 투명 테두리로 트랙과 간격을 만들어 얇아 보이게 한다 */
    border: 3px solid transparent;
    background-clip: content-box;
    transition: background-color .15s;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: content-box; }
::-webkit-scrollbar-thumb:active { background: var(--primary); background-clip: content-box; }
/* 양끝 화살표 버튼과 코너 제거 */
::-webkit-scrollbar-button { display: none; }
::-webkit-scrollbar-corner { background: transparent; }

/* ══════════════════════════════════════════════════════════════
   모바일(스마트폰) 보정 — 햄버거/사이드바 슬라이드는 기존 900px 블록이 담당.
   여기서는 화면 안 콘텐츠(조회 도구줄·그리드 툴바·모달·폼)를 좁은 폭에 맞춘다.
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    /* 화면 제목 + 조회 도구: 한 줄 고정(nowrap)이라 375px 에서 화면을 넘쳤다.
       제목 아래로 도구줄이 내려와 전체 폭을 쓰며 줄바꿈되게 한다. */
    .pane-title { flex-wrap: wrap; row-gap: 8px; }
    .pane-tools { margin-left: 0; flex-basis: 100%; flex-wrap: wrap; row-gap: 6px; }
    .pane-tools .mdl-field-inline { flex: 1 1 130px; min-width: 0; }
    .pane-tools .btn-x { flex: 0 0 auto; }

    /* 그리드 툴바(검색·Excel·열 선택): 줄바꿈 + 안내문은 공간 없으면 숨김 */
    .dxgrid-toolbar { flex-wrap: wrap; row-gap: 6px; }
    .search-box-inline { flex: 1 1 100%; }
    .search-box-inline input { width: 100%; }
    .dxgrid-toolbar > .text-light-x { display: none; }

    /* 모달: 화면을 거의 채우고, 2칸 행은 세로로 */
    .mdl-overlay { padding: 10px; }
    .mdl-box { width: 100%; max-width: 100%; max-height: 92vh; }
    .mdl-row { flex-direction: column; gap: 0; }

    /* 카드 안 표: 옆으로 스크롤 (열 압착 방지) */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-x { min-width: 480px; }

    /* 대시보드 지표 카드: 2열 (1열은 세로로 너무 길다) */
    .grid-5 { grid-template-columns: 1fr 1fr !important; }

    /* 터치 대상 최소 크기 확보 */
    .btn-x { min-height: 36px; }
    .topbar-icon { width: 38px; height: 38px; }
}

/* 클릭 가능한 지표 카드 (대시보드 → 관련 화면 이동) */
.stat-card.clickable { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.stat-card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: var(--primary); }

/* 상단바 로그인 유지 남은 시간 배지 (theme.js uuresIdle 이 매초 갱신) */
.idle-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 11px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface-2);
    font-size: 12px; font-weight: 700; color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.idle-badge i { font-size: 11px; color: var(--text-light); }
/* 만료 60초 전(카운트다운 구간)에는 붉게 강조 */
.idle-badge #idle-remain.warn { color: var(--error-text); }
@media (max-width: 640px) { .idle-badge { display: none; } 
}

/* 대시보드 재고 부족 행의 [발주] 버튼 — 표 행 높이에 맞춘 소형 */
.dash-po-btn { padding: 2px 8px; font-size: 11.5px; min-height: 0; margin-left: 6px; border-radius: 8px; }
.dash-po-btn i { font-size: 10.5px; margin-right: 2px; }

/* 대시보드 표: 데이터를 자르지 않고 전부 보여주되, 카드가 무한정 길어지지 않게 안에서 스크롤 */
.dash-scroll { max-height: 340px; overflow-y: auto; }
.dash-scroll thead th { position: sticky; top: 0; background: var(--card); z-index: 1; }

/* ── 대시보드 모바일 보정 ──
   grid 자식의 min-width 기본값(auto) 때문에 카드 안의 넓은 표(min-width:480px)가
   grid 칸 자체를 밀어내 카드 폭이 서로 달라지고 화면을 넘쳤다.
   min-width:0 을 주면 카드는 화면 폭에 맞고, 표는 카드 안에서 가로 스크롤된다. */
.grid > * { min-width: 0; }

/* 배지(유형/부족/상태)와 숫자 셀은 세로로 꺾이면 읽을 수 없다 — 항상 한 줄 */
.badge-soft { white-space: nowrap; }
.table-x th, .table-x td { white-space: nowrap; }

/* 대시보드/일반 표 공용 — 모바일(≤640px)에서 부차 컬럼 숨김용 (그리드의 .m-hide 와 동일 규칙) */
.cell-ellip { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
    .m-hide { display: none !important; }
}

/* 경영 대시보드 연도 전환 (월별 매출·매입) */
.year-nav { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; }
.year-nav .btn-x { padding: 3px 9px; min-height: 0; }
.year-nav-label { font-size: 13px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; min-width: 62px; text-align: center; }

.mmchart-legend {
    display: flex; align-items: center; flex-wrap: wrap; gap: 16px;
    font-size: 12.5px; color: var(--text-light);
    padding: 2px 4px 14px;
}
.mmchart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.mmchart-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.mmchart-sum { margin-left: auto; color: var(--text); }
.mmchart-sum b { font-weight: 700; }

.mmchart-group { cursor: pointer; }
.mmchart-bar { transition: opacity .12s; }

.mmchart-tip {
    position: absolute; top: 4px; transform: translateX(-50%);
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg, var(--shadow)); padding: 9px 12px;
    font-size: 12px; white-space: nowrap; pointer-events: none; z-index: 5;
    min-width: 128px;
}
.mmchart-tip-head { font-weight: 800; font-size: 12.5px; color: var(--text); margin-bottom: 5px; }
.mmchart-tip-row { display: flex; align-items: center; gap: 6px; color: var(--text-light); padding: 1px 0; }
.mmchart-tip-row b { margin-left: auto; color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.mmchart-tip-diff { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.mmchart-tip-diff span { color: var(--text-light); }

/* ───────── 첨부파일 (AttachFiles 공용 컴포넌트, G29) ───────── */
.attach-box { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 10px; background: var(--bg); }
.attach-head { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 12.5px; color: var(--text); }
.attach-head > i { color: var(--primary); }
.attach-count { background: var(--primary-soft); color: var(--primary); border-radius: 12px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
.attach-add { margin-left: auto; position: relative; overflow: hidden; cursor: pointer; font-size: 12px; }
.attach-add input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.attach-add.disabled { pointer-events: none; opacity: .6; }
.attach-empty { font-size: 12px; color: var(--text-light); padding: 8px 2px 2px; }
.attach-error { font-size: 12px; color: var(--error); padding: 6px 2px 0; }
.attach-list { display: flex; flex-direction: column; gap: 2px; margin-top: 7px; }
.attach-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 7px; font-size: 12.5px; }
.attach-row:hover { background: var(--hover); }
.attach-row > i { color: var(--text-light); width: 16px; text-align: center; }
.attach-name { color: var(--text); text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.attach-name:hover { color: var(--primary); text-decoration: underline; }
.attach-meta { margin-left: auto; color: var(--text-light); font-size: 11px; white-space: nowrap; }
.attach-del { border: 0; background: transparent; color: var(--text-light); cursor: pointer; border-radius: 6px; width: 22px; height: 22px; }
.attach-del:hover { color: var(--error); background: var(--hover); }

/* 거래처유형 배지 색상 — 수주처/발주처가 한눈에 구분되도록 */
.badge-soft.ct-o { background: rgba(19, 222, 185, .16); color: #0d9c82; }   /* 수주처 */
.badge-soft.ct-i { background: rgba(255, 174, 31, .18); color: #c07f00; }   /* 발주처 */
.badge-soft.ct-a { background: rgba(139, 92, 246, .16); color: #7c3aed; }   /* 수·발주처 */
.badge-soft.ct-e { background: rgba(14, 165, 233, .15); color: #0284c7; }   /* 외주가공처 */
.badge-soft.ct-p { background: rgba(148, 163, 184, .2); color: #64748b; }   /* 개인고객 */
[data-theme="dark"] .badge-soft.ct-o, .dark .badge-soft.ct-o { color: #2fe3c0; }
[data-theme="dark"] .badge-soft.ct-i, .dark .badge-soft.ct-i { color: #ffc14d; }
[data-theme="dark"] .badge-soft.ct-a, .dark .badge-soft.ct-a { color: #b198fa; }
[data-theme="dark"] .badge-soft.ct-e, .dark .badge-soft.ct-e { color: #4cc3f7; }
[data-theme="dark"] .badge-soft.ct-p, .dark .badge-soft.ct-p { color: #a5b4cd; }

/* 기간 조회 바 (DateRangeBar 공용 컴포넌트) */
.daterange { display: inline-flex; align-items: center; gap: 6px; }
.daterange-input {
    height: 32px; padding: 0 8px; font-size: 12.5px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--card); color: var(--text);
}
.daterange-sep { color: var(--text-light); font-size: 12px; }

/* ───────── AI 차트 확대 보기 (라이트박스) ───────── */
.ai-chart-zoomable { cursor: zoom-in; position: relative; border-radius: 10px; transition: box-shadow .15s, transform .15s; }
.ai-chart-zoomable:hover { box-shadow: 0 0 0 2px var(--primary-soft); }
.ai-zoom-overlay {
    position: fixed; inset: 0; z-index: 2200;
    background: rgba(15, 15, 26, .62);
    display: flex; align-items: center; justify-content: center;
    padding: 24px; backdrop-filter: blur(2px);
}
.ai-zoom-box {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.35);
    max-width: min(1100px, 94vw); max-height: 90vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.ai-zoom-head {
    display: flex; align-items: center; gap: 9px;
    padding: 13px 16px; border-bottom: 1px solid var(--border);
    font-weight: 800; font-size: 14.5px; color: var(--text);
}
.ai-zoom-head i { color: var(--primary); }
.ai-zoom-close {
    margin-left: auto; border: 0; background: transparent; cursor: pointer;
    color: var(--text-light); width: 30px; height: 30px; border-radius: 8px; font-size: 15px;
}
.ai-zoom-close:hover { background: var(--hover); color: var(--text); }
.ai-zoom-body { padding: 18px 20px 22px; overflow: auto; }
.ai-zoom-body svg { width: 100%; height: auto; }
