:root {
    --bg-main: #f0f2f5;
    --bg-card: #ffffff;
    --bg-card-hover: #f5f8ff;
    --border: #d0d7de;
    --border-light: #e8ecf0;
    --text-primary: #1f2328;
    --text-secondary: #57606a;
    --text-muted: #8b949e;
    --accent-blue: #0969da;
    --accent-green: #1a7f37;
    --accent-yellow: #bf8700;
    --accent-red: #cf222e;
    --accent-cyan: #0a8b8b;
    --bar-bg: #e8ecf0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* === 헤더 === */
.header {
    position: sticky; top: 0; z-index: 100;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-bottom: 2px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    display: flex; justify-content: space-between; align-items: center;
    height: 50px;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.header-title { font-size: 16px; font-weight: 700; color: var(--accent-cyan); }
.header-time { font-size: 12px; color: var(--text-muted); }
.header-controls { display: flex; align-items: center; gap: 8px; }
.hours-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.hours-btn {
    width: 30px; height: 30px;
    border: 2px solid var(--border); background: #fff; color: var(--text-primary);
    border-radius: 8px; font-size: 16px; font-weight: 700;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.hours-btn:hover { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.hours-value { font-size: 20px; font-weight: 700; color: var(--accent-blue); min-width: 28px; text-align: center; }
.hours-unit { font-size: 13px; color: var(--text-secondary); }

/* === 메인 레이아웃 === */
.main-layout {
    display: flex;
    height: calc(100vh - 50px);
    overflow: hidden;
}

.left-panel {
    width: 66%;
    min-width: 200px;
    background: var(--bg-card);
    border-right: none;
    border-left: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    overflow: auto;
    order: 2;
}

.right-panel {
    width: 33%;
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    order: 0;
}

/* === 드래그 분할바 === */
.divider {
    width: 6px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
    order: 1;
}
.divider:hover, .divider:active {
    background: var(--accent-blue);
}
.divider::after {
    content: '⋮';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    pointer-events: none;
}

/* === 패널 제목 === */
.panel-title {
    font-size: 14px; font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px; padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

/* === 스프레드시트 === */
.sheet-info {
    display: flex; gap: 12px; flex-wrap: wrap;
    font-size: 12px; color: var(--text-secondary);
    margin-bottom: 8px; padding: 6px 8px;
    background: #f8f9fa; border-radius: 6px;
    flex-shrink: 0;
}
.sheet-info b { color: var(--text-primary); }

#spreadsheet { flex: 1; overflow: auto; }

.sheet-actions {
    margin-top: 8px; display: flex; gap: 8px; flex-shrink: 0;
}
.action-btn {
    padding: 6px 14px;
    border: 1px solid var(--accent-blue); background: var(--accent-blue); color: #fff;
    border-radius: 6px; font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all 0.15s;
}
.action-btn:hover { opacity: 0.85; }
.action-btn.secondary { background: #fff; color: var(--accent-blue); }

/* === 빈 그리드 1열×8행 === */
.bins-grid {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(8, 1fr);
    gap: 3px;
    flex: 1;
    overflow: hidden;
}

.bin-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 0.5em;
    padding: 0.4em 0.5em;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column;
    position: relative; overflow: hidden;
    transition: all 0.2s;
}
.bin-card:hover { border-color: var(--accent-blue); box-shadow: 0 2px 8px rgba(9,105,218,0.12); }

.bin-card::before {
    content: '';
    position: absolute; left: 0; top: 0; bottom: 0; width: 0.25em;
}
.bin-card.status-normal::before { background: var(--accent-green); }
.bin-card.status-warning::before { background: var(--accent-yellow); }
.bin-card.status-alert::before { background: var(--accent-red); }

.bin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2em; }
.bin-name { font-size: 1em; font-weight: 700; }
.bin-env { font-size: 0.75em; color: var(--text-muted); margin-bottom: 0.4em; }

.status-dot { width: 0.6em; height: 0.6em; border-radius: 50%; }
.status-dot.normal { background: var(--accent-green); box-shadow: 0 0 4px rgba(26,127,55,0.4); }
.status-dot.warning { background: var(--accent-yellow); animation: pulse 2s infinite; }
.status-dot.alert { background: var(--accent-red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

.bin-bar-wrapper {
    height: 1.3em; background: var(--bar-bg); border-radius: 0.35em;
    overflow: hidden; margin-bottom: 0.5em; position: relative;
    border: 1px solid var(--border-light);
}
.bin-bar-fill {
    height: 100%; border-radius: 0.3em;
    transition: width 0.8s ease;
    background: linear-gradient(90deg, #34d399, #0ea5e9);
}
.bin-bar-text {
    position: absolute; right: 0.4em; top: 50%; transform: translateY(-50%);
    font-size: 0.75em; font-weight: 700; color: var(--text-primary);
}

.bin-data { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.25em; }
.data-item { text-align: center; padding: 0.2em 0; background: var(--bg-main); border-radius: 0.3em; }
.data-label { font-size: 0.6em; font-weight: 600; color: var(--text-muted); letter-spacing: 0.3px; }
.data-value { font-size: 0.85em; font-weight: 700; color: var(--text-primary); }
.data-value.positive { color: var(--accent-green); }
.data-value.negative { color: var(--accent-red); }
.data-value.water { color: var(--accent-blue); }

.bin-footer {
    margin-top: 0.3em;
    display: flex; justify-content: space-between; align-items: center;
}
.ratio { font-size: 0.65em; color: var(--text-muted); }
.judgment-tag {
    padding: 0.15em 0.5em; border-radius: 0.3em;
    font-size: 0.65em; font-weight: 700;
}
.judgment-normal { background: rgba(26,127,55,0.08); color: var(--accent-green); }
.judgment-warning { background: rgba(191,135,0,0.1); color: var(--accent-yellow); }
.judgment-alert { background: rgba(207,34,46,0.1); color: var(--accent-red); }

.loading { text-align: center; padding: 2em; color: var(--text-muted); font-size: 0.9em; grid-column: span 2; }

/* jspreadsheet 오버라이드 */
.jexcel_container { font-size: 13px !important; }
.jexcel thead td { font-size: 12px !important; font-weight: 600 !important; background: #f0f4f8 !important; color: #000 !important; }
.jexcel td { font-size: 14px !important; padding: 4px 6px !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* === 회차 선택 === */
#batchSelect {
    margin-left: 8px; padding: 2px 6px;
    border: 1px solid var(--border); border-radius: 4px;
    font-size: 12px; font-weight: 600;
}
.batch-btn {
    margin-left: 4px; padding: 2px 8px;
    border: 1px solid var(--accent-blue); background: #fff; color: var(--accent-blue);
    border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer;
}
.batch-btn:hover { background: var(--accent-blue); color: #fff; }

/* === sheet-info 입력 === */
.sheet-info input[type="number"] {
    width: 80px; padding: 2px 4px;
    border: 1px solid var(--border); border-radius: 4px;
    font-size: 12px; font-weight: 600; text-align: right;
}
.sheet-info label { display: flex; align-items: center; gap: 4px; font-weight: 500; }

/* === 하단 집계 === */
.summary-section {
    flex-shrink: 0;
    margin-top: 8px; padding: 10px 12px;
    background: #f8f9fa; border-radius: 6px;
    border: 1px solid var(--border-light);
}
.summary-title { font-size: 14px; font-weight: 800; margin-bottom: 8px; color: var(--text-primary); }
.summary-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
.summary-table th, .summary-table td {
    padding: 5px 8px; border: 1px solid var(--border-light); text-align: center; font-weight: 600;
}
.summary-table th { background: #eef1f5; text-align: center; font-weight: 700; color: #000; }
.total-row { background: #e8f4fd; color: var(--accent-blue); font-weight: 800; }
.summary-calc {
    display: flex; align-items: center; gap: 12px;
    margin-top: 8px; font-size: 14px; font-weight: 700;
}
.summary-calc input {
    width: 80px; padding: 4px 6px;
    border: 1px solid var(--border); border-radius: 4px;
    font-size: 14px; font-weight: 700; text-align: right;
}

/* === 입고 팝업 === */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.modal {
    background: #fff; border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 520px; max-height: 80vh; overflow: auto;
}
.modal-header {
    padding: 12px 16px; font-size: 14px; font-weight: 700;
    border-bottom: 1px solid var(--border-light);
    display: flex; justify-content: space-between; align-items: center;
    gap: 8px;
}
#feedTypeSelect {
    padding: 3px 8px; border: 1px solid var(--accent-blue);
    border-radius: 4px; font-size: 12px; font-weight: 600;
    color: var(--accent-blue); background: #f0f7ff;
}
.modal-close {
    border: none; background: none; font-size: 18px; cursor: pointer; color: var(--text-muted);
}
.modal-body { padding: 12px 16px; }
.modal-footer {
    padding: 10px 16px; border-top: 1px solid var(--border-light);
    display: flex; align-items: center; gap: 10px;
}
.modal-footer span { flex: 1; font-size: 14px; }
.truck-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.truck-grid label {
    display: flex; align-items: center; gap: 4px;
    font-size: 13px; font-weight: 600;
}
.truck-grid input {
    width: 90px; padding: 6px 8px;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 14px; font-weight: 600; text-align: right;
}

/* === 회차 폼 === */
.batch-form {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.batch-form label:first-child {
    grid-column: 1 / -1;
}
.batch-form label {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 600; white-space: nowrap;
}
.batch-form input {
    width: 0; flex: 1; min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; text-align: right;
}
.batch-form input[type="text"] { text-align: left; }
.batch-form input[type="date"] { text-align: center; }

/* 동별 수수 그리드 */
.chicks-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
    margin-top: 4px;
}
.chicks-grid label {
    display: flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.chicks-grid input {
    width: 0; flex: 1; min-width: 0;
    padding: 4px 6px; border: 1px solid var(--border);
    border-radius: 4px; font-size: 12px; text-align: right;
}
.batch-preview {
    margin-top: 10px; padding: 6px 10px;
    background: #e8f4fd; border-radius: 6px;
    font-size: 13px; color: var(--accent-blue);
}

/* 사료빈 카드 내 텍스트 흑백 통일 (증체비 오렌지색 제외) */
.bin-card * {
    color: #000 !important;
}
.bin-card span[style*="d97706"] {
    color: #d97706 !important;
}
