/* =====================================================================
   Keysell 客户端 设计系统
   零外部依赖。改品牌色只改 :root 里的 --c-primary 系列。
   ===================================================================== */

:root {
    /* 品牌 / 主色 */
    --c-primary: #2563eb;
    --c-primary-600: #1d4ed8;
    --c-primary-700: #1e40af;
    --c-primary-50: #eff6ff;
    --c-primary-100: #dbeafe;

    /* 中性色 */
    --c-bg: #f3f5f9;
    --c-surface: #ffffff;
    --c-surface-2: #f8fafc;
    --c-border: #e3e8ef;
    --c-border-strong: #cbd5e1;
    --c-text: #1e293b;
    --c-text-2: #475569;
    --c-text-3: #94a3b8;

    /* 语义色 */
    --c-success: #15803d;  --c-success-bg: #dcfce7;
    --c-warning: #b45309;  --c-warning-bg: #fef3c7;
    --c-danger:  #b91c1c;  --c-danger-bg:  #fee2e2;
    --c-info:    #1d4ed8;  --c-info-bg:    #dbeafe;

    /* 标签色（与 includes/forecast.php 里的 color 名对应） */
    --tag-blue:   #1d4ed8; --tag-blue-bg:   #dbeafe;
    --tag-red:    #b91c1c; --tag-red-bg:    #fee2e2;
    --tag-purple: #6d28d9; --tag-purple-bg: #ede9fe;
    --tag-green:  #15803d; --tag-green-bg:  #dcfce7;
    --tag-yellow: #a16207; --tag-yellow-bg: #fef9c3;
    --tag-orange: #c2410c; --tag-orange-bg: #ffedd5;
    --tag-gray:   #475569; --tag-gray-bg:   #e2e8f0;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
    --shadow-lg: 0 10px 40px rgba(16, 24, 40, .18);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
            "Microsoft YaHei", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --topbar-h: 56px;
}

/* ---------- 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 13px; letter-spacing: .01em; }
.muted { color: var(--c-text-3); }
.muted-2 { color: var(--c-text-2); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.container {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
}

/* ---------- 顶栏 ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
}
.topbar__inner {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 24px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--c-text);
    text-decoration: none;
    flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand__mark {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-700));
    color: #fff;
    font-weight: 800;
    font-size: 17px;
    display: grid; place-items: center;
    letter-spacing: -.02em;
}
.brand__name { font-weight: 700; font-size: 16px; }
.brand__sub { color: var(--c-text-3); font-size: 12px; margin-left: 6px; }

.nav { display: flex; gap: 4px; height: 100%; }
.nav__item {
    position: relative;
    height: 100%;
    padding: 0 14px;
    border: 0;
    background: none;
    color: var(--c-text-2);
    font-weight: 500;
    display: inline-flex; align-items: center; gap: 6px;
}
.nav__item:hover { color: var(--c-text); }
.nav__item.is-active { color: var(--c-primary); }
.nav__item.is-active::after {
    content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px;
    height: 2px; border-radius: 2px; background: var(--c-primary);
}
.topbar__user {
    margin-left: auto;
    display: flex; align-items: center; gap: 14px;
    color: var(--c-text-2);
    font-size: 13px;
}
.topbar__user .company { font-weight: 600; color: var(--c-text); }
.topbar__user .sep { color: var(--c-border-strong); }

/* ---------- 通知条 ---------- */
.notice {
    background: var(--c-warning-bg);
    border-bottom: 1px solid #fde68a;
    color: #78350f;
}
.notice__inner {
    display: flex; align-items: flex-start; gap: 10px;
    padding-top: 10px; padding-bottom: 10px;
}
.notice__icon { flex-shrink: 0; margin-top: 2px; color: var(--c-warning); }
.notice__text { flex: 1; min-width: 0; white-space: pre-line; font-size: 13px; }
.notice.is-collapsed .notice__text {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notice__toggle {
    flex-shrink: 0;
    border: 0; background: none; color: var(--c-warning);
    font-size: 13px; padding: 0 4px; font-weight: 500;
}

/* ---------- 页面 / 卡片 ---------- */
.main { padding-top: 24px; padding-bottom: 48px; }
.page { display: none; }
.page.is-active { display: block; }
.stack > * + * { margin-top: 20px; }

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--c-border);
}
.card__title { font-size: 16px; }
.card__title-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card__body { padding: 20px; }
.card__body--tight { padding: 0; }
.card__footer { padding: 14px 20px; border-top: 1px solid var(--c-border); background: var(--c-surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions--between { justify-content: space-between; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 13px; font-weight: 500; color: var(--c-text-2); }
.field__help { font-size: 12px; color: var(--c-text-3); }
.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    background: var(--c-surface);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-100);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--c-surface-2); color: var(--c-text-3); }
.input--sm, .select--sm { padding: 6px 10px; font-size: 13px; }
.textarea { resize: vertical; min-height: 44px; }
.select {
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}
.form-grid--forecast { grid-template-columns: minmax(200px, 260px) 1fr; }
.checkbox { width: 16px; height: 16px; accent-color: var(--c-primary); cursor: pointer; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--c-primary-600); }
.btn--secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--c-surface-2); }
.btn--ghost { background: transparent; color: var(--c-text-2); }
.btn--ghost:hover:not(:disabled) { background: var(--c-surface-2); color: var(--c-text); }
.btn--danger { background: var(--c-surface); color: var(--c-danger); border-color: #fecaca; }
.btn--danger:hover:not(:disabled) { background: var(--c-danger-bg); }
.btn--sm { padding: 6px 12px; font-size: 13px; }
.btn--lg { padding: 12px 22px; font-size: 15px; }
.btn--block { width: 100%; }
.btn--link { padding: 0; border: 0; background: none; color: var(--c-primary); font-weight: 500; }
.btn--link:hover { text-decoration: underline; }
.btn--link.danger { color: var(--c-danger); }

/* ---------- 标签 / 筹码 ---------- */
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px; font-weight: 500;
    white-space: nowrap;
    background: var(--tag-gray-bg); color: var(--tag-gray);
}
.tag--blue   { background: var(--tag-blue-bg);   color: var(--tag-blue); }
.tag--red    { background: var(--tag-red-bg);    color: var(--tag-red); }
.tag--purple { background: var(--tag-purple-bg); color: var(--tag-purple); }
.tag--green  { background: var(--tag-green-bg);  color: var(--tag-green); }
.tag--yellow { background: var(--tag-yellow-bg); color: var(--tag-yellow); }
.tag--orange { background: var(--tag-orange-bg); color: var(--tag-orange); }
.tag--gray   { background: var(--tag-gray-bg);   color: var(--tag-gray); }

.badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 999px;
    background: var(--c-primary); color: #fff;
    font-size: 11px; font-weight: 600; line-height: 1;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-text-2);
    font-size: 13px;
}
.chip:hover { border-color: var(--c-border-strong); color: var(--c-text); }
.chip.is-active { background: var(--c-primary-50); border-color: var(--c-primary); color: var(--c-primary-700); font-weight: 500; }
.chip__count { font-variant-numeric: tabular-nums; color: var(--c-text-3); }
.chip.is-active .chip__count { color: var(--c-primary-600); }
.chip__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .7; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px; font-weight: 600;
    color: var(--c-text-3);
    letter-spacing: .02em;
    border-bottom: 1px solid var(--c-border);
    background: var(--c-surface);
    white-space: nowrap;
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--c-surface-2); }
.table--sticky th { position: sticky; top: 0; z-index: 1; }
.table .td-right { text-align: right; }
.table .td-num { font-variant-numeric: tabular-nums; }
.table-wrap--tall { max-height: calc(100vh - 320px); overflow-y: auto; }

/* 响应式表格：窄屏时每行变卡片，用 data-label 显示列名 */
@media (max-width: 720px) {
    .table--responsive thead { display: none; }
    .table--responsive, .table--responsive tbody, .table--responsive tr, .table--responsive td { display: block; width: 100%; }
    .table--responsive tr {
        border: 1px solid var(--c-border);
        border-radius: var(--radius-sm);
        margin: 0 0 10px;
        padding: 6px 0;
        background: var(--c-surface);
    }
    .table--responsive td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 7px 14px;
        border-bottom: 0;
        text-align: right;
    }
    .table--responsive td::before {
        content: attr(data-label);
        color: var(--c-text-3);
        font-size: 12px;
        flex-shrink: 0;
        text-align: left;
    }
    .table--responsive td.td-title {
        display: block; text-align: left;
        padding-bottom: 4px;
        font-size: 15px;
    }
    .table--responsive td.td-title::before { display: none; }
    .table--responsive tbody tr:hover td { background: transparent; }
    .table--responsive td.td-actions { justify-content: flex-end; }
    .table--responsive td.td-actions::before { display: none; }
    .table--responsive td.td-empty { display: none; }
}

/* ---------- 缩略图 / 灯箱 ---------- */
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumb {
    width: 44px; height: 44px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--c-border);
    cursor: zoom-in;
    background: var(--c-surface-2);
    transition: transform .12s;
}
.thumb:hover { transform: scale(1.06); }
.thumb--more {
    width: 44px; height: 44px; border-radius: 6px;
    display: grid; place-items: center;
    background: var(--c-surface-2); color: var(--c-text-2);
    font-size: 12px; border: 1px dashed var(--c-border-strong); cursor: pointer;
}

.modal {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15, 23, 42, .6);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal__box {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 960px; width: 100%;
    max-height: 90vh;
    display: flex; flex-direction: column;
}
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--c-border); }
.modal__close { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--c-text-3); padding: 4px 8px; }
.modal__close:hover { color: var(--c-text); }
.modal__body { padding: 16px; overflow: auto; display: flex; align-items: center; justify-content: center; }
.modal__body img { max-width: 100%; max-height: 75vh; object-fit: contain; border-radius: 6px; }
.modal__nav { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; border-top: 1px solid var(--c-border); font-size: 13px; color: var(--c-text-2); }

/* ---------- 搜索区 ---------- */
.search { position: relative; }
.search__box {
    width: 100%;
    padding: 14px 16px;
    font-size: 15px;
    font-family: var(--mono);
    line-height: 1.5;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    resize: none;
    outline: none;
    min-height: 52px;
    max-height: 40vh;
    overflow-y: auto;
    transition: border-color .15s, box-shadow .15s;
}
.search__box:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-100); }
.search__box::placeholder { font-family: var(--font); color: var(--c-text-3); }
.search__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.search__hint { font-size: 12px; color: var(--c-text-3); }
.search__advanced { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--c-border); }

.notfound {
    display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap;
    padding: 12px 20px;
    background: var(--c-warning-bg);
    border-bottom: 1px solid #fde68a;
    color: #78350f; font-size: 13px;
}
.notfound__list { display: flex; gap: 6px; flex-wrap: wrap; }
.notfound__item { font-family: var(--mono); background: #fff; border: 1px solid #fde68a; border-radius: 4px; padding: 1px 6px; font-size: 12px; }

/* ---------- 空状态 ---------- */
.empty {
    text-align: center;
    padding: 56px 20px;
    color: var(--c-text-3);
}
.empty__icon { width: 48px; height: 48px; margin: 0 auto 12px; color: var(--c-border-strong); }
.empty__title { font-size: 15px; color: var(--c-text-2); font-weight: 500; }
.empty__sub { font-size: 13px; margin-top: 4px; }

/* ---------- 步骤 ---------- */
.steps { display: flex; gap: 0; margin-bottom: 20px; }
.step { display: flex; align-items: center; gap: 8px; color: var(--c-text-3); font-size: 13px; font-weight: 500; }
.step + .step::before { content: ''; width: 40px; height: 1px; background: var(--c-border); margin: 0 12px; }
.step__num {
    width: 24px; height: 24px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--c-surface-2); border: 1px solid var(--c-border-strong);
    font-size: 12px; font-weight: 600;
}
.step.is-active { color: var(--c-primary-700); }
.step.is-active .step__num { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.step.is-done { color: var(--c-success); }
.step.is-done .step__num { background: var(--c-success-bg); border-color: var(--c-success); color: var(--c-success); }

/* 预览表格 */
.preview .input, .preview .select { padding: 5px 8px; font-size: 13px; }
.preview tr.is-added td { background: var(--c-success-bg); }
.preview tr.is-exists td { background: var(--c-surface-2); color: var(--c-text-3); }
.preview tr.is-invalid td { background: var(--c-danger-bg); }
.preview .check-ok { color: var(--c-success); }
.preview .check-exists { color: var(--c-text-3); }
.preview .check-invalid { color: var(--c-danger); }
.preview .check-note { display: block; color: var(--c-warning); font-size: 12px; }
.preview .btn-remove { border: 0; background: none; color: var(--c-text-3); font-size: 16px; padding: 2px 6px; }
.preview .btn-remove:hover { color: var(--c-danger); }

/* ---------- 提示 / 加载 ---------- */
.toast-stack {
    position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
    z-index: 200;
    display: flex; flex-direction: column; gap: 8px; align-items: center;
    pointer-events: none;
    width: min(520px, calc(100% - 32px));
}
.toast {
    pointer-events: auto;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 14px;
    background: var(--c-text); color: #fff;
    white-space: pre-line;
    animation: toast-in .18s ease-out;
    max-width: 100%;
}
.toast--success { background: var(--c-success); }
.toast--error { background: var(--c-danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.loading {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(255, 255, 255, .55);
    display: flex; align-items: center; justify-content: center;
}
.loading::after {
    content: '';
    width: 36px; height: 36px;
    border: 3px solid var(--c-primary-100);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border: 1px solid transparent;
}
.alert--error { background: var(--c-danger-bg); color: var(--c-danger); border-color: #fecaca; }
.alert--info { background: var(--c-info-bg); color: var(--c-info); border-color: #bfdbfe; }

/* ---------- 登录页 ---------- */
.auth {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px 16px;
    background:
        radial-gradient(900px 500px at 10% -10%, var(--c-primary-100), transparent 60%),
        radial-gradient(700px 400px at 110% 110%, #e0e7ff, transparent 60%),
        var(--c-bg);
}
.auth__card {
    width: 100%; max-width: 400px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 32px 28px 28px;
}
.auth__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth__brand .brand__mark { width: 40px; height: 40px; font-size: 20px; border-radius: 11px; }
.auth__title { font-size: 20px; font-weight: 700; }
.auth__sub { color: var(--c-text-3); font-size: 13px; margin-top: 2px; }
.auth__form { display: flex; flex-direction: column; gap: 14px; }
.auth__foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--c-text-3); }

/* ---------- 响应式 ---------- */
@media (max-width: 960px) {
    .container { padding-left: 16px; padding-right: 16px; }
    .brand__sub { display: none; }
}
@media (max-width: 720px) {
    .main { padding-top: 16px; }
    .form-grid--forecast { grid-template-columns: 1fr; }
    .topbar__inner { gap: 12px; }
    .topbar__user .company, .topbar__user .sep, .topbar__user .username { display: none; }
    .nav__item { padding: 0 10px; }
    .card__header { padding: 14px 16px; }
    .card__body { padding: 16px; }
    .stack > * + * { margin-top: 14px; }
    .steps { flex-wrap: wrap; gap: 8px 0; }
    .step + .step::before { width: 16px; margin: 0 8px; }
    .search__box { font-size: 14px; }
    .btn--lg { padding: 11px 18px; font-size: 14px; }
    .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
    .form-grid { grid-template-columns: 1fr; }
    .brand__name { font-size: 15px; }
}

/* 窄屏下隐藏批量选择列（每行有独立的删除按钮） */
@media (max-width: 720px) {
    .table--responsive td.td-check { display: none; }
}
