*,
*::before,
*::after {
    box-sizing: border-box;
}

/* CSS 变量 */
:root {
    --primary-color: #007aff;
    --primary-hover: #0062cc;
    --danger-color: #dc3545;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #6c757d;
    --gray-600: #495057;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;
    --bg-dark: #1e293b;
    --bg-darker: #0f172a;
    --border-dark: #334155;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--gray-100);
    color: var(--gray-700);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.hidden {
    display: none !important;
}

/* 初始加载遮罩 */
#initialLoader {
    position: fixed;
    inset: 0;
    background-color: white;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease-out;
}

#initialLoader.fade-out {
    opacity: 0;
}

.loading-spinner .spinner-icon {
    width: 50px;
    height: 50px;
    animation: rotate 1.5s linear infinite;
}

.loading-spinner .spinner-circle {
    stroke: var(--primary-color);
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate {
    100% { transform: rotate(360deg); }
}

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

/* 登录页面 */
#loginPage {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    width: 100%;
    max-width: 420px;
}

.login-title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
    text-align: center;
}

.login-subtitle {
    font-size: 0.9375rem;
    color: var(--gray-500);
    margin-bottom: 2rem;
    text-align: center;
}

/* 表单样式 */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.form-hint {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.9375rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

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

.btn-outline {
    background-color: white;
    color: var(--gray-700);
    border-color: var(--gray-200);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--gray-100);
    border-color: var(--gray-400);
}

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

.btn-danger:hover:not(:disabled) {
    background-color: #c82333;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-block {
    width: 100%;
}

.cancel-btn {
    background-color: var(--gray-100);
    color: var(--gray-700);
}

.cancel-btn:hover:not(:disabled) {
    background-color: var(--gray-200);
}

/* 认证切换 */
.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9375rem;
    color: var(--gray-600);
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* 成功消息 */
.success-message {
    text-align: center;
    padding: 1rem;
}

.success-icon {
    margin-bottom: 1rem;
}

.success-message h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
}

.success-message p {
    font-size: 0.9375rem;
    color: var(--gray-600);
    margin-bottom: 1.5rem;
}

/* 导航栏 */
.navbar {
    background-color: white;
    padding: 1rem 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 50;
}

.navbar-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1280px;
    margin: 0 auto;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: var(--gray-100);
    border-radius: 0.5rem;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.9rem;
}

/* 主容器 */
.main-container {
    max-width: 1280px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* 操作栏 */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.75rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

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

.action-buttons {
    display: flex;
    gap: 0.75rem;
}

/* 令牌列表 */
.token-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

/* 空状态 */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--gray-500);
}

.empty-state svg {
    margin-bottom: 1rem;
    color: var(--gray-300);
}

.empty-state p {
    font-size: 1.125rem;
    margin-bottom: 1.5rem;
}

/* 令牌卡片 */
.token-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 0.75rem;
    padding: 1.5rem;
    transition: all 0.2s;
}

.token-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

.token-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;
}

.token-info h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
    word-break: break-word;
}

.delete-btn {
    padding: 0.5rem;
    background: transparent;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: 0.375rem;
    transition: all 0.2s;
}

.delete-btn:hover {
    background: #fee2e2;
    color: var(--danger-color);
}

.token-code-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.token-code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Courier New', monospace;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.25rem;
    color: var(--primary-color);
    flex: 1;
}

.progress-ring {
    width: 40px;
    height: 40px;
    transform: rotate(-90deg);
    flex-shrink: 0;
}

.progress-ring-circle {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 3;
}

.progress-ring-fill {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear;
}

.copy-btn {
    padding: 0.5rem;
    background: transparent;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: 0.375rem;
    transition: all 0.2s;
    flex-shrink: 0;
}

.copy-btn:hover {
    background: var(--gray-100);
    color: var(--primary-color);
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 0.75rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}

.modal-large {
    max-width: 800px;
}

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.modal-body {
    padding: 1.5rem;
}

/* 标签页 */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--gray-200);
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--gray-500);
    transition: all 0.2s;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-btn:hover:not(.active) {
    color: var(--gray-700);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* 二维码上传 */
.qr-upload-area {
    margin-bottom: 1.5rem;
}

.drop-zone {
    border: 2px dashed var(--gray-300);
    border-radius: 0.75rem;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-500);
    background: var(--gray-100);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary-color);
    background: rgba(0, 122, 255, 0.05);
    color: var(--primary-color);
}

.drop-zone svg {
    margin-bottom: 1rem;
}

.drop-zone p {
    margin: 0.5rem 0;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--gray-700);
}

.drop-zone small {
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.qr-success {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    background: #d1fae5;
    border-radius: 0.5rem;
    margin-bottom: 1.25rem;
    color: #065f46;
    font-weight: 500;
    font-size: 0.9375rem;
}

#qrResult input[readonly] {
    background: var(--gray-100);
    color: var(--gray-600);
    cursor: not-allowed;
}

#qrTokenName {
    border: 2px solid var(--gray-300);
    transition: border-color 0.2s;
}

#qrTokenName:focus {
    border-color: var(--primary-color);
    background: white;
}

/* API 文档 */
.api-section {
    margin-bottom: 2rem;
}

.api-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 1rem;
}

.code-block {
    background-color: var(--bg-dark);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1rem;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-darker);
    border-bottom: 1px solid var(--border-dark);
}

.code-title {
    color: #94a3b8;
    font-size: 0.875rem;
    font-weight: 500;
}

.btn-copy {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background-color: var(--border-dark);
    color: #e2e8f0;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copy:hover {
    background-color: #475569;
}

.code-content {
    padding: 1rem;
}

.code-content pre {
    margin: 0;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #e2e8f0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.api-url {
    color: #60a5fa;
}

.api-key {
    color: #fbbf24;
}

/* 通知系统 */
#notificationContainer {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 400px;
}

.notification {
    padding: 1rem 1.25rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    font-size: 0.9375rem;
    font-weight: 500;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.notification.show {
    opacity: 1;
    transform: translateX(0);
}

.notification-success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success-color);
}

.notification-error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger-color);
}

.notification-warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning-color);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .navbar {
        padding: 1rem;
    }

    .navbar-container {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .navbar-actions {
        justify-content: space-between;
    }

    .main-container {
        margin: 1rem auto;
        padding: 0 1rem;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: none;
    }

    .action-buttons {
        justify-content: space-between;
    }

    .token-list {
        grid-template-columns: 1fr;
    }

    .token-code {
        font-size: 1.5rem;
        letter-spacing: 0.15rem;
    }

    .login-card {
        padding: 2rem 1.5rem;
    }

    .modal-content {
        width: 95%;
    }

    .drop-zone {
        padding: 2rem 1rem;
    }

    #notificationContainer {
        top: auto;
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
        max-width: none;
    }

    .btn-sm span {
        display: none;
    }
}

@media (max-width: 480px) {
    .navbar-brand {
        font-size: 1.25rem;
    }

    .action-buttons {
        flex-wrap: wrap;
    }

    .action-buttons .btn {
        flex: 1;
        min-width: 120px;
    }

    .token-code {
        font-size: 1.25rem;
        letter-spacing: 0.1rem;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }
}

/* 打印样式 */
@media print {
    .navbar,
    .action-bar,
    .delete-btn,
    .copy-btn,
    .modal {
        display: none !important;
    }

    .token-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
