:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-bg: #f1f5f9;
    --color-surface: #ffffff;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-error-bg: #fef2f2;
    --color-error-text: #dc2626;
    --color-sidebar: #1e293b;
    --shadow-card: 0 4px 24px rgba(15, 23, 42, 0.08);
    --radius: 12px;
    --topbar-height: 56px;
    --bottom-nav-height: 60px;
}

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

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    color: var(--color-primary-hover);
}

/* ---- Login Page ---- */

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(160deg, #eff6ff 0%, var(--color-bg) 50%, #f8fafc 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 32px 24px;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}

.login-card .subtitle {
    margin: 0 0 24px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.login-divider {
    display: flex;
    align-items: center;
    margin: 20px 0 16px;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
}

.login-divider::before,
.login-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.login-divider span {
    padding: 0 12px;
}

.login-hint {
    margin: 10px 0 0;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.btn-wxwork {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: 8px;
    background: #07c160;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s;
}

.btn-wxwork:hover {
    background: #06ad56;
    color: #ffffff;
}

/* ---- Form ---- */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
}

.form-group input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="radio"]):not([type="checkbox"]) {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--color-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

.form-group input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="radio"]):not([type="checkbox"]):focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-group textarea {
    width: 100%;
    padding: 12px;
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    line-height: 1.5;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--color-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-datetime {
    display: flex;
    gap: 8px;
}

.form-datetime input {
    flex: 1;
    min-width: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

.btn-primary:hover {
    background: var(--color-primary-hover);
    color: #fff;
}

.btn-secondary {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-success {
    background: #16a34a;
    color: #fff;
}

.btn-success:hover {
    background: #15803d;
    color: #fff;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
    color: #fff;
}

.btn-block {
    width: 100%;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
}

/* ---- Alert ---- */

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* ---- App Layout ---- */

.app-layout {
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    display: none;
}

.main-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
}

.topbar-user {
    display: none;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.main-content {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-height) + 16px + env(safe-area-inset-bottom, 0px));
}

/* ---- Bottom Nav (Mobile) ---- */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--color-text-muted);
    font-size: 0.6875rem;
    transition: color 0.15s;
}

.bottom-nav-item.active {
    color: var(--color-primary);
}

.bottom-nav-item.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.bottom-nav-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.bottom-nav-label {
    line-height: 1.2;
}

/* ---- Page Content ---- */

.page-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px 16px;
}

.page-heading {
    margin: 0 0 8px;
    font-size: 1.25rem;
    font-weight: 600;
}

.page-desc {
    margin: 0 0 20px;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-item {
    padding: 14px;
    background: var(--color-bg);
    border-radius: 8px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 0.9375rem;
    font-weight: 600;
    word-break: break-all;
}

.placeholder-box {
    padding: 24px 16px;
    text-align: center;
    background: var(--color-bg);
    border-radius: 8px;
    border: 1px dashed var(--color-border);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.placeholder-box p {
    margin: 0;
}

/* ---- Desktop (>= 768px) ---- */

@media (min-width: 768px) {
    .app-layout {
        display: flex;
    }

    .sidebar {
        display: flex;
        flex-direction: column;
        width: 220px;
        min-height: 100vh;
        background: var(--color-sidebar);
        color: #e2e8f0;
        flex-shrink: 0;
    }

    .sidebar-brand {
        padding: 20px 16px;
        font-size: 1.125rem;
        font-weight: 700;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .sidebar-nav {
        flex: 1;
        padding: 12px 0;
    }

    .sidebar-nav a {
        display: block;
        padding: 10px 16px;
        color: #94a3b8;
        font-size: 0.9375rem;
        transition: background 0.15s, color 0.15s;
    }

    .sidebar-nav a:hover {
        background: rgba(255, 255, 255, 0.06);
        color: #e2e8f0;
    }

    .sidebar-nav a.active {
        background: rgba(37, 99, 235, 0.2);
        color: #fff;
        border-right: 3px solid var(--color-primary);
    }

    .sidebar-nav a.disabled {
        opacity: 0.45;
        pointer-events: none;
    }

    .sidebar-footer {
        padding: 16px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        font-size: 0.8125rem;
    }

    .sidebar-footer .user-name {
        display: block;
        margin-bottom: 6px;
        color: #e2e8f0;
        font-weight: 500;
    }

    .sidebar-footer .logout-link {
        color: #94a3b8;
        font-size: 0.8125rem;
    }

    .sidebar-footer .logout-link:hover {
        color: #fff;
    }

    .main-wrapper {
        flex: 1;
        min-width: 0;
    }

    .topbar-user {
        display: flex;
    }

    .main-content {
        padding: 24px;
        padding-bottom: 24px;
    }

    .bottom-nav {
        display: none;
    }

    .page-card {
        padding: 28px 24px;
    }

    .login-card {
        padding: 40px 32px;
    }
}

@media (min-width: 1024px) {
    .main-content {
        padding: 32px;
    }
}

/* ---- Leads ---- */

.page-toolbar {
    margin-bottom: 16px;
}

.page-toolbar .page-heading {
    margin: 8px 0 0;
}

.page-tabs {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    border-bottom: 1px solid var(--color-border);
}

.page-tab {
    display: inline-block;
    padding: 8px 4px;
    margin-bottom: -1px;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.page-tab:hover {
    color: var(--color-primary);
}

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

.back-link {
    display: inline-block;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.back-link:hover {
    color: var(--color-primary-hover);
}

.search-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px;
    margin-bottom: 16px;
}

.search-form .search-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.form-select,
.form-textarea {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--color-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-select {
    height: 44px;
    padding: 0 12px;
}

.form-textarea {
    padding: 12px;
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    line-height: 1.5;
}

.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
}

.form-radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.95rem;
}

.form-radio input {
    width: auto;
    margin: 0;
    accent-color: var(--color-primary);
}

.form-hint {
    margin: 0 0 16px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.section-title {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 600;
}

.lead-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.lead-card {
    display: block;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px;
    color: inherit;
    transition: transform 0.15s, box-shadow 0.15s;
}

.lead-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 28px rgba(15, 23, 42, 0.12);
    color: inherit;
}

.lead-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.lead-name {
    font-size: 1rem;
    font-weight: 600;
}

.lead-card-phone {
    font-size: 0.9375rem;
    color: var(--color-text-muted);
    margin-bottom: 10px;
}

.lead-card-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.lead-card-source {
    margin-top: 8px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.level-badge-a {
    background: #dcfce7;
    color: #166534;
}

.level-badge-b {
    background: #dbeafe;
    color: #1e40af;
}

.level-badge-c {
    background: #f1f5f9;
    color: #64748b;
}

.level-badge-none {
    background: #c8c8c8;
    color: #ffffff;
}

.lead-detail-card {
    margin-bottom: 16px;
}

.lead-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.lead-detail-name {
    margin: 0 0 4px;
    font-size: 1.25rem;
    font-weight: 600;
}

.lead-detail-phone {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9375rem;
    color: var(--color-text-muted);
}

.lead-detail-phone-link {
    color: var(--color-primary);
}

.lead-detail-phone-link:hover {
    color: var(--color-primary-hover);
}

.lead-detail-phone-text {
    color: inherit;
}

.btn-copy-phone {
    flex-shrink: 0;
    padding: 2px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    line-height: 1.5;
    cursor: pointer;
}

.btn-copy-phone:hover {
    color: var(--color-text);
    border-color: #cbd5e1;
}

.btn-copy-phone.is-copied {
    color: #166534;
    border-color: #86efac;
    background: #f0fdf4;
}

.detail-list {
    margin: 0;
}

.detail-item {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 8px;
    padding: 10px 0;
    border-top: 1px solid var(--color-border);
}

.detail-item dt {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.detail-item dd {
    margin: 0;
    font-size: 0.9375rem;
    word-break: break-word;
}

.detail-actions {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.detail-action-form {
    margin: 0;
}

.lead-detail-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.badge-deal {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.follow-form {
    margin-top: 4px;
}

.quick-phrases {
    margin-bottom: 16px;
}

.quick-phrases-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.quick-phrases-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-phrase-btn {
    padding: 6px 12px;
    min-height: 36px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.8125rem;
    line-height: 1.4;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.quick-phrase-btn:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.quick-phrase-btn:active {
    background: #f1f5f9;
}

.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline-item {
    position: relative;
    padding: 0 0 20px 16px;
    border-left: 2px solid var(--color-border);
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item::before {
    content: "";
    position: absolute;
    left: -5px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
}

.timeline-item-log::before {
    background: #94a3b8;
}

.timeline-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.timeline-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.timeline-content {
    font-size: 0.875rem;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
}

.transfer-summary p {
    margin: 0 0 8px;
    font-size: 0.9375rem;
}

.empty-state,
.empty-text {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.empty-state p {
    margin: 0 0 16px;
}

.pagination {
    margin-top: 8px;
}

.pagination ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
    justify-content: center;
}

.pagination li {
    display: inline-flex;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 0.875rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
}

.pagination .active span {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.home-action {
    margin-top: 8px;
}

.home-action .btn {
    width: 100%;
    margin-bottom: 8px;
    margin-right: 8px;
}

@media (min-width: 768px) {
    .lead-card-meta {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 16px;
    }

    .search-form {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0 16px;
    }

    .search-form .search-actions {
        grid-column: 1 / -1;
    }

    .home-action .btn {
        width: auto;
    }
}

.public-pool-index .public-pool-fetch-form {
    margin-top: 24px;
}

.public-pool-index .btn-lg {
    padding: 14px 20px;
    font-size: 1rem;
}

.public-pool-mark-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.public-pool-mark-actions form {
    display: block;
    flex: 1;
    min-width: 90px;
    margin-right: 10px;
}

.public-pool-mark-actions .btn {
    width: 100%;
}
