/**
 * Case Master Dashboard - 기존 로컬호스트 디자인과 동일
 */

/* =====================================================
   Design Tokens (기존과 동일)
   ===================================================== */
:root {
    --background: #ffffff;
    --foreground: #171717;
    
    --space-4: 4px;
    --space-8: 8px;
    --space-12: 12px;
    --space-16: 16px;
    --space-24: 24px;
    --space-32: 32px;

    --radius-8: 8px;
    --radius-12: 12px;

    --color-primary: #0B6DFF;
    --color-error: #D14343;
    --color-muted: #6B7280;
    --color-border: #E5E7EB;
    --color-bg-soft: #F8FAFC;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 6px 16px rgba(0,0,0,.08);
}

/* =====================================================
   Reset & Base
   ===================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
}

html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    color: var(--foreground);
    background: var(--background);
    font-family: Arial, Helvetica, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

/* =====================================================
   Layout
   ===================================================== */
.container {
    max-width: 1160px;
    margin: 0 auto;
    padding: var(--space-16);
}

.header {
    border-bottom: 1px solid var(--color-border);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav {
    display: flex;
    align-items: center;
    gap: var(--space-16);
    padding: var(--space-12) var(--space-16);
}

.nav a.brand {
    font-weight: 700;
    color: #111;
}

.nav a {
    color: var(--color-muted);
    transition: color 0.15s;
}

.nav a:hover,
.nav a.active {
    color: #111;
}

/* =====================================================
   Grid System (기존과 동일)
   ===================================================== */
.grid-12 {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--space-24);
}

.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; }

@media (max-width: 1199px) {
    .col-8 { grid-column: span 7; }
    .col-6 { grid-column: span 6; }
    .col-4 { grid-column: span 5; }
}

@media (max-width: 767px) {
    .grid-12 { grid-template-columns: 1fr; }
    .col-8, .col-4, .col-6 { grid-column: auto; }
}

/* =====================================================
   Card (기존과 동일)
   ===================================================== */
.card {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-12);
    box-shadow: var(--shadow-sm);
    padding: var(--space-12);
}

.sticky {
    position: sticky;
    top: var(--space-16);
}

/* =====================================================
   Form Elements (기존과 동일)
   ===================================================== */
.label {
    font-size: 12px;
    font-weight: 600;
    color: #111827;
    margin-bottom: var(--space-8);
    display: inline-block;
}

.helper {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: var(--space-4);
}

.field {
    display: grid;
    gap: var(--space-8);
    margin-bottom: var(--space-16);
}

.input,
.select,
.textarea {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-8);
    padding: 10px 12px;
    background: #fff;
    color: #111827;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(11, 109, 255, 0.1);
}

.textarea {
    min-height: 96px;
    resize: vertical;
}

.error {
    color: var(--color-error);
    font-size: 12px;
}

/* =====================================================
   Buttons (기존과 동일)
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--color-border);
    padding: 8px 12px;
    border-radius: var(--radius-8);
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.15s;
}

.btn:hover {
    background: var(--color-bg-soft);
}

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

.btn-primary:hover {
    background: #0059D6;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--color-bg-soft);
}

.btn-dark {
    background: #1f2937;
    color: #fff;
    border-color: #1f2937;
}

.chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.badge {
    font-size: 12px;
    color: var(--color-muted);
}

/* =====================================================
   Case Grid (기존과 동일)
   ===================================================== */
.case-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.case-card {
    display: block;
}

.case-card article {
    border: 1px solid #eee;
    border-radius: var(--radius-8);
    padding: var(--space-12);
    transition: box-shadow 0.15s, transform 0.15s;
}

.case-card:hover article {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* =====================================================
   Photo Upload (기존과 동일)
   ===================================================== */
.dropzone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-8);
    padding: var(--space-24);
    text-align: center;
    color: var(--color-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--color-primary);
    background: rgba(11, 109, 255, 0.03);
}

.dropzone.loading {
    opacity: 0.6;
    pointer-events: none;
}

.photo-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.photo-item {
    position: relative;
    width: 100px;
    height: 100px;
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-8);
    cursor: pointer;
}

.photo-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-error);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}

.photo-item:hover .photo-remove {
    opacity: 1;
}

.photo-item img:hover {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(11, 109, 255, 0.1);
}

/* =====================================================
   Lightbox (이미지 확대 보기)
   ===================================================== */
#lightbox {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    cursor: pointer;
    animation: fadeIn 0.3s;
}

#lightbox.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

#lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    animation: zoomIn 0.3s;
    border-radius: var(--radius-12);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes zoomIn {
    from { 
        opacity: 0;
        transform: scale(0.9); 
    }
    to { 
        opacity: 1;
        transform: scale(1); 
    }
}

/* =====================================================
   Floating Action Button (기존과 동일)
   ===================================================== */
.fab {
    position: fixed;
    right: 24px;
    bottom: 124px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    border: 2px solid #111;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0,0,0,.12);
    font-size: 28px;
    line-height: 50px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

/* =====================================================
   Dropzone
   ===================================================== */
.dropzone {
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s;
}

.dropzone:hover {
    border-color: #94a3b8;
    background: #f1f5f9;
}

.dropzone.dragover {
    border-color: var(--color-primary);
    background: #eff6ff;
}

.photo-item {
    position: relative;
    display: inline-block;
}

.photo-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #DC2626;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-remove:hover {
    background: #991b1b;
}

/* =====================================================
   Modal (기존과 동일)
   ===================================================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
}

.modal-content {
    position: relative;
    width: 980px;
    max-width: 95vw;
    max-height: 85vh;
    overflow: auto;
    background: #fff;
    border-radius: var(--radius-12);
    padding: var(--space-16);
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
}

/* =====================================================
   Lightbox
   ===================================================== */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    color: #fff;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

/* =====================================================
   Toast
   ===================================================== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 16px;
    background: #1f2937;
    color: #fff;
    border-radius: var(--radius-8);
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
    font-size: 14px;
}

.toast.success { background: #10B981; }
.toast.error { background: var(--color-error); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* =====================================================
   Summary Card (기존 StickySummary와 동일)
   ===================================================== */
.summary-card h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.summary-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    font-size: 12px;
}

.summary-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-muted);
}

.summary-status.saved .dot { background: #10B981; }
.summary-status.saving .dot { background: #F59E0B; animation: pulse 1s infinite; }
.summary-status.unsaved .dot { background: var(--color-error); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.summary-info {
    font-size: 13px;
    color: var(--color-muted);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

.summary-info > div {
    padding: 4px 0;
}

/* =====================================================
   Login Page
   ===================================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-soft);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-12);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-subtitle {
    color: var(--color-muted);
    text-align: center;
    margin-bottom: 24px;
    font-size: 14px;
}

.error-msg {
    background: #FEF2F2;
    border: 1px solid #FEE2E2;
    color: var(--color-error);
    padding: 10px 14px;
    border-radius: var(--radius-8);
    margin-bottom: 16px;
    font-size: 13px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 13px;
    color: var(--color-muted);
}

.login-footer a {
    color: var(--color-primary);
}

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.remember-row input {
    width: 16px;
    height: 16px;
}

.remember-row label {
    font-size: 13px;
    color: var(--color-muted);
}

/* =====================================================
   Empty State
   ===================================================== */
.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--color-muted);
}

/* =====================================================
   Loading Overlay (로딩 오버레이)
   ===================================================== */
.cm-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.cm-loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.cm-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cm-spin 0.8s linear infinite;
}

.cm-loading-text {
    color: #fff;
    font-size: 14px;
    margin-top: 16px;
    font-weight: 500;
}

@keyframes cm-spin {
    to {
        transform: rotate(360deg);
    }
}

/* =====================================================
   Custom Alert Modal (커스텀 알림 모달)
   ===================================================== */
.cm-alert-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.cm-alert-overlay.active {
    opacity: 1;
    visibility: visible;
}

.cm-alert-box {
    background: #fff;
    border-radius: 16px;
    padding: 32px 40px;
    max-width: 360px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.2s ease;
}

.cm-alert-overlay.active .cm-alert-box {
    transform: scale(1) translateY(0);
}

.cm-alert-icon {
    margin-bottom: 16px;
}

.cm-alert-icon svg {
    display: inline-block;
}

.cm-alert-message {
    font-size: 15px;
    color: #1F2937;
    line-height: 1.6;
    margin-bottom: 24px;
    word-break: keep-all;
}

.cm-alert-btn {
    background: #0B6DFF;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 32px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.cm-alert-btn:hover {
    background: #0956D0;
}

.cm-alert-btn:active {
    transform: scale(0.98);
}

/* =====================================================
   AI Generate Button (AI 생성 버튼)
   ===================================================== */
.ai-gen-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ai-gen-btn:hover {
    background: linear-gradient(135deg, #FDE68A 0%, #FCD34D 100%);
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(251, 191, 36, 0.4);
}

.ai-gen-btn:active {
    transform: scale(0.95);
}

.ai-gen-btn:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
}

/* 라벨 내 버튼 정렬 */
.field label {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* =====================================================
   완성된 이미지 드래그 정렬
   ===================================================== */
.drag-handle {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    z-index: 15;
    opacity: 0.7;
    transition: all 0.2s;
    user-select: none;
    letter-spacing: -2px;
}

.final-image-sortable-item:hover .drag-handle {
    opacity: 1;
    background: rgba(11, 109, 255, 0.9);
}

.drag-handle:active {
    cursor: grabbing;
    transform: scale(1.1);
}

/* Sortable 드래그 중 스타일 */
.sortable-ghost {
    opacity: 0.4;
    background: #e0f2fe !important;
    border: 2px dashed #0B6DFF !important;
}

.sortable-chosen {
    box-shadow: 0 8px 20px rgba(11, 109, 255, 0.3) !important;
    border-color: #0B6DFF !important;
}

.sortable-drag {
    opacity: 1;
    transform: rotate(2deg);
}
