/* ===========================================================================
 * 基础层 — reset / 排版 / 全局可访问性
 * 依赖 tokens.css，本文件不得出现硬编码色值。
 * =========================================================================== */

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

html {
    /* iOS 横屏时不自动放大字号 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

[hidden] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
        Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background-color: var(--kk-bg);
    background-image: linear-gradient(to bottom, var(--kk-primary-soft), transparent 260px);
    background-repeat: no-repeat;
    color: var(--kk-text);
    font-size: var(--kk-text-base);
    line-height: var(--kk-leading-base);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* 主题切换时不生硬跳变 */
    transition: background-color var(--kk-dur-base) var(--kk-ease),
        color var(--kk-dur-base) var(--kk-ease);
}

::selection {
    color: var(--kk-text);
    background: var(--kk-primary-soft);
}

h1,
h2,
h3,
h4 {
    color: var(--kk-text);
    line-height: var(--kk-leading-tight);
    font-weight: 600;
}

h2 {
    font-size: var(--kk-text-xl);
}

h3 {
    font-size: var(--kk-text-lg);
}

h4 {
    font-size: var(--kk-text-md);
}

p {
    color: var(--kk-text);
}

a {
    color: var(--kk-link);
    text-decoration: none;
}

ul,
ol {
    padding-left: var(--kk-space-5);
}

li {
    margin-bottom: var(--kk-space-1);
}

strong {
    font-weight: 600;
}

small {
    font-size: var(--kk-text-sm);
}

/* ---------------------------------------------------------------------------
 * 键盘可达性
 * 只在键盘导航时显示焦点环：鼠标/触摸点击不显示，但绝不整体去掉 outline。
 * ------------------------------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--kk-primary);
    outline-offset: 2px;
    border-radius: var(--kk-radius-sm);
}

:focus:not(:focus-visible) {
    outline: none;
}

/* 触摸设备上去掉系统默认的点击高亮块，改由各组件自己的 :active 表达 */
button,
a,
[role='button'],
[onclick] {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    cursor: pointer;
    background: none;
    border: none;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

/* ---------------------------------------------------------------------------
 * 图标
 * stroke 走 currentColor，颜色跟随所在文字，自动适配亮暗主题。
 * ------------------------------------------------------------------------- */
.kk-icon {
    display: inline-block;
    vertical-align: -0.15em;
    flex-shrink: 0;
}

[data-icon] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

/* ---------------------------------------------------------------------------
 * 首屏加载态
 * ------------------------------------------------------------------------- */
.loading-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: var(--kk-vh, 100vh);
    background-color: var(--kk-bg);
    color: var(--kk-text-muted);
    gap: var(--kk-space-4);
    padding: var(--kk-space-6);
    text-align: center;
}

.loading-brand {
    position: relative;
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
}

.loading-brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--kk-radius-md);
    background: var(--kk-primary);
    color: var(--kk-on-primary);
    font-size: var(--kk-text-md);
    font-weight: 800;
    letter-spacing: 0;
    box-shadow: var(--kk-shadow-sm);
}

.loading-progress {
    position: absolute;
    inset: 0;
    border: 3px solid var(--kk-border);
    border-top-color: var(--kk-primary);
    border-radius: 50%;
    animation: kk-spin 0.9s linear infinite;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--kk-border);
    border-top-color: var(--kk-primary);
    border-radius: 50%;
    animation: kk-spin 0.9s linear infinite;
}

@keyframes kk-spin {
    to {
        transform: rotate(360deg);
    }
}

/* 降低动效偏好下，转圈换成低频呼吸，仍能表达「在动」但不旋转 */
@media (prefers-reduced-motion: reduce) {
    .loading-progress,
    .loading-spinner {
        animation: kk-pulse 1.6s ease-in-out infinite;
    }
}

@keyframes kk-pulse {
    0%,
    100% {
        opacity: 0.4;
    }
    50% {
        opacity: 1;
    }
}

/* 全屏遮罩加载器（长操作） */
.global-loader {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--kk-scrim);
    z-index: var(--kk-z-loader);
    padding: var(--kk-space-6);
}

.global-loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--kk-space-4);
    background: var(--kk-surface);
    color: var(--kk-text);
    border: 1px solid var(--kk-border);
    border-radius: var(--kk-radius-lg);
    padding: var(--kk-space-6) var(--kk-space-8);
    box-shadow: var(--kk-shadow-lg);
    text-align: center;
}

/* 文案类加载占位 */
.loading-text,
.loading-message {
    color: var(--kk-text-muted);
    font-size: var(--kk-text-sm);
    text-align: center;
    padding: var(--kk-space-4);
}

/* ---------------------------------------------------------------------------
 * 通用状态文案
 * ------------------------------------------------------------------------- */
.no-data {
    color: var(--kk-text-subtle);
    font-size: var(--kk-text-sm);
    text-align: center;
    padding: var(--kk-space-5) var(--kk-space-4);
}

.error-message {
    color: var(--kk-danger-fg);
    font-size: var(--kk-text-sm);
}

.success-content,
.info-content,
.warning-content {
    flex: 1;
    min-width: 0;
}

.error-icon,
.success-icon,
.info-icon,
.warning-icon,
.notice-icon,
.status-icon {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
 * 工具类
 * ------------------------------------------------------------------------- */
.mt-2 {
    margin-top: var(--kk-space-2);
}

/* 群管理员视图下隐藏超管专属区块（role.js 同步 inline 控制，此处兜底） */
body[data-role='chat_admin'] .super-only {
    display: none !important;
}

/* ---------------------------------------------------------------------------
 * 滚动条：默认样式在暗色下是亮色滑块，很跳
 * ------------------------------------------------------------------------- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--kk-border-strong) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--kk-border-strong);
    border-radius: var(--kk-radius-full);
}
