/* TrackSense 공통 스타일 */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --warning: #f59e0b;
    --success: #10b981;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --sidebar-w: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

img,
video,
canvas {
    max-width: 100%;
    height: auto;
}

/* ── 인증 페이지 (로그인/회원가입) ── */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.auth-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.auth-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.5rem;
    color: var(--gray-900);
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
}

.auth-brand-logo {
    width: 100%;
    max-width: 280px;
    height: auto;
    display: block;
}

.auth-brand-text {
    margin-top: -2px;
    font-size: 0.82rem;
    color: var(--gray-500);
    text-align: center;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 28px;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    text-align: center;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover { background: var(--gray-200); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

/* ── 로그인 옵션 (아이디 저장 / 자동 로그인) ── */
.login-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    margin-top: -4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-700);
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
    margin: 0;
}

.auth-link {
    text-align: center;
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--gray-500);
}

.auth-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.auth-link a:hover { text-decoration: underline; }

/* ── 소셜 로그인 ── */
.social-divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    gap: 12px;
}

.social-divider::before,
.social-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-200);
}

.social-divider span {
    font-size: 0.85rem;
    color: var(--gray-500);
    white-space: nowrap;
}

.social-login-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 8px;
}

.btn-social {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    border: 1px solid var(--gray-300);
}

.btn-google {
    background: #fff;
    color: var(--gray-700);
}

.btn-google:hover {
    background: var(--gray-50);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.btn-kakao {
    background: #FEE500;
    color: #3C1E1E;
    border-color: #FEE500;
}

.btn-kakao:hover {
    background: #FDDC3F;
}

/* ── 사업자번호 입력 + 확인 버튼 ── */
.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-btn input {
    flex: 1;
}

.input-with-btn .btn {
    flex-shrink: 0;
    white-space: nowrap;
    height: 40px;
}

.field-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.hint-success {
    color: var(--success);
}

.hint-error {
    color: var(--danger);
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    display: none;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.alert-warning {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}

/* ── 레이아웃 (대시보드/관리 페이지) ── */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--gray-900);
    color: #fff;
    padding: 12px 0 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow: hidden;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar .logo {
    padding: 0 12px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 8px;
}

.sidebar .logo h2 {
    font-size: 1.1rem;
    color: #fff;
}

.sidebar .logo .brand-logo {
    width: 100%;
    max-width: 172px;
    max-height: 56px;
    object-fit: contain;
    display: block;
    margin-left: -4px;
    margin-bottom: -4px;
}

.sidebar .logo small {
    color: var(--gray-500);
    font-size: 0.72rem;
    display: block;
    margin-top: 0;
    padding-left: 58px;
    line-height: 1.25;
}

.sidebar nav {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--gray-300);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar nav a.active {
    border-left: 3px solid var(--primary);
    padding-left: 17px;
}

.sidebar .sidebar-footer {
    position: static;
    margin-top: auto;
    width: auto;
    padding: 10px 14px 12px;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(17, 24, 39, 0.96);
}

.sidebar .sidebar-footer .user-email {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 24px 32px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.5rem;
    color: var(--gray-900);
}

/* ── 구독 상태 배너 ── */
.subscription-banner {
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: none;
    font-size: 0.9rem;
    align-items: center;
    justify-content: space-between;
}

.banner-trial {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.banner-grace {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #b45309;
}

.banner-expired {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
}

/* ── 카드 ── */
.card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid var(--gray-200);
    padding: 20px;
    margin-bottom: 16px;
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--gray-700);
}

/* ── KPI 카드 ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid var(--gray-200);
    padding: 20px;
    text-align: center;
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.kpi-card .kpi-label {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-top: 4px;
}

.kpi-card.danger .kpi-value { color: var(--danger); }
.kpi-card.warning .kpi-value { color: var(--warning); }
.kpi-card.success .kpi-value { color: var(--success); }

/* ── 테이블 ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.9rem;
}

.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
}

.data-table tr:hover td {
    background: var(--gray-50);
}

/* ── 배지 ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-critical { background: #fef2f2; color: var(--danger); }
.badge-warning { background: #fffbeb; color: #b45309; }
.badge-info { background: #eff6ff; color: #2563eb; }
.badge-success { background: #f0fdf4; color: #15803d; }

/* ── 모달 ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: 1.2rem;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ── 빈 상태 ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}

.empty-state h3 {
    color: var(--gray-700);
    margin-bottom: 8px;
}

/* ── 케이스 상세 ── */
.case-detail-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--gray-100);
}

.detail-label {
    min-width: 120px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-500);
}

/* ── 타임라인 ── */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
}

.timeline-item {
    position: relative;
    padding: 8px 0 16px 0;
}

.timeline-marker {
    position: absolute;
    left: -20px;
    top: 12px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--primary);
}

.timeline-time {
    font-size: 0.78rem;
    color: var(--gray-500);
    margin-bottom: 4px;
}

.timeline-event {
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

/* ── 리뷰 항목 ── */
.review-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.9rem;
}

/* ── 페이지 설명 (page-desc) ── */
.page-desc {
    background: var(--gray-50);
    border-left: 3px solid var(--primary);
    padding: 12px 16px;
    margin-bottom: 18px;
    border-radius: 0 8px 8px 0;
    font-size: 0.85rem;
    color: var(--gray-700);
    line-height: 1.7;
}

.page-desc strong { color: var(--gray-900); }

.page-desc ul {
    margin: 6px 0 0 18px;
    padding: 0;
    list-style: disc;
}

.page-desc ul li { margin-bottom: 2px; }

.help-tip {
    display: inline-block;
    width: 15px;
    height: 15px;
    background: var(--gray-300);
    color: #fff;
    border-radius: 50%;
    text-align: center;
    font-size: 0.65rem;
    line-height: 15px;
    cursor: help;
    margin-left: 4px;
    font-weight: 700;
    position: relative;
    vertical-align: middle;
}

.help-tip:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    white-space: normal;
    z-index: 100;
    min-width: 200px;
    max-width: 420px;
    width: max-content;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    text-align: left;
    word-break: keep-all;
}

/* ── 토글 스위치 ── */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--gray-300);
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── 모바일 햄버거 메뉴 ── */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 300;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: var(--gray-900);
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

.sidebar-overlay.open { display: block; }

/* ── 카톡 상담 플로팅 ── */
.kakao-consult-floating {
    position: fixed;
    right: 20px;
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    z-index: 350;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 999px;
    padding: 10px 14px;
    background: #FEE500;
    color: #3C1E1E;
    font-size: 0.86rem;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.kakao-consult-floating:hover {
    filter: brightness(0.97);
}

.kakao-consult-floating .kakao-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3C1E1E;
    color: #FEE500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
}

/* ── 테이블 스크롤 래퍼 ── */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── 반응형 ── */
@media (max-width: 768px) {
    .mobile-menu-btn { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 60px 14px calc(14px + env(safe-area-inset-bottom, 0px) + 76px);
    }

    .page-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .page-header h1 {
        font-size: 1.2rem;
        width: 100%;
    }

    .kpi-grid { grid-template-columns: 1fr 1fr; }

    .kpi-card .kpi-value { font-size: 1.5rem; }
    .kpi-card { padding: 14px 10px; }

    .card {
        padding: 14px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal {
        max-width: 95vw;
        padding: 20px;
        margin: 8px;
    }

    .btn-sm {
        padding: 8px 14px;
        font-size: 0.85rem;
        min-height: 38px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 8px;
        font-size: 0.8rem;
        white-space: nowrap;
    }
    .data-table { min-width: 620px; }

    .detail-label { min-width: 90px; font-size: 0.8rem; }
    .detail-row { align-items: flex-start; }

    .page-desc {
        font-size: 0.8rem;
        padding: 10px 12px;
    }
    .page-desc ul {
        margin-left: 16px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .card input,
    .card select,
    .card textarea {
        min-height: 40px;
        font-size: 16px; /* iOS 확대 방지 */
    }

    .card [style*="display:grid"][style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    .card [style*="display:flex"] {
        flex-wrap: wrap !important;
    }
    .card [style*="display:flex"] > .btn,
    .card [style*="display:flex"] > button,
    .card [style*="display:flex"] > select,
    .card [style*="display:flex"] > input {
        flex: 1 1 auto;
    }
    .page-header > div[style*="display:flex"] {
        width: 100%;
    }

    .help-tip:hover::after {
        left: 0;
        transform: none;
        max-width: 280px;
    }

    .kakao-consult-floating {
        right: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px) + 48px);
        padding: 9px 12px;
        font-size: 0.82rem;
    }

    .auth-card { padding: 24px 20px; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }

    .page-header h1 { font-size: 1.1rem; }
    .card { padding: 12px; }

    .modal-actions {
        flex-direction: column;
    }
    .modal-actions .btn { width: 100%; }

    .btn,
    .btn-sm {
        width: 100%;
    }

    .login-options {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}
