:root {
    --bg-color-main: #f0f4f8;
    --sidebar-bg: #1a202c;
    --sidebar-text: #e2e8f0;
    --sidebar-active: #2d3748;

    --primary-color: #3182ce;
    --primary-hover: #2b6cb0;
    --secondary-color: #4a5568;
    --accent-color: #ed8936;
    --danger-color: #e53e3e;

    --card-bg: rgba(255, 255, 255, 0.75);
    --card-border: rgba(255, 255, 255, 0.5);
    --card-shadow: 0 4px 12px 0 rgba(31, 38, 135, 0.05);
    --glass-blur: blur(8px);

    --text-main: #1a202c;
    --text-muted: #4a5568;

    --font-stack: 'Inter', 'Malgun Gothic', sans-serif;
    --transition: 0.15s ease;
}

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

body {
    font-family: var(--font-stack);
    background: var(--bg-color-main);
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    font-size: 11px;
    /* 극한의 압축을 위한 기본 폰트 더 축소 */
}

/* Typography */
h1 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 2px;
    color: #fff;
}

h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
}

h3 {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-main);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 2px;
    display: inline-block;
}

p {
    line-height: 1.2;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 130px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.sidebar .logo {
    padding: 12px 10px;
    text-align: center;
    background: rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar .logo p {
    color: var(--accent-color);
    font-size: 0.75rem;
    margin-top: 3px;
}

.nav-links {
    list-style: none;
    margin-top: 5px;
}

.nav-links li {
    /* 탭 글자 크기 */
    padding: 11px 10px;
    cursor: pointer;
    font-weight: 200;
    font-size: 1.0rem;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.nav-links li:hover {
    background-color: var(--sidebar-active);
}

.nav-links li.active {
    background-color: var(--sidebar-active);
    border-left-color: var(--primary-color);
    color: #fff;
}

.content {
    flex: 1;
    overflow: hidden;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
}

.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.tab-content.active.grid-layout {
    display: grid;
    grid-template-columns: 50% 50%;
}

.tab-content.active.flex-layout {
    display: flex;
    flex-direction: column;
}

/* Grid Layout */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 525px;
    gap: 10px;
    height: calc(100vh - 45px);
    overflow: hidden;
}

/* ★★★ CSS Multi-Column 레이아웃 적용 ★★★ */
/* 빈틈없이 차례대로 컬럼을 채우는 가장 강력한 속성 */
.left-col {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 5px;
}

.left-col::-webkit-scrollbar {
    width: 5px;
}

.left-col::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.right-col {
    display: grid;
    grid-template-columns: 260px 250px;
    gap: 15px;
    height: 100%;
}

.right-panel-col1 {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.right-panel-col2 {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
}

.right-col::-webkit-scrollbar {
    width: 4px;
}

.right-col::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

/* Glass Cards */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 8px;
    box-shadow: var(--card-shadow);
}

/* Sections for Items */
.item-group-card {
    width: max-content;
    display: flex;
    flex-direction: column;
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.item-row {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.4);
    padding: 1px 4px;
    border-radius: 4px;
    border: 1px solid transparent;
    gap: 6px;
}

.item-row:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-color);
}

.item-row:has(input.chk-order:checked) {
    background: #fef08a !important;
    border-color: #eab308;
}

.item-row label {
    flex: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.item-row label input {
    margin: 0;
    transform: scale(0.85);
    /* 체크박스 크기 축소 */
}

.item-row input[type="text"],
.item-row input[type="number"],
.item-row select {
    width: 32px;
    padding: 1px;
    border: 1px solid #cbd5e0;
    border-radius: 3px;
    text-align: center;
    outline: none;
    font-size: 0.75rem;
}

/* 스피너(증감 화살표) 숨기기 */
.item-row input[type="number"]::-webkit-outer-spin-button,
.item-row input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.item-row input[type="number"] {
    -moz-appearance: textfield;
}

.item-row input[type="text"]:focus,
.item-row input[type="number"]:focus,
.item-row select:focus {
    border-color: var(--primary-color);
}

/* Special Text Colors */
.text-orange {
    color: #dd6b20;
    font-weight: 700;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 5px;
}

.form-group label {
    display: block;
    margin-bottom: 1px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.8);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: #fff;
}

/* Buttons */
.btn {
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--primary-color);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: #fff;
}

.btn-secondary:hover {
    background: #2d3748;
}

.btn-accent {
    background: var(--accent-color);
    color: #fff;
}

.btn-accent:hover {
    background: #dd6b20;
}

.btn-danger {
    background: var(--danger-color);
    color: #fff;
}

.btn-danger:hover {
    background: #c53030;
}

.btn-large {
    padding: 8px 12px;
    font-size: 0.85rem;
}

.block {
    display: block;
    width: 100%;
}

.mt-1 {
    margin-top: 3px;
}

.mt-2 {
    margin-top: 6px;
}

/* Action Buttons Area */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.action-buttons.horizontal {
    display: flex;
}

.action-buttons.horizontal .btn {
    flex: 1;
}

.action-buttons .block {
    grid-column: 1 / -1;
}

/* Radio & Checkbox Groups */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.radio-group label,
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-size: 0.75rem;
}

.radio-group input[type="radio"],
.checkbox-label input {
    transform: scale(0.85);
}

.chk-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
}

/* Previews */
.preview-box {
    flex: 1;
    min-height: 100px;
    display: flex;
    flex-direction: column;
}

.preview-box textarea {
    flex: 1;
    width: 100%;
    background: #fff;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    padding: 6px;
    font-size: 0.8rem;
    resize: none;
    line-height: 1.3;
}

/* History Box */
.history-box {
    display: flex;
    flex-direction: column;
}

.history-box ul {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.history-box ul::-webkit-scrollbar {
    width: 5px;
}

.history-box ul::-webkit-scrollbar-track {
    background: transparent;
}

.history-box ul::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

.history-box li {
    padding: 4px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
}

.history-box li:hover {
    background: rgba(0, 0, 0, 0.05);
}

.action-text {
    float: right;
    font-size: 0.7rem;
    color: var(--danger-color);
    cursor: pointer;
}

.action-text:hover {
    text-decoration: underline;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    padding: 15px;
    width: 90%;
    max-width: 350px;
    border-radius: 8px;
}

.close {
    position: absolute;
    right: 12px;
    top: 8px;
    font-size: 20px;
    cursor: pointer;
}

/* Gift Settings Grid */
.gift-settings-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-content: flex-start;
    height: calc(100vh - 100px);
}

.gift-rule-card {
    padding: 10px;
    width: 410px;
    height: 300px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.rule-inputs {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}

.rule-inputs input {
    width: 85px;
    padding: 3px;
    font-size: 0.75rem;
}

.gift-radio-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.8rem;
}

.bottom-action {
    position: absolute;
    bottom: 15px;
    right: 15px;
}

/* Loading Overlay for Google Sheets */
.sheet-loader-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    z-index: 10;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #e2e8f0;
    border-top: 5px solid #3182ce;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: rgba(49, 130, 206, 0.5);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(49, 130, 206, 0.8);
}

@font-face {
    font-family: 'NanumSquareNeo';
    src: url('../font/NanumSquareNeo-bRg.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Pretendard-Regular';
    src: url('../font/PRETENDARD-REGULAR.TTF') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* ==========================================================================
   Mobile Responsive Adjustments (Max-Width 800px)
   ========================================================================== */
@media (max-width: 800px) {
    /* 1. Body & Container */
    body {
        overflow: auto;
    }
    .app-container {
        flex-direction: column;
        height: auto;
        padding-bottom: 65px; /* space for bottom nav */
    }
    .content {
        overflow: visible;
        padding: 5px;
    }

    /* 2. Sidebar to Bottom Nav */
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }
    .sidebar .logo {
        display: none; /* Hide logo on mobile to save space */
    }
    .nav-links {
        display: flex;
        flex-direction: row;
        width: 100%;
        margin: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        background-color: var(--sidebar-bg); /* ensure background is solid */
    }
    .nav-links li {
        flex: none;
        min-width: 85px;
        text-align: center;
        padding: 15px 5px;
        white-space: nowrap;
        border-left: none;
        border-bottom: 3px solid transparent;
        font-size: 0.9rem;
    }
    .nav-links li.active {
        border-left-color: transparent;
        border-bottom-color: var(--primary-color);
    }

    /* 3. Main Grid & Left Col (Product List) */
    .main-grid {
        display: flex;
        flex-direction: column;
        height: auto;
        gap: 15px;
    }
    .left-col {
        height: 45vh; /* Fixed height with internal scroll */
        flex-direction: column;
        flex-wrap: nowrap;
        overflow-y: auto;
        overflow-x: hidden;
        border: 1px solid rgba(0, 0, 0, 0.1);
        padding: 5px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.5);
    }
    .item-group-card {
        width: 100%;
        margin-bottom: 5px;
    }

    /* 4. Right Col (Forms & SMS Preview) */
    .right-col {
        display: flex;
        flex-direction: column;
        height: auto;
        gap: 15px;
    }
    .right-panel-col1, .right-panel-col2 {
        width: 100%;
        height: auto;
    }

    /* 5. Override Inline Styles via !important */
    .preview-box {
        height: 200px !important;
    }
    .history-box, .manual-history-box {
        height: 300px !important;
    }
    
    .history-box li, .manual-history-box li {
        font-size: 0.65rem;
        padding: 6px 4px;
        white-space: normal; /* 글씨가 짤리지 않고 줄바꿈 되도록 설정 */
        word-break: break-all;
    }
    
    .history-box li .action-text, .manual-history-box li .action-text {
        font-size: 0.6rem;
        margin-left: 5px;
        flex-shrink: 0;
    }

    /* 6. Form Adjustments for Touch */
    .chk-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .chk-grid label {
        padding: 8px 4px; /* Larger touch targets */
        background: rgba(255, 255, 255, 0.5);
        border-radius: 4px;
        border: 1px solid #e2e8f0;
        margin: 0;
    }
    .action-buttons {
        flex-wrap: wrap;
    }
    .btn {
        padding: 12px 10px;
        font-size: 1rem;
    }
    input[type="text"], input[type="number"], select {
        padding: 10px;
        font-size: 1rem; /* Prevent zoom */
    }
    
    /* Settings / Manual Info */
    .gift-settings-container {
        flex-direction: column;
        height: auto;
        flex-wrap: nowrap;
    }
    .gift-rule-card {
        width: 100%;
    }
    
    /* 7. Ver History UI Adjustments */
    #manual-guide-tab .timeline-item h2 {
        font-size: 1.3rem !important;
        margin-bottom: 8px !important;
    }
    #manual-guide-tab .timeline-item h2 span {
        font-size: 0.85rem !important;
    }
    #manual-guide-tab .timeline-item h4 {
        font-size: 1.05rem !important;
        margin-bottom: 6px !important;
    }
    #manual-guide-tab .timeline-item h4 span {
        font-size: 1.1rem !important;
    }
    #manual-guide-tab .timeline-item ul {
        font-size: 0.9rem !important;
        padding-left: 18px !important;
        line-height: 1.5 !important;
    }
    #manual-guide-tab .timeline-item {
        margin-bottom: 25px !important;
    }

    /* Return Tab Mobile Layout (Split top and bottom) */
    .return-split-container {
        flex-direction: column !important;
        height: auto !important;
        gap: 15px !important;
        overflow: visible !important;
    }
    
    .return-split-container > .glass-card {
        height: 45vh !important;
        min-height: 320px !important;
        flex: none !important;
    }

    .return-split-container .glass-card > div {
        overflow: auto !important;
    }

    /* Mobile detail toggle and collapsible form elements */
    .btn-detail-toggle {
        display: inline-block !important;
        height: 20px;
        padding: 2px 6px;
        font-size: 0.7rem;
        background: #718096;
        color: white;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-weight: normal;
        margin-left: 8px;
    }
    
    .mobile-hide {
        display: none !important;
    }
    
    form.show-details .mobile-hide {
        display: flex !important;
    }
    
    form.show-details div.form-group.mobile-hide {
        display: block !important;
    }

    /* Product Settings Tab Mobile Horizontal Scroll */
    #product-groups-container {
        overflow-x: auto !important;
        max-width: 100% !important;
    }

    /* Code Settings Tab Mobile Horizontal Scroll & Side-by-Side Layout */
    .code-split-container {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
    }
    
    .code-split-container > .glass-card:first-child {
        flex: 0 0 560px !important;
        width: 560px !important;
        max-width: 560px !important;
        height: 100% !important;
    }
    
    .code-split-container > .glass-card:last-child {
        flex: 0 0 1000px !important;
        width: 1000px !important;
        max-width: 1000px !important;
        height: 100% !important;
    }

    /* Settings Tab Mobile Style Optimizations */
    #gift-tab h1 {
        color: #2d3748 !important;
    }

    select option {
        color: #2d3748 !important;
        background-color: #ffffff !important;
    }

    #gift-tab .left-settings, 
    #gift-tab .right-settings, 
    #gift-tab .third-settings {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
    }
    
    #gift-tab .glass-card {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
    }

    #app-font-select {
        flex: 1 !important;
        min-width: 0 !important;
        width: 100% !important;
        max-width: calc(100% - 85px) !important;
    }

    .settings-action-container {
        position: static !important;
        margin-top: 15px !important;
        margin-bottom: 80px !important;
        width: 100% !important;
        display: flex !important;
        justify-content: flex-end !important;
    }
}

.btn-detail-toggle {
    display: none;
}

/* ==========================================================================
   Auto Order (스마트스토어 발주 자동화) TAB Styles
   ========================================================================== */

/* File Drop Area */
.file-drop-area {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    padding: 2rem 1rem;
    border: 2px dashed rgb(200, 200, 200);
    border-radius: 8px;
    background-color: #fafbfc;
    margin-bottom: 1rem;
    transition: background-color 0.2s, border-color 0.2s;
    cursor: pointer;
}

.file-drop-area.is-active {
    background-color: #f0fdf4;
    border-color: #03C75A;
}

.file-msg {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-align: center;
}

/* Loading Spinner */
.spinner-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1rem;
}

#downloadSpinner, #uploadSpinner {
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #03C75A;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
    display: inline-block;
}

.hidden {
    display: none !important;
}

/* Result Box */
.result-box {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: #f8f9fa;
}

.result-box.success {
    border-color: #03C75A;
    background-color: #f0fdf4;
}

.result-box.error {
    border-color: #ff4a4a;
    background-color: #fff5f5;
}

.result-box h3 {
    margin-bottom: 0.5rem;
}

/* Toggle Switch CSS */
.toggle-switch {
    position: relative;
    width: 50px;
    height: 24px;
    display: inline-block;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-label {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.switch-label:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.toggle-switch input:checked + .switch-label {
    background-color: #03C75A;
}

.toggle-switch input:focus + .switch-label {
    box-shadow: 0 0 1px #03C75A;
}

.toggle-switch input:checked + .switch-label:before {
    transform: translateX(26px);
}