/* ============================================================
   活码系统 - 全局样式
   设计：移动端优先 / 浅色主题 / 现代简约
   ============================================================ */

:root {
    /* 颜色系统 */
    --c-bg: #f6f7f9;
    --c-surface: #ffffff;
    --c-surface-2: #f9fafb;
    --c-border: #e5e7eb;
    --c-border-strong: #d1d5db;
    --c-text: #111827;
    --c-text-2: #4b5563;
    --c-text-3: #9ca3af;
    --c-primary: #4f46e5;
    --c-primary-hover: #4338ca;
    --c-primary-light: #eef2ff;
    --c-success: #059669;
    --c-success-light: #ecfdf5;
    --c-danger: #dc2626;
    --c-danger-light: #fef2f2;
    --c-warning: #d97706;
    --c-warning-light: #fffbeb;

    /* 圆角 */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-full: 9999px;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow-md: 0 4px 12px rgba(17, 24, 39, 0.08);
    --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.12);

    /* 间距 */
    --sidebar-w: 248px;
    --topbar-h: 64px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

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

svg { width: 20px; height: 20px; display: inline-block; vertical-align: middle; }

/* ============================================================
   布局
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--c-border);
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
    width: 32px; height: 32px;
    background: var(--c-primary);
    color: #fff;
    border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 16px;
}
.logo-text { font-weight: 600; font-size: 15px; color: var(--c-text); }

.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: var(--c-text-3); }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    color: var(--c-text-2);
    font-weight: 500;
    margin-bottom: 4px;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--c-surface-2); color: var(--c-text); }
.nav-item.active { background: var(--c-primary-light); color: var(--c-primary); }
.nav-icon { display: flex; }
.nav-icon svg { width: 18px; height: 18px; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--c-border); }
.user-block { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.user-avatar {
    width: 36px; height: 36px;
    border-radius: var(--r-full);
    background: var(--c-primary-light);
    color: var(--c-primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    text-transform: uppercase;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 13px; color: var(--c-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 12px; color: var(--c-text-3); }

.logout-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px;
    border-radius: var(--r-md);
    color: var(--c-text-2);
    font-size: 13px;
    transition: all 0.15s;
}
.logout-btn:hover { background: var(--c-danger-light); color: var(--c-danger); }
.logout-btn svg { width: 16px; height: 16px; }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.menu-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--c-text-2); }
.page-title { font-size: 17px; font-weight: 600; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.content { padding: 24px; flex: 1; max-width: 1280px; width: 100%; }

/* ============================================================
   卡片 & 面板
   ============================================================ */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* 统计卡片网格 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-label { font-size: 13px; color: var(--c-text-3); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--c-text); line-height: 1.2; }
.stat-icon {
    width: 40px; height: 40px;
    border-radius: var(--r-md);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.primary { background: var(--c-primary-light); color: var(--c-primary); }
.stat-icon.success { background: var(--c-success-light); color: var(--c-success); }
.stat-icon.warning { background: var(--c-warning-light); color: var(--c-warning); }
.stat-icon.danger { background: var(--c-danger-light); color: var(--c-danger); }

/* ============================================================
   按钮
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1.4;
    font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-hover); color: #fff; }
.btn-outline { background: var(--c-surface); border-color: var(--c-border-strong); color: var(--c-text-2); }
.btn-outline:hover { background: var(--c-surface-2); color: var(--c-text); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-ghost { background: transparent; color: var(--c-text-2); }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-text); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   表单
   ============================================================ */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--c-text);
    margin-bottom: 6px;
}
.form-label .req { color: var(--c-danger); margin-left: 2px; }
.form-hint { font-size: 12px; color: var(--c-text-3); margin-top: 6px; }
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--r-md);
    font-size: 14px;
    font-family: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.form-control::placeholder { color: var(--c-text-3); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--c-border);
}

/* ============================================================
   表格
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
}
.data-table th {
    background: var(--c-surface-2);
    font-weight: 600;
    color: var(--c-text-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--c-surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .col-actions { text-align: right; white-space: nowrap; }
.data-table .col-actions .btn { margin-left: 6px; }

/* ============================================================
   徽章
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
}
.badge-success { background: var(--c-success-light); color: var(--c-success); }
.badge-danger { background: var(--c-danger-light); color: var(--c-danger); }
.badge-warning { background: var(--c-warning-light); color: var(--c-warning); }
.badge-muted { background: var(--c-surface-2); color: var(--c-text-3); }
.badge-primary { background: var(--c-primary-light); color: var(--c-primary); }

/* ============================================================
   Flash 消息
   ============================================================ */
.flash-container { margin-bottom: 20px; display: flex; flex-direction: column; gap: 10px; }
.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--r-md);
    font-size: 13px;
    animation: slideDown 0.3s ease;
    border: 1px solid transparent;
}
.flash-success { background: var(--c-success-light); color: var(--c-success); border-color: #a7f3d0; }
.flash-error { background: var(--c-danger-light); color: var(--c-danger); border-color: #fecaca; }
.flash-warning { background: var(--c-warning-light); color: var(--c-warning); border-color: #fde68a; }
.flash-info { background: var(--c-primary-light); color: var(--c-primary); border-color: #c7d2fe; }
.flash-close { background: none; border: none; cursor: pointer; font-size: 20px; line-height: 1; color: inherit; opacity: 0.6; }
.flash-close:hover { opacity: 1; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   模态框
   ============================================================ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(17, 24, 39, 0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}
.modal {
    background: var(--c-surface);
    border-radius: var(--r-lg);
    width: 100%; max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 12px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--c-text-3); font-size: 22px; line-height: 1; }
.modal-close:hover { color: var(--c-text); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ============================================================
   空状态 & 分页
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--c-text-3);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { margin-bottom: 16px; }

.pagination { display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: 20px; flex-wrap: wrap; }
.pagination .btn { min-width: 36px; }
.pagination .page-info { font-size: 13px; color: var(--c-text-3); padding: 0 8px; }

/* ============================================================
   登录页
   ============================================================ */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #eef2ff 0%, #f6f7f9 50%, #ecfdf5 100%);
}
.auth-card {
    background: var(--c-surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
}
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.auth-title { text-align: center; font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.auth-subtitle { text-align: center; font-size: 13px; color: var(--c-text-3); margin-bottom: 28px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--c-text-3); }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--c-surface-2); padding: 4px; border-radius: var(--r-md); }
.auth-tab { flex: 1; text-align: center; padding: 8px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500; color: var(--c-text-2); cursor: pointer; transition: all 0.15s; }
.auth-tab.active { background: var(--c-surface); color: var(--c-primary); box-shadow: var(--shadow-sm); }

/* ============================================================
   链接项列表（用户面板专用）
   ============================================================ */
.link-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    margin-bottom: 10px;
    background: var(--c-surface-2);
    transition: box-shadow 0.15s, opacity 0.15s, transform 0.15s;
}
/* 拖拽手柄 */
.drag-handle {
    cursor: grab;
    color: var(--c-text-3);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 2px;
    border-radius: var(--r-sm);
    transition: color 0.15s, background 0.15s;
}
.drag-handle:hover { color: var(--c-primary); background: var(--c-primary-light); }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 18px; height: 18px; }
/* 拖拽中状态 */
.link-item.dragging {
    opacity: 0.5;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.25);
    transform: scale(0.99);
}
.link-item.drag-over {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}
.link-item-index {
    width: 28px; height: 28px;
    border-radius: var(--r-full);
    background: var(--c-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600;
    flex-shrink: 0;
}
.link-item-body { flex: 1; min-width: 0; }
.link-item-url {
    font-size: 13px;
    color: var(--c-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.link-item-url a {
    color: var(--c-primary);
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}
.link-item-meta { font-size: 12px; color: var(--c-text-3); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 复制按钮反馈 */
.copy-input-group { display: flex; gap: 8px; align-items: stretch; }
.copy-input-group .form-control { flex: 1; font-family: monospace; font-size: 13px; }

/* ============================================================
   工具类
   ============================================================ */
.text-center { text-align: center; }
.text-muted { color: var(--c-text-3); }
.text-danger { color: var(--c-danger); }
.text-success { color: var(--c-success); }
.text-sm { font-size: 12px; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 8px; } .gap-4 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }

/* ============================================================
   响应式
   ============================================================ */
.overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(17, 24, 39, 0.4);
    z-index: 99;
}
.overlay.active { display: block; }

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: flex; }
    .main { margin-left: 0; }
    .menu-toggle { display: flex; }
    .content { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
}

@media (max-width: 640px) {
    .topbar { padding: 0 16px; }
    .page-title { font-size: 15px; }
    .content { padding: 12px; }
    .card-body { padding: 16px; }
    .card-header { padding: 14px 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-value { font-size: 22px; }
    .form-row { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .data-table th, .data-table td { padding: 10px 12px; }
    .auth-card { padding: 28px 24px; }
    .modal { max-width: 100%; }
    .btn-sm { padding: 8px 12px; }
}

/* 移动端操作按钮简化 */
@media (max-width: 480px) {
    .data-table .btn-label { display: none; }
    .data-table .col-actions .btn { padding: 8px; }
}
