:root {
    --bg: #f8fafc;
    --bg-accent: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #3b82f6;
    --primary-2: #2563eb;
    --danger: #ef4444;
    --success: #10b981;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --sidebar-bg: #1e293b;
}

/* 全局气泡提示 Toast */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    min-width: 260px;
    max-width: 400px;
    padding: 12px 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    border-left: 4px solid var(--primary);
    animation: toast-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    pointer-events: auto;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(50px) scale(0.9); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

.toast-fade-out {
    animation: toast-out 0.3s ease-in forwards !important;
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(50px); }
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--card);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.auth-card h1 {
    margin: 0 0 4px;
    font-size: 28px;
}

.auth-card h2 {
    margin: 16px 0;
    font-size: 20px;
}

label {
    font-size: 13px;
    color: var(--muted);
    margin: 8px 0 4px;
    display: block;
}

input,
select,
button {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    font-size: 14px;
}

input:focus {
    outline: 2px solid rgba(13, 110, 253, 0.25);
    border-color: var(--primary);
}

button {
    margin-top: 12px;
    border: none;
    background: linear-gradient(120deg, var(--primary), var(--primary-2));
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    filter: brightness(1.04);
}

.btn-success {
    background: #10b981;
    color: #fff;
    border: none;
}

.btn-warn {
    background: #f59e0b;
    color: #fff;
    border: none;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
    border: none;
}

.btn-danger-outline {
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
}

.btn-danger-outline:hover {
    background: #ef4444;
    color: #fff;
}

.alert {
    border-radius: 10px;
    padding: 10px 12px;
    margin: 10px 0;
    font-size: 13px;
}

.alert.success {
    background: rgba(20, 159, 100, 0.12);
    color: #0d7c4e;
}

.alert.error {
    background: rgba(222, 60, 75, 0.12);
    color: #ab1f2c;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    padding: 24px 20px;
    letter-spacing: -0.025em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar a {
    color: #cbd5e1;
    padding: 10px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.sidebar a.active {
    background: var(--primary);
    color: #fff;
}

.content {
    flex: 1;
    padding: 24px;
    min-width: 0;
}

@media (max-width: 920px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        position: relative;
    }

    .brand {
        padding: 16px 20px;
    }

    .sidebar nav {
        flex-direction: row;
        overflow-x: auto;
        padding: 8px 12px;
        scrollbar-width: none;
    }

    .sidebar nav::-webkit-scrollbar {
        display: none;
    }

    .sidebar a {
        white-space: nowrap;
        padding: 8px 16px;
    }
}

.topbar {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 24px;
}

.topbar h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.topbar p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.card h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 1.1rem;
    font-weight: 600;
}

.grid-form {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 12px;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 5px;
}

.grid-form > div {
    flex: 1;
    min-width: 150px;
    flex-shrink: 0;
}

.grid-form label {
    margin-bottom: 6px;
    white-space: nowrap;
}

.grid-form button {
    width: auto;
    height: 38px;
    padding: 0 20px;
    margin-top: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

@media (max-width: 920px) {
    .grid-form {
        flex-wrap: nowrap; /* 移动端也强行单行，超出则滑动 */
    }
}

.token-input-wrap {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 12px;
}

.btn-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    font-weight: 500;
}

.filter-form {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    padding: 16px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.filter-form input,
.filter-form select,
.filter-form button {
    width: auto;
    margin: 0;
    height: 38px;
}

.btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
}

.page-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.page-total {
    color: var(--muted);
    font-size: 13px;
    margin-left: 4px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

th {
    background: #f8fafc;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
}

th, td {
    padding: 12px 16px;
    text-align: left;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: #f8fafc;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.inline-form input,
.inline-form button {
    width: auto;
    margin: 0;
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
}

.token-ops-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.admin-ops {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
}

.admin-ops form {
    display: flex;
    flex-shrink: 0;
    margin: 0;
}

.mini-input {
    width: 90px;
}

.token-cell {
    max-width: 230px;
    word-break: break-all;
}

@media (max-width: 920px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    .brand {
        padding: 12px 20px;
        font-size: 18px;
        text-align: center;
        border-bottom: none;
    }

    .sidebar nav {
        flex-direction: row;
        overflow-x: auto;
        padding: 4px 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        scrollbar-width: none;
    }

    .sidebar nav::-webkit-scrollbar {
        display: none;
    }

    .sidebar a {
        white-space: nowrap;
        padding: 8px 12px;
        font-size: 13px;
    }

    .content {
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    /* 移动端操作表单：改为一行一个字段 */
    .grid-form {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .grid-form > div {
        width: 100%;
        min-width: 0;
    }

    .grid-form button {
        width: 100%;
        height: 42px;
    }

    .filter-form {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .filter-form input,
    .filter-form select,
    .filter-form button,
    .btn-link {
        width: 100%;
        height: 42px;
    }

    .token-input-wrap {
        grid-template-columns: 1fr;
    }

    .token-input-wrap button {
        height: 42px;
    }

    .table-wrap {
        border: none;
    }

    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead {
        display: none;
    }

    /* 概览页面的最近日志在移动端隐藏标题显示 */
    section[data-view="dashboard"] thead {
        display: none;
    }

    /* 概览页面的 TD 渲染：不显示前面的 data-label */
    section[data-view="dashboard"] td::before {
        display: none;
    }

    section[data-view="dashboard"] td {
        display: block;
        padding: 4px 0;
        text-align: left;
    }

    tr {
        margin-bottom: 16px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: #fff;
        padding: 12px;
        box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    }

    td {
        border: none;
        padding: 6px 0;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        text-align: left;
        font-size: 13px;
    }

    td::before {
        content: attr(data-label) "：";
        font-weight: 600;
        color: var(--muted);
        margin-bottom: 0;
        font-size: 12px;
        flex-shrink: 0;
    }

    .token-cell {
        max-width: 180px;
        font-size: 11px;
        color: #475569;
    }

    /* 移动端列表中的操作按钮：改为一行一个操作 */
    .admin-ops {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-top: 8px;
    }

    .admin-ops form {
        width: 100%;
    }

    .inline-form {
        width: 100%;
        flex-wrap: wrap;
    }

    .inline-form input {
        flex: 1;
        min-width: 100px;
    }

    .inline-form button {
        flex: 1;
    }
}
