* { margin: 0; padding: 0; box-sizing: border-box; }
:root { --primary: #6366f1; --danger: #dc2626; --border: #e2e8f0; --light-orange: #FFF3E0; --light-orange-text: #E67E22; --detail-green: #d1fae5; --detail-green-text: #047857; }
body { font-family: system-ui, -apple-system, sans-serif; background: #f1f5f9; overflow-x: hidden; font-size: 16px; }
body.modal-open { position: fixed; overflow: hidden; width: 100%; height: 100%; }

.app-container {
    max-width: 100%;
    margin: 0 auto;
    background: #f1f5f9;
    min-height: 100vh;
    padding-top: 12px;
    overflow-x: hidden;
}

.navbar {
    background: var(--primary);
    padding: 12px 16px;
    display: grid;
    grid-template-columns: 4fr 4fr 2fr 2fr;
    gap: 12px;
    align-items: stretch;
    border-radius: 30px;
    margin: 0 16px;
}
.nav-col {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}
.nav-top, .nav-bottom {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}
.nav-col .info-box, .nav-col button, .nav-col .lang-group {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    border-radius: 40px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 10px;
    height: 44px;
    font-size: 0.8rem;
    line-height: normal;
}
.nav-col:first-child .info-box {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: bold;
}
.nav-col .info-box {
    background: #FEF3C7;
    color: #C2410C;
    gap: 6px;
}
.nav-col button:hover { background: rgba(255,255,255,0.35); }
.lang-group {
    background: transparent;
    padding: 0;
}
.lang-group button {
    background: white;
    color: var(--primary);
    flex: 1;
}
.lang-group button.active {
    background: #3B82F6;
    color: white;
}
.save-btn button {
    background: #4a5568;
    color: white;
    white-space: nowrap;
    font-size: 0.8rem;
}

.main-card {
    background: white;
    border-radius: 24px;
    margin: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    overflow: hidden;
}
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 0 16px;
}
.title-area {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.title-area h2 { font-size: 1.2rem; display: inline-flex; align-items: center; gap: 6px; }
.btn-add-transaction {
    background: #10B981; color: white; border: none; height: 44px; padding: 0 16px;
    border-radius: 40px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.8rem;
}
.search-area {
    display: flex;
    gap: 12px;
    align-items: center;
}
.search-box { position: relative; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 0.8rem; }
.search-box input {
    height: 44px; padding: 0 12px 0 36px; border: 1px solid var(--primary); border-radius: 40px;
    width: 160px; font-size: 0.8rem; outline: none;
}
.search-area button {
    height: 44px; padding: 0 16px; background: var(--primary); color: white; border: none;
    border-radius: 40px; font-weight: 500; cursor: pointer; font-size: 0.8rem;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 60vh;
    margin-top: 16px;
    -webkit-overflow-scrolling: touch;
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}
th, td {
    padding: 14px 10px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}
th {
    background: #FEF3C7;
    position: sticky;
    top: 0;
}
.customer-table th:nth-child(1), .customer-table td:nth-child(1) { width: 30%; }
.customer-table th:nth-child(2), .customer-table td:nth-child(2) { width: 20%; }
.customer-table th:nth-child(3), .customer-table td:nth-child(3) { width: 30%; }
.customer-table th:nth-child(4), .customer-table td:nth-child(4),
.customer-table th:nth-child(5), .customer-table td:nth-child(5) {
    display: none;
}
.total-footer {
    padding: 16px;
    text-align: right;
    font-weight: bold;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}
.action-group {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}
.action-btn {
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: 0.2s;
    border: 1px solid var(--border);
    background: white;
    padding: 0 12px;
}
.action-btn.detail-btn {
    flex: 2;
    background: #d1fae5;
    color: #047857;
    border-color: #10b981;
    font-weight: bold;
}
.action-btn.edit-btn {
    flex: 1;
}
.action-btn.delete-btn {
    flex: 1;
    color: var(--danger);
}
.deposit-action-group {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}
.deposit-action-btn {
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: 0.2s;
    border: 1px solid var(--border);
    background: white;
    padding: 0 12px;
}
.deposit-action-btn.convert-btn {
    background: #3B82F6;
    color: white;
    border-color: #3B82F6;
    min-width: 100px;
}
.deposit-action-btn.edit-btn {
    background: white;
    color: #333;
}
.deposit-action-btn.delete-btn {
    background: white;
    color: var(--danger);
}
@media (min-width: 481px) {
    .action-btn { white-space: nowrap; }
}

/* ===== 공통 입력 필드 스타일 ===== */
input, select, textarea {
    text-align: center;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--primary);
    border-radius: 24px;
    font-size: 16px;   /* iOS 확대 방지 */
    height: 44px;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}
input::placeholder, textarea::placeholder {
    text-align: center;
}
textarea {
    text-align: center;
    height: 80px;
    resize: vertical;
}
.form-group {
    margin-bottom: 20px;
}
/* 그리드 레이아웃 - 기본 (데스크톱/아이패드) */
.form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
/* 2열 전용 */
.form-row.two-cols {
    grid-template-columns: repeat(2, 1fr);
}
/* 1열 전용 */
.form-row.one-col {
    grid-template-columns: 1fr;
}
label, .form-group label {
    display: inline-block;
    background: #FEF3C7;
    border: 1px solid var(--primary);
    border-radius: 20px;
    padding: 4px 12px;
    margin-bottom: 10px;
    margin-left: 8px;
    font-weight: 600;
    font-size: 0.7rem;
}
select {
    text-align: center;
    text-align-last: center;
}
input[type="date"] {
    text-align: center;
}
input[type="date"]::-webkit-calendar-picker-indicator {
    display: none;
    -webkit-appearance: none;
}
.input-with-button {
    display: flex;
    gap: 8px;
    align-items: center;
}
.input-with-button input, .input-with-button select {
    flex: 1;
    text-align: center;
}
.date-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}
.date-input-wrapper input {
    flex: 1;
    text-align: center;
}
.date-calendar-btn {
    background: #FEF3C7;
    border: 1px solid var(--primary);
    border-radius: 40px;
    padding: 0 12px;
    height: 44px;
    font-size: 0.8rem;
    font-weight: 500;
    color: #C2410C;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.modal-footer {
    flex-shrink: 0;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
/* 아이패드 가로, 작은 화면 */
@media (max-width: 480px) {
    .form-row, .form-row.two-cols, .form-row.one-col {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    .date-input-wrapper {
        flex-wrap: wrap;
    }
}

/* 모달 스타일 - 스크롤 개선 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
#customerModal, #brandFormModal, #depositFormModal, #manualModal {
    z-index: 3200;
}
.modal-content {
    background: white;
    border-radius: 28px;
    width: 90%;
    max-width: 800px;
    min-width: 300px;
    max-height: 90vh;
    overflow: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    background: white;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    z-index: 10;
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}
.close-modal {
    background: var(--light-orange);
    color: var(--light-orange-text);
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 1.4rem;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: auto;
}
.form-scroll {
    overflow-y: auto;
    flex: 1;
    margin-top: 10px;
    padding-right: 5px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}
.btn-cancel {
    background: var(--light-orange);
    color: var(--light-orange-text);
    border: 1px solid var(--primary);
    padding: 8px 20px;
    border-radius: 40px;
    cursor: pointer;
}
.btn-prominent {
    background: var(--primary);
    color: white;
    padding: 10px 24px;
    border-radius: 40px;
    border: none;
    font-weight: bold;
    cursor: pointer;
}

.option-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.option-buttons button {
    padding: 12px;
    font-size: 1rem;
    background: var(--light-orange);
    color: var(--light-orange-text);
    border: 1px solid var(--primary);
    border-radius: 40px;
    cursor: pointer;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: nowrap;
    gap: 12px;
    flex-shrink: 0;
}
.detail-buttons-bar {
    display: flex;
    gap: 12px;
    align-items: center;
}
.detail-total {
    background: #FEF3C7;
    padding: 8px 18px;
    border-radius: 40px;
    font-size: 0.9rem;
    font-weight: bold;
    color: #C2410C;
    white-space: nowrap;
}
#detailGroupsContainer {
    overflow-y: auto;
    flex: 1;
}
.season-group {
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}
.group-header {
    background: #f8fafc;
    padding: 12px 20px;
    font-weight: bold;
    color: var(--primary);
    font-size: 0.95rem;
}
.subtotal-row {
    background: #fffbeb;
}

.deposit-header-right {
    display: flex;
    gap: 20px;
    align-items: center;
}

.deleted-table td, .deleted-table th {
    font-size: 0.7rem;
    padding: 6px 3px;
}
.deleted-table .action-btn {
    font-size: 0.6rem;
    padding: 3px 6px;
}
#transactionModal {
    z-index: 2100;
}
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 40px;
    font-size: 0.9rem;
    z-index: 3000;
    opacity: 0.9;
    transition: opacity 0.3s;
}

.modal .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.modal table {
    min-width: 500px;
}

.manual-content {
    max-height: 55vh;
    overflow-y: auto;
    padding: 16px 20px 24px 20px;
    background: linear-gradient(145deg, #ffffff 0%, #f9fafb 100%);
    border-radius: 20px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.03), 0 4px 12px rgba(0,0,0,0.05);
    font-size: 0.95rem;
    line-height: 1.55;
    color: #1e293b;
}
.manual-content h4 {
    color: var(--primary);
    margin: 24px 0 12px 0;
    font-size: 1.2rem;
    font-weight: 600;
    border-left: 5px solid var(--primary);
    padding-left: 14px;
    background: rgba(99,102,241,0.08);
    border-radius: 0 12px 12px 0;
}
.manual-content h4:first-of-type {
    margin-top: 0;
}
.manual-content p {
    margin: 14px 0;
    background: white;
    padding: 12px 16px;
    border-radius: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.manual-content ul {
    margin: 12px 0 16px 24px;
    background: white;
    padding: 12px 16px 12px 32px;
    border-radius: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.manual-content li {
    margin: 10px 0;
}
.btn-sample {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 30px;
    font-size: 0.75rem;
    font-weight: 500;
    margin: 0 4px;
    white-space: nowrap;
}
.btn-sample.green { background: #d1fae5; color: #047857; border: 1px solid #10b981; }
.btn-sample.blue { background: #dbeafe; color: #1e40af; border: 1px solid #3b82f6; }
.btn-sample.orange { background: #fed7aa; color: #9a3412; border: 1px solid #f97316; }
.btn-sample.red { background: #fee2e2; color: #b91c1c; border: 1px solid #ef4444; }
.btn-sample.purple { background: #e9d5ff; color: #6b21a5; border: 1px solid #a855f7; }

/* ===== 아이패드 최적화 (768px 이상) ===== */
@media (min-width: 768px) {
    .app-container {
        padding: 20px 40px;
    }
    .navbar {
        margin: 0 0 16px 0;
        border-radius: 40px;
        padding: 16px 24px;
    }
    .main-card {
        margin: 16px 0;
    }
    th, td {
        font-size: 0.9rem;
    }
    .modal-content {
        padding: 32px;
    }
}

@media (max-width: 480px) {
    .navbar {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .nav-col button {
        font-size: 0.7rem;
        padding: 0 6px;
        height: 40px;
        line-height: normal;
    }
    .nav-col .info-box {
        font-size: 0.7rem;
    }
    .modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        padding: 16px;
    }
    .close-modal {
        right: 8px;
        top: 8px;
    }
    .action-btn {
        font-size: 0.65rem;
        padding: 0 8px;
    }
    .deposit-action-btn {
        font-size: 0.65rem;
        padding: 0 8px;
    }
    .deposit-action-btn.convert-btn {
        min-width: 80px;
    }
    .deposit-header-right {
        gap: 12px;
    }
    #depositTotalAmount {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
    input, select, input[type="date"] {
        height: 40px;
        font-size: 14px;
    }
    .date-calendar-btn {
        height: 40px;
        font-size: 0.7rem;
        padding: 0 8px;
    }
    .modal .table-scroll {
        overflow-x: auto;
    }
    .modal table {
        min-width: 450px;
    }
    .manual-content {
        padding: 12px 12px 20px 12px;
        font-size: 0.85rem;
    }
    .manual-content h4 {
        font-size: 1rem;
    }
}

.season-header {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f1f5f9;
    padding: 4px 12px;
    border-radius: 40px;
}
.season-header span {
    font-size: 0.8rem;
    white-space: nowrap;
}
.season-header select {
    border: 1px solid var(--primary);
    border-radius: 40px;
    padding: 4px 8px;
    font-size: 0.8rem;
    background: white;
    min-width: 80px;
    text-align: center;
    text-align-last: center;
    height: 36px;
}
@media (max-width: 480px) {
    .season-header {
        padding: 2px 8px;
    }
    .season-header select {
        min-width: 60px;
        font-size: 0.7rem;
        padding: 2px 6px;
    }
}

@media print {
    body * { visibility: hidden; }
    .print-area, .print-area * { visibility: visible; }
    .print-area { position: absolute; top: 0; left: 0; width: 100%; }
    table { width: 100%; border-collapse: collapse; }
    th, td { border: 1px solid #000; padding: 8px; text-align: center; }
    th { background: #f2f2f2; }
}