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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ===== Auth Pages ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow-lg);
}

.auth-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    color: var(--gray-900);
}

.auth-subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 28px;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.auth-footer {
    text-align: center;
    margin-top: 20px;
}

/* Service Code Inputs */
.service-code-inputs {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.code-input {
    width: 72px;
    height: 48px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
    letter-spacing: 2px;
}

.code-input:focus { border-color: var(--primary); }

.code-sep {
    font-size: 1.2rem;
    color: var(--gray-400);
    font-weight: 600;
}

/* ===== Forms ===== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-input {
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    background: white;
}

.form-input:focus { border-color: var(--primary); }

.form-hint {
    font-size: 0.8rem;
    color: var(--gray-400);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

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

.btn-success {
    background: #059669;
    color: white;
}
.btn-success:hover { background: #047857; }

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-outline {
    background: transparent;
    color: var(--gray-600);
    border: 1.5px solid var(--gray-200);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

/* ===== Messages ===== */
.error-msg {
    color: var(--danger);
    font-size: 0.9rem;
    padding: 10px 14px;
    background: #fef2f2;
    border-radius: 8px;
    border: 1px solid #fecaca;
}

.result-msg {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
}
.result-msg.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.result-msg.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ===== Code Display ===== */
.code-display {
    text-align: center;
    padding: 20px;
    background: var(--primary-light);
    border-radius: 10px;
    border: 1px solid #c7d2fe;
}
.code-value {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--primary);
    margin: 8px 0 12px;
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
}

.sidebar-admin { background: var(--gray-900); }
.sidebar-admin .sidebar-header h2 { color: white; }
.sidebar-admin .sidebar-menu a { color: var(--gray-300); }
.sidebar-admin .sidebar-menu a:hover { background: var(--gray-800); color: white; }
.sidebar-admin .sidebar-menu .active a { background: var(--primary); color: white; }
.sidebar-admin .sidebar-footer { border-top-color: var(--gray-700); }

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
}
.sidebar-admin .sidebar-header { border-bottom-color: var(--gray-700); }

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-900);
}

.sidebar-menu {
    list-style: none;
    padding: 8px;
    flex: 1;
}

.sidebar-menu a {
    display: block;
    padding: 10px 14px;
    color: var(--gray-600);
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.15s;
}
.sidebar-menu a:hover { background: var(--gray-50); color: var(--gray-900); text-decoration: none; }
.sidebar-menu .active a { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
}

.user-info {
    margin-bottom: 8px;
    color: var(--gray-500);
    font-size: 0.85rem;
    word-break: break-all;
}

.main-content {
    flex: 1;
    padding: 24px 32px;
    margin-left: 240px;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ===== Cards ===== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
    border: 1px solid var(--gray-100);
}

.card-link {
    display: block;
    transition: box-shadow 0.2s;
    cursor: pointer;
    color: inherit;
}
.card-link:hover { box-shadow: var(--shadow-md); text-decoration: none; }

.card-header {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--gray-100);
    background: var(--gray-50);
}

.card-id { font-weight: 600; color: var(--gray-700); }
.card-body { padding: 16px 20px; }
.card-body p { margin-bottom: 6px; }
.card-title { font-weight: 600; color: var(--gray-800); font-size: 1.05rem; }
.card-time { color: var(--gray-400); font-size: 0.85rem; }

.card-list { display: flex; flex-direction: column; gap: 12px; }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-waiting { background: #fef3c7; color: #92400e; }
.status-hold { background: #f3e8ff; color: #6b21a8; }
.status-processing { background: #dbeafe; color: #1e40af; }
.status-success { background: #d1fae5; color: #065f46; }
.status-error { background: #fee2e2; color: #991b1b; }
.status-closed { background: var(--gray-100); color: var(--gray-500); }

/* ===== Steps ===== */
.steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 28px;
}

.step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    color: var(--gray-400);
    font-weight: 500;
    position: relative;
}

.step::after {
    content: '';
    width: 40px;
    height: 2px;
    background: var(--gray-200);
    margin-left: 12px;
}
.step:last-child::after { display: none; }

.step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    background: var(--gray-200);
    color: var(--gray-500);
}

.step.active { color: var(--primary); }
.step.active .step-num { background: var(--primary); color: white; }
.step.done .step-num { background: var(--success); color: white; }
.step.done { color: var(--success); }

/* ===== Upload ===== */
.upload-area {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--gray-400);
}
.upload-placeholder p { font-weight: 500; color: var(--gray-600); }

.upload-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.upload-preview img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 640px; }

.modal-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
}
.modal-close:hover { color: var(--gray-600); }

.modal-body { padding: 20px; }

/* ===== Help Icon ===== */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-500);
    font-size: 0.75rem;
    cursor: pointer;
    font-style: normal;
    transition: all 0.15s;
    vertical-align: middle;
}
.help-icon:hover { background: var(--primary-light); color: var(--primary); }

/* ===== Tables ===== */
.table-container { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.9rem;
}

.data-table tbody tr:hover { background: var(--gray-50); }

/* ===== Stats ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}
.stat-card-warning { border-left-color: var(--warning); }
.stat-card-info { border-left-color: var(--info); }
.stat-card-danger { border-left-color: var(--danger); }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
}
.stat-label {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ===== Detail Grid ===== */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-item label {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--gray-400);
    letter-spacing: 0.5px;
    font-weight: 600;
}
.detail-item p { margin-top: 4px; }

/* ===== Chat Replies ===== */
.replies-section {
    margin-top: 20px;
}
.replies-section h3 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    background: var(--gray-50);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    max-height: 500px;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    gap: 10px;
    max-width: 80%;
}

.chat-item-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-item-admin {
    align-self: flex-start;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.chat-item-user .chat-avatar {
    background: var(--primary);
}

.chat-item-admin .chat-avatar {
    background: var(--success);
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
    word-break: break-word;
}

.chat-item-user .chat-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-item-admin .chat-bubble {
    background: white;
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
    border-bottom-left-radius: 4px;
}

.chat-bubble-content {
    line-height: 1.6;
    font-size: 0.95rem;
    white-space: pre-wrap;
}

.chat-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 0.75rem;
}

.chat-item-user .chat-meta {
    justify-content: flex-end;
    color: rgba(255,255,255,0.7);
}

.chat-item-admin .chat-meta {
    color: var(--gray-400);
}

.chat-sender {
    font-weight: 600;
}

.chat-item-admin .chat-sender { color: var(--success); }
.chat-item-user .chat-sender { color: rgba(255,255,255,0.85); }

.chat-empty {
    text-align: center;
    padding: 30px;
    color: var(--gray-400);
    font-size: 0.9rem;
}

.reply-form {
    margin-top: 16px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.reply-form .form-input {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 120px;
}

.reply-form .btn {
    flex-shrink: 0;
    height: 44px;
}

/* ===== Misc ===== */
.reject-reason {
    background: #fef2f2;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #fecaca;
    color: #991b1b;
    margin: 8px 0;
}

.hint { color: var(--gray-500); font-size: 0.9rem; }

.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray-400);
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--gray-400);
    font-size: 0.95rem;
}

.link {
    color: var(--primary);
    font-weight: 500;
}
.link:hover { text-decoration: underline; }

.filter-group { display: flex; gap: 8px; align-items: center; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        width: 100%;
        height: auto;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        border-right: none;
        border-top: 1px solid var(--gray-200);
        flex-direction: row;
        z-index: 100;
    }
    .sidebar-header { display: none; }
    .sidebar-footer { display: none; }
    .sidebar-menu {
        display: flex;
        padding: 4px;
        width: 100%;
        justify-content: space-around;
    }
    .sidebar-menu a {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-bottom: 70px;
    }
    .service-code-inputs { gap: 2px; }
    .code-input { width: 56px; height: 42px; font-size: 0.9rem; }
    .auth-card { padding: 24px; }
    .steps { gap: 0; }
    .step { padding: 6px 8px; font-size: 0.85rem; }
    .step::after { width: 20px; margin-left: 4px; }
    .detail-grid { grid-template-columns: 1fr; }
    .chat-item { max-width: 90%; }
    .chat-list { padding: 12px; }
    .reply-form { flex-direction: column; }
    .reply-form .btn { width: 100%; height: auto; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
