:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel-soft: #f9fafc;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
    --radius: 8px;
    --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    letter-spacing: 0;
}

a { color: inherit; }

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(360px, 480px) 1fr;
    background:
        linear-gradient(120deg, rgba(37, 99, 235, .10), transparent 38%),
        linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
}

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    background: #fff;
    border-right: 1px solid var(--line);
}

.auth-card { width: 100%; max-width: 360px; }

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 26px;
    font-size: 20px;
    font-weight: 700;
}

.auth-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: var(--brand);
    color: #fff;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
    line-height: 1.2;
}

.auth-card p {
    margin: 0 0 28px;
    color: var(--muted);
}

.auth-side {
    display: flex;
    align-items: center;
    padding: 64px;
}

.auth-copy { max-width: 620px; }

.auth-copy h2 {
    margin: 0 0 18px;
    font-size: 42px;
    line-height: 1.15;
}

.auth-copy p {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.8;
}

.hint-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 34px;
}

.hint-item {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .74);
}

.hint-item strong { display: block; margin-bottom: 6px; }
.hint-item span { color: var(--muted); font-size: 13px; }

.gm-shell {
    height: 100vh;
    display: grid;
    grid-template-columns: 232px 1fr;
    background: var(--bg);
}

.gm-sidebar {
    background: #111827;
    color: #d1d5db;
    display: flex;
    flex-direction: column;
}

.gm-logo {
    height: 64px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    color: #fff;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.gm-logo-mark {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: var(--brand);
}

.gm-nav {
    padding: 14px 12px;
    flex: 1;
}

.gm-nav-section {
    margin: 16px 8px 8px;
    color: #9ca3af;
    font-size: 12px;
}

.gm-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: var(--radius);
    color: #d1d5db;
    text-decoration: none;
}

.gm-nav a:hover,
.gm-nav a.is-active {
    background: rgba(37, 99, 235, .18);
    color: #fff;
}

.gm-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.gm-topbar {
    height: 64px;
    padding: 0 22px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.gm-topbar h1 {
    margin: 0;
    font-size: 18px;
}

.gm-user {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.gm-frame {
    width: 100%;
    height: calc(100vh - 64px);
    border: 0;
}

.page {
    padding: 22px;
}

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

.page-title h1,
.page-title h2 {
    margin: 0 0 6px;
    font-size: 24px;
    line-height: 1.25;
}

.page-title p {
    margin: 0;
    color: var(--muted);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel-header {
    min-height: 58px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-body { padding: 16px; }

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

.toolbar .layui-form { display: flex; gap: 10px; flex-wrap: wrap; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(140px, 1fr));
    gap: 14px;
}

.stat-card {
    padding: 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.stat-label {
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    margin-top: 10px;
    font-size: 28px;
    font-weight: 760;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
    gap: 14px;
    margin-top: 14px;
}

.list-line {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.list-line:last-child { border-bottom: 0; }
.list-line strong { display: block; }
.list-line span { color: var(--muted); font-size: 13px; }

.status-pill {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.status-ok { color: #166534; background: #dcfce7; }
.status-warn { color: #92400e; background: #fef3c7; }
.status-off { color: #6b7280; background: #f3f4f6; }
.status-bad { color: #991b1b; background: #fee2e2; }

.form-card {
    max-width: 760px;
}

.form-actions {
    padding-top: 8px;
    display: flex;
    gap: 10px;
}

.empty-state {
    padding: 42px 18px;
    text-align: center;
    color: var(--muted);
}

.portal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 22px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.portal-header h1 {
    margin: 0;
    font-size: 20px;
}

.gmail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.gmail-card {
    padding: 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.gmail-card h3 {
    margin: 0 0 12px;
    font-size: 18px;
    word-break: break-all;
}

.meta-line {
    color: var(--muted);
    font-size: 13px;
    margin: 6px 0;
}

@media (max-width: 980px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-side { display: none; }
    .gm-shell { grid-template-columns: 1fr; }
    .gm-sidebar { display: none; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .content-grid { grid-template-columns: 1fr; }
}

/* Customer portal */
.customer-portal {
    min-height: 100vh;
    background: var(--bg);
}

.portal-header--customer,
.portal-header--mail {
    min-height: 72px;
    padding: 0 32px;
}

.portal-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.portal-brand > div {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.portal-brand strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.portal-brand span:not(.portal-mark) {
    color: var(--muted);
    font-size: 12px;
}

.portal-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 11px;
    background: var(--brand);
    color: #fff !important;
    font-size: 16px;
    font-weight: 800;
}

.portal-user,
.mail-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
}

.portal-user-name {
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.portal-logout {
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
}

.portal-logout:hover { color: var(--brand); }
.portal-logout .layui-icon { margin-right: 5px; }

.portal-page { max-width: 1280px; margin: 0 auto; padding-top: 38px; }
.portal-page-header { align-items: center; margin-bottom: 28px; }
.portal-page-header .page-title h1 { font-size: 30px; }
.eyebrow { display: block; margin-bottom: 8px; color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.portal-summary { display: grid; gap: 2px; min-width: 110px; padding: 16px 20px; border: 1px solid #dbe5fb; border-radius: 12px; background: rgba(255,255,255,.82); text-align: center; }
.portal-summary strong { font-size: 28px; line-height: 1; color: var(--brand); }
.portal-summary span { color: var(--muted); font-size: 12px; }

.portal-empty { padding: 72px 20px; text-align: center; }
.portal-empty-icon,
.reader-icon {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    margin: 0 auto 16px;
    border-radius: 16px;
    background: #eaf1ff;
    color: var(--brand);
    font-size: 24px;
}
.portal-empty h2, .mail-reader-empty h2 { margin: 0 0 8px; font-size: 20px; }
.portal-empty p, .mail-reader-empty p { margin: 0; color: var(--muted); }

.portal-mail-card { padding: 20px; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.portal-mail-card:hover { transform: translateY(-2px); border-color: #bfd1f7; box-shadow: 0 14px 34px rgba(37, 99, 235, .12); }
.gmail-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.gmail-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: #eaf1ff; color: var(--brand); font-size: 19px; }
.portal-mail-card h3 { margin-bottom: 6px; font-size: 18px; }
.gmail-alias { min-height: 20px; color: var(--muted); font-size: 13px; }
.gmail-card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0 14px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.gmail-card-meta div { min-width: 0; }
.gmail-card-meta span, .gmail-card-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gmail-card-meta span { margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.gmail-card-meta strong { font-size: 12px; }
.gmail-expiry { min-height: 20px; margin-bottom: 18px; color: var(--muted); font-size: 12px; }
.gmail-card-actions { display: flex; gap: 8px; }
.gmail-card-actions .layui-btn:first-child { flex: 1; }
.gmail-card-actions .layui-btn { margin: 0; }

.portal-back { color: var(--muted); font-size: 20px; text-decoration: none; }
.portal-back:hover { color: var(--brand); }
.portal-header--mail .portal-mark { display: grid; }
.portal-header--mail .portal-mark .layui-icon { font-size: 18px; }
.mail-sync-status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.mail-sync-status i { width: 7px; height: 7px; display: block; border-radius: 50%; background: var(--muted); }
.mail-sync-status.is-loading i { background: var(--amber); animation: portal-pulse 1s infinite; }
.mail-sync-status.is-ready i { background: var(--green); }
.mail-sync-status.is-error i { background: var(--red); }
@keyframes portal-pulse { 50% { opacity: .35; } }

.mail-page { max-width: 1440px; margin: 0 auto; padding-top: 30px; }
.mail-page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.mail-page-heading h1 { margin: 0 0 6px; font-size: 28px; }
.mail-page-heading p { margin: 0; color: var(--muted); }
.mail-search { width: min(330px, 100%); display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mail-search i { color: var(--muted); }
.mail-search input { width: 100%; height: 40px; border: 0; outline: 0; color: var(--text); }
.mail-workspace { display: grid; grid-template-columns: minmax(340px, 430px) minmax(0, 1fr); gap: 16px; align-items: start; }
.mail-list-panel, .mail-reader { min-height: 600px; overflow: hidden; }
.mail-list-header { min-height: 56px; }
.mail-list-header span { color: var(--muted); font-size: 12px; }
.mail-list { max-height: calc(100vh - 250px); overflow: auto; }
.mail-item { padding: 15px 17px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .15s ease; }
.mail-item:hover { background: #f7faff; }
.mail-item.is-selected { background: #eef4ff; box-shadow: inset 3px 0 0 var(--brand); }
.mail-item.is-unread strong { color: var(--brand-strong); }
.mail-item-row { display: flex; align-items: center; gap: 8px; }
.mail-item-row strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.mail-item-row .mail-date { margin-left: auto; flex: 0 0 auto; }
.mail-unread-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: transparent; }
.mail-item.is-unread .mail-unread-dot { background: var(--brand); }
.mail-from, .mail-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-from { margin: 8px 0 4px 15px; color: var(--text); font-size: 12px; }
.mail-preview { margin-left: 15px; color: var(--muted); font-size: 12px; }
.mail-date { color: var(--muted); font-size: 11px; }
.mail-pagination { padding: 12px; text-align: center; }
.mail-state { display: grid; place-items: center; min-height: 330px; padding: 24px; color: var(--muted); text-align: center; }
.mail-state i { margin-bottom: 10px; color: #9db5e9; font-size: 28px; }
.mail-state p { margin: 0; }
.mail-state-error h3 { margin: 0 0 8px; color: var(--text); font-size: 16px; }
.mail-state-error p { max-width: 300px; margin: 0 0 18px; line-height: 1.6; }
.mail-reader { position: relative; }
.mail-reader.is-loading::after { content: "正在读取正文…"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.78); color: var(--muted); }
.mail-reader-empty { display: grid; place-items: center; min-height: 600px; padding: 30px; text-align: center; }
.reader-icon-error { background: #fee2e2; color: var(--red); }
.mail-reader-content { min-height: 600px; }
.reader-head { padding: 24px 26px 18px; border-bottom: 1px solid var(--line); }
.reader-head h2 { margin: 0 0 10px; font-size: 21px; line-height: 1.4; }
.reader-date { color: var(--muted); font-size: 12px; }
.reader-meta { display: flex; align-items: center; gap: 10px; padding: 18px 26px; border-bottom: 1px solid var(--line); }
.reader-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: #eaf1ff; color: var(--brand); font-weight: 800; }
.reader-meta div { display: grid; gap: 3px; }
.reader-meta strong { font-size: 13px; }
.reader-meta span { color: var(--muted); font-size: 11px; }
.reader-body { padding: 26px; color: #374151; font-size: 14px; line-height: 1.8; overflow-wrap: anywhere; }
.mail-empty-body { color: var(--muted); }

@media (max-width: 980px) {
    .portal-header--customer, .portal-header--mail { padding: 0 18px; }
    .portal-user-name, .portal-header--mail .portal-logout { display: none; }
    .portal-page, .mail-page { padding: 24px 16px; }
    .portal-page-header, .mail-page-heading { align-items: flex-start; flex-direction: column; }
    .portal-summary { align-self: stretch; display: flex; align-items: center; justify-content: space-between; }
    .mail-search { width: 100%; }
    .mail-workspace { grid-template-columns: 1fr; }
    .mail-list-panel, .mail-reader, .mail-reader-content { min-height: auto; }
    .mail-list { max-height: 430px; }
    .mail-reader-empty { min-height: 300px; }
}

@media (max-width: 560px) {
    .mail-toolbar { gap: 8px; }
    .mail-sync-status { display: none; }
    .portal-brand strong { max-width: 190px; }
    .gmail-card-meta { grid-template-columns: 1fr; }
}
