@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css');

:root {
    --primary: #1B4332;
    --primary-light: #2D6A4F;
    --secondary: #40916C;
    --accent: #74C69D;
    --accent-light: #B7E4C7;
    --bg: #F0FDF4;
    --bg-card: rgba(255,255,255,0.75);
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #d1d5db;
    --danger: #ef4444;
    --danger-light: #fecaca;
    --warning: #f59e0b;
    --sidebar-width: 200px;
}

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

body {
    font-family: 'Pretendard Variable', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Auth Pages (Login/Register) ── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 50%, var(--accent) 100%);
    padding: 20px;
}

.auth-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 1.25rem;
    padding: 3rem;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.15);
}

.auth-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 0.25rem;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-light) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.3s, transform 0.3s;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 64px;
}

/* Collapsed state */
.sidebar.collapsed .sidebar-logo > span { display: none; }
.sidebar.collapsed .sidebar-nav a span { display: none; }
.sidebar.collapsed .sidebar-user-info { display: none; }
.sidebar.collapsed .sidebar-logout span { display: none; }

.sidebar.collapsed .sidebar-logo { justify-content: center; padding: 1.5rem 0.5rem; }
.sidebar.collapsed .sidebar-nav a { justify-content: center; padding: 0.85rem 0; border-left: none; gap: 0; }
.sidebar.collapsed .sidebar-nav a svg { width: 22px; height: 22px; }

.sidebar.collapsed .sidebar-user { flex-direction: column; gap: 0.5rem; align-items: center; }
.sidebar.collapsed .sidebar-user-actions { width: 100%; justify-content: center; gap: 0.5rem; }
.sidebar.collapsed .sidebar-logout { padding: 0.4rem; }
.sidebar.collapsed .sidebar-toggle-btn { padding: 0.4rem; }
.sidebar.collapsed #toggleIcon { transform: rotate(180deg); }

.sidebar.collapsed + .main-content,
body.sidebar-collapsed .main-content { margin-left: 64px; }

.sidebar-logo {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-logo span { color: var(--accent-light); }

.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.5rem;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.925rem;
    font-weight: 500;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: #fff;
    background: rgba(255,255,255,0.08);
    border-left-color: var(--accent);
}

.sidebar-nav a svg {
    width: 20px; height: 20px;
    flex-shrink: 0;
}

.sidebar-user {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-user-info strong { color: #fff; display: block; margin-bottom: 0.1rem; }
.sidebar-user-company { font-size: 0.8rem; }

.sidebar-user-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar-logout {
    display: flex; align-items: center; gap: 0.4rem;
    color: rgba(255,255,255,0.5);
    font-size: 0.8rem;
    text-decoration: none;
    padding: 0.35rem 0.5rem;
    border-radius: 0.375rem;
    transition: all 0.2s;
}
.sidebar-logout:hover { color: #fff; background: rgba(255,255,255,0.1); }

.sidebar-toggle-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.5);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.sidebar-toggle-btn svg { transition: transform 0.3s; }

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 2rem;
    min-height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* ── Mobile Toggle ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem; left: 1rem;
    z-index: 200;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    width: 40px; height: 40px;
    cursor: pointer;
    font-size: 1.25rem;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.04);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(0,0,0,0.08); }

.stat-card {
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.stat-card .stat-icon {
    width: 48px; height: 48px;
    border-radius: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 0.75rem;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    color: var(--primary);
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

/* ── Forms ── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.375rem;
}

.form-control {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    font-size: 0.925rem;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(116, 198, 157, 0.25);
}

.input-group {
    display: flex;
    gap: 0.5rem;
}

.input-group .form-control { flex: 1; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 9999px;
    font-size: 0.925rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
}

.btn-secondary {
    background: #fff;
    color: var(--primary);
    border: 1px solid var(--border);
}

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

.btn-sm { padding: 0.45rem 1rem; font-size: 0.825rem; }
.btn-lg { padding: 0.9rem 2.25rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ── Table ── */
.table-wrap {
    overflow-x: auto;
    border-radius: 1rem;
    border: 1px solid var(--border);
    background: #fff;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table-wrap th {
    background: var(--bg);
    font-weight: 600;
    text-align: left;
    padding: 0.85rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table-wrap td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.table-wrap tr:last-child td { border-bottom: none; }
.table-wrap tr:hover td { background: #f9fafb; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fecaca; color: #991b1b; }
.badge-gray { background: #e5e7eb; color: #4b5563; }

/* ── DAS Grid ── */
.das-grid {
    display: grid;
    gap: 4px;
    margin-top: 0.5rem;
}

.das-box {
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.35rem 0.4rem;
    background: #fff;
    transition: all 0.3s;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.das-box .box-number {
    position: absolute;
    top: 2px; left: 2px;
    background: var(--primary);
    color: #fff;
    width: 20px; height: 20px;
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    z-index: 1;
}

.das-box .box-number:hover {
    background: var(--accent);
    transform: scale(1.2);
}

.das-box.completed .box-number { cursor: default; }
.das-box.completed .box-number:hover { transform: none; background: var(--primary); }

.das-box .box-info {
    margin-top: 1.25rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.das-box .box-receiver {
    font-weight: 700;
    font-size: 0.75rem;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.das-box .box-product {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.das-box .box-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.6rem;
    color: var(--text);
    line-height: 1.2;
    padding: 2px 3px;
    margin: 1px 0;
    border-radius: 3px;
    cursor: pointer;
    background: rgba(116, 198, 157, 0.1);
    border: 1px solid rgba(116, 198, 157, 0.2);
    transition: all 0.15s;
    gap: 2px;
}

.das-box .box-item .item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.das-box .box-item .item-qty {
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
    font-size: 0.6rem;
}

.das-box .box-item:hover {
    background: rgba(116, 198, 157, 0.35);
    border-color: var(--accent);
}

.das-box .box-item.done {
    background: #e5e7eb;
    color: #9ca3af;
    border-color: transparent;
    cursor: default;
}

.das-box .box-item.done .item-name { text-decoration: line-through; }
.das-box .box-item.done .item-qty { color: #9ca3af; }

.box-progress-badge {
    position: absolute;
    top: 2px; right: 2px;
    color: #fff;
    font-size: 0.5rem;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 9999px;
    line-height: 1.3;
}

.box-progress-bar {
    height: 3px;
    background: #e5e7eb;
    border-radius: 2px;
    margin-top: auto;
    overflow: hidden;
}

.box-progress-bar > div {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--accent));
    border-radius: 2px;
    transition: width 0.3s;
}

/* ── Simple Mode ── */
.das-box.simple-active {
    border-color: #f59e0b !important;
    border-width: 3px !important;
    background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.5), inset 0 0 10px rgba(245, 158, 11, 0.1) !important;
    z-index: 1;
    opacity: 1 !important;
    transform: scale(1.02);
}

.das-box .box-qty {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary);
    text-align: right;
    line-height: 1;
    margin-top: auto;
    padding-top: 2px;
}

.das-box.empty {
    background: #f9fafb;
    border-style: dashed;
    border-width: 1px;
}

.das-box.empty .box-info { display: none; }
.das-box.empty .box-qty { display: none; }

.das-box.completed {
    background: #e5e7eb;
    border-color: #9ca3af;
    opacity: 0.5;
}

.das-box.locate {
    border-color: #3b82f6;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
    animation: dasLocate 0.6s ease;
    transform: scale(1.04);
    opacity: 1 !important;
    z-index: 2;
}

@keyframes dasLocate {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1.04); }
}

.das-box.highlight {
    border-color: var(--accent);
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    box-shadow: 0 0 20px rgba(116, 198, 157, 0.5);
    animation: dasHighlight 0.4s ease;
    transform: scale(1.04);
    opacity: 1 !important;
    z-index: 2;
}

@keyframes dasHighlight {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1.04); }
}

.das-box.error {
    border-color: var(--danger);
    background: var(--danger-light);
    animation: dasError 0.3s ease;
}

@keyframes dasError {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* ── Barcode Input ── */
.barcode-input-wrap {
    position: relative;
    margin-bottom: 1rem;
}

.barcode-input {
    width: 100%;
    padding: 0.6rem 1rem;
    font-size: 1.2rem;
    font-weight: 700;
    border: 3px solid var(--accent);
    border-radius: 0.75rem;
    text-align: center;
    letter-spacing: 0.1em;
    outline: none;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.barcode-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(27, 67, 50, 0.15);
}

/* ── Progress Bar ── */
.progress-bar {
    width: 100%;
    height: 12px;
    background: #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--accent));
    border-radius: 6px;
    transition: width 0.5s ease;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.85rem 1.25rem;
    border-radius: 0.75rem;
    color: #fff;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    animation: toastIn 0.3s ease;
    min-width: 280px;
}

.toast-success { background: var(--secondary); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-overlay.active { display: flex; }

.modal {
    background: #fff;
    border-radius: 1.25rem;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    box-shadow: 0 25px 60px rgba(0,0,0,0.2);
}

.modal h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1.25rem;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.pagination a:hover { background: var(--bg); color: var(--primary); }
.pagination .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ── Upload Area ── */
.upload-area {
    border: 2px dashed var(--accent);
    border-radius: 1rem;
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(116, 198, 157, 0.05);
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(116, 198, 157, 0.1);
}

.upload-area .upload-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

/* ── Mapping Table ── */
.mapping-table td {
    padding: 0.5rem;
}

.mapping-table select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.875rem;
    width: 100%;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
    .main-content { margin-left: 0; padding: 1rem; padding-top: 4rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .auth-card { padding: 2rem 1.5rem; }
}
