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

:root {
    --bg: #141820;
    --panel: #1c2230;
    --card: #232d3f;
    --border: #2e3a50;
    --accent: #4f8ef7;
    --accent-dim: #2a4a80;
    --text: #e2e8f0;
    --text-dim: #6b7a96;
    --hover: #252f42;
    --selected: #1e3560;
    --green: #34d399;
    --yellow: #fbbf24;
    --red: #f87171;
    --font: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── 헤더 ── */
#header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: 48px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#header h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.biz-tabs { display: flex; gap: 4px; }
.biz-tab {
    padding: 5px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    border: 1px solid var(--border);
    color: var(--text-dim);
    transition: all 0.15s;
}
.biz-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-weight: 600;
}

.nav-tabs { display: flex; gap: 2px; margin-left: auto; }
.nav-tab {
    padding: 5px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dim);
}
.nav-tab:hover { color: var(--text); background: var(--hover); }
.nav-tab.active { color: var(--text); background: var(--card); }

/* ── 검색 영역 (상단 고정) ── */
#search-area {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    flex-shrink: 0;
    position: relative;
}

#search-wrap {
    position: relative;
    max-width: 440px;
}

#search-input {
    width: 100%;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 9px 14px;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-dim); }

/* 자동완성 드롭다운 */
#autocomplete {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 100;
    overflow: hidden;
    display: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    max-height: 280px;
    overflow-y: auto;
}
#autocomplete.show { display: block; }

.ac-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.focused { background: var(--selected); }
.ac-item .ac-name { font-size: 14px; font-weight: 500; }
.ac-item .ac-bank { font-size: 11px; color: var(--text-dim); }
.ac-item .ac-count { font-size: 11px; color: var(--accent); background: var(--accent-dim); padding: 1px 6px; border-radius: 10px; }

#selected-vendor-bar {
    display: none;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    font-size: 13px;
}
#selected-vendor-bar.show { display: flex; }
#selected-vendor-bar strong { font-size: 15px; color: var(--accent); }
#selected-vendor-bar .bank-info { color: var(--text-dim); font-size: 12px; }
#clear-vendor { cursor: pointer; color: var(--text-dim); font-size: 18px; margin-left: auto; padding: 0 4px; }
#clear-vendor:hover { color: var(--red); }

/* ── 메인 영역 ── */
#main { display: flex; flex: 1; overflow: hidden; }

/* ── 페이지 ── */
.page { display: none; flex: 1; overflow: hidden; }
.page.active { display: flex; }

/* ── 결재 내역 페이지 ── */
#page-payments {
    flex-direction: row;
    gap: 0;
}

/* ── 좌측: 결재 추가 폼 (메인) ── */
#add-panel {
    width: 340px;
    min-width: 300px;
    border-right: 2px solid var(--accent-dim);
    background: var(--card);
    display: flex;
    flex-direction: column;
    padding: 24px 24px 20px;
    gap: 0;
    flex-shrink: 0;
    overflow-y: auto;
}

#add-panel h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.3px;
}

.period-display {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.period-display strong { color: var(--accent); font-size: 14px; }

.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 5px;
    letter-spacing: 0.3px;
}
.field input, .field select {
    width: 100%;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.field input:focus, .field select:focus { border-color: var(--accent); }

.field .hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* 체크박스 */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    cursor: pointer;
    user-select: none;
}
.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}
.checkbox-row .cb-label { font-size: 14px; }
.checkbox-row .cb-hint { font-size: 11px; color: var(--text-dim); margin-left: auto; }

/* 세액 미리보기 */
#tax-preview {
    background: var(--card);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
    display: none;
    border: 1px solid var(--border);
}
#tax-preview .tp-row { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text-dim); }
#tax-preview .tp-total { display: flex; justify-content: space-between; padding-top: 6px; margin-top: 4px; border-top: 1px solid var(--border); font-weight: 600; color: var(--text); }

/* 저장 버튼 */
#save-btn {
    width: 100%;
    padding: 13px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-family: var(--font);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s;
    margin-top: 6px;
    letter-spacing: 0.3px;
}
#save-btn:hover { opacity: 0.85; }
#save-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.add-panel-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 13px;
    text-align: center;
    line-height: 2;
}

/* ── 우측: 결재 내역 (참고) ── */
#history-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

#history-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
#history-header h3 { font-size: 14px; font-weight: 600; }
#history-header .total-badge {
    font-size: 12px;
    color: var(--text-dim);
    background: var(--card);
    padding: 2px 10px;
    border-radius: 10px;
}

#history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.history-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    cursor: pointer;
    transition: background 0.1s;
}
.history-item:hover { background: var(--hover); }
.history-item:last-child { border-bottom: none; }

.history-item .hi-date {
    font-size: 13px;
    color: var(--text);
    min-width: 70px;
    font-variant-numeric: tabular-nums;
}
/* 기수별 그룹 헤더 */
.history-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 20px;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    background: var(--panel);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}
.history-group:first-child .history-group-header { border-top: none; }
.gh-sum { color: var(--text-dim); font-size: 11px; font-weight: 400; font-variant-numeric: tabular-nums; }
.history-item .hi-amount {
    font-size: 14px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    min-width: 90px;
}
.history-item .hi-memo {
    flex: 1;
}
.history-item .hi-tax {
    font-size: 10px;
    background: var(--yellow);
    color: #000;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 600;
}
.history-item .hi-cross {
    font-size: 10px;
    background: var(--accent-dim);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 3px;
}
.history-item .hi-del {
    font-size: 18px;
    color: var(--border);
    opacity: 0;
    cursor: pointer;
    padding: 0 2px;
    transition: color 0.1s;
}
.history-item:hover .hi-del { opacity: 1; }
.history-item .hi-del:hover { color: var(--red); }

.history-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    font-size: 13px;
}

/* ── 결재리스트 / 세금계산서 페이지 ── */
#page-list, #page-tax {
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
    gap: 16px;
}

.page-title { font-size: 16px; font-weight: 600; }

.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-bar label { font-size: 12px; color: var(--text-dim); }
.filter-bar select, .filter-bar input {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 12px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
}

.btn {
    padding: 7px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    transition: all 0.15s;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { opacity: 0.85; }
.btn.success { background: var(--green); border-color: var(--green); color: #000; font-weight: 600; }

.summary-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.summary-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 18px;
    min-width: 140px;
}
.summary-card .sc-label { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.summary-card .sc-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--panel);
    padding: 9px 12px;
    text-align: left;
    font-size: 12px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
tbody tr:hover { background: var(--hover); }
.amount-cell { text-align: right; font-variant-numeric: tabular-nums; }

/* ── 세금계산서 ── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}
.upload-zone:hover { border-color: var(--accent); }

/* ── 스크롤바 ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.ml-auto { margin-left: auto; }

/* ── 거래처 관리 ── */
.vm-cnt {
    display: inline-block;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.vm-cnt.zero {
    background: var(--card);
    color: var(--text-dim);
}

/* ── 수정 드로어 (history item 클릭 시) ── */
.edit-row {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.edit-row input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    width: 110px;
}
.edit-row input:focus { border-color: var(--accent); }
.edit-row .edit-actions { display: flex; gap: 6px; margin-left: auto; }
