/* style.css - Material Design 3 风格 + 抽屉式布局 + 动态主题 */
:root {
    --md-sys-color-primary: #6750A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #EADDFF;
    --md-sys-color-on-primary-container: #21005D;
    --md-sys-color-secondary-container: #E8DEF8;
    --md-sys-color-on-secondary-container: #1D192B;
    --md-sys-color-error: #B3261E;
    --md-sys-color-error-container: #F9DEDC;
    --md-sys-color-success: #1E6E34;
    --md-sys-color-surface: #FEF7FF;
    --md-sys-color-surface-variant: #E7E0EC;
    --md-sys-color-surface-container: #F3EDF7;
    --md-sys-color-surface-container-high: #ECE6F0;
    --md-sys-color-on-surface: #1D1B20;
    --md-sys-color-outline: #79747E;
    --drawer-w: 280px;
    --appbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Roboto", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    background: #F5F2FA;
    color: var(--md-sys-color-on-surface);
    -webkit-tap-highlight-color: transparent;
}

a { text-decoration: none; color: inherit; }

/* ============ 顶栏 ============ */
.top-app-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--appbar-h);
    background: var(--md-sys-color-surface);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    z-index: 30;
}
.appbar-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.icon-btn {
    border: none;
    background: transparent;
    width: 44px; height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    transition: background .2s;
    flex-shrink: 0;
}
.icon-btn:hover { background: rgba(0,0,0,0.06); }

/* ============ 抽屉 ============ */
.drawer {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--drawer-w);
    background: var(--md-sys-color-surface);
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 16px rgba(0,0,0,0.18);
    border-top-right-radius: 16px;
    border-bottom-right-radius: 16px;
}
.drawer.open { transform: translateX(0); }

.drawer-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 24px 12px;
    font-size: 18px;
    font-weight: 700;
    color: var(--md-sys-color-primary);
}
.drawer-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px 20px;
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
}
.avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
    text-transform: uppercase;
}
.drawer-user-meta b { display: block; font-size: 15px; }
.drawer-user-meta small { color: var(--md-sys-color-outline); font-size: 12px; }

.drawer-nav { padding: 12px; flex: 1; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    height: 52px;
    border-radius: 26px;
    color: var(--md-sys-color-on-surface);
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 4px;
    transition: background .2s;
}
.nav-item:hover { background: var(--md-sys-color-surface-container-high); }
.nav-item.active {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}
.nav-item.nav-danger { color: var(--md-sys-color-error); }
.nav-sep { height: 1px; background: var(--md-sys-color-surface-variant); margin: 12px 16px; }

.scrim {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity .28s;
}
.scrim.show { opacity: 1; visibility: visible; }

/* ============ 内容容器 ============ */
.content {
    margin-top: var(--appbar-h);
    padding: 24px;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

/* 大屏：抽屉常驻，内容右移 */
@media (min-width: 1024px) {
    .drawer { transform: translateX(0); box-shadow: none; border-right: 1px solid var(--md-sys-color-surface-variant); }
    .scrim { display: none !important; }
    .top-app-bar { left: var(--drawer-w); }
    .content { margin-left: calc(var(--drawer-w) + 24px); margin-right: 24px; }
    #menuBtn { display: none; }
}

/* ============ 卡片 ============ */
.card {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 20px;
}
.card-interactive { cursor: pointer; transition: transform .2s, box-shadow .2s; }
.card-interactive:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.12); }
.card-title { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; font-size: 17px; color: var(--md-sys-color-primary); }
.card-title svg { flex-shrink: 0; }
.card-sub { font-size: 13px; color: var(--md-sys-color-outline); margin: 4px 0 16px; }

h1,h2,h3,h4 { color: var(--md-sys-color-on-surface); }
.headline-large { font-size: 22px; font-weight: 600; margin: 0; }

.row-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; }
.page-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }

/* 项目卡片网格 */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.proj-name { margin: 0 0 8px; font-size: 18px; color: var(--md-sys-color-on-surface); }
.proj-pid { color: var(--md-sys-color-outline); font-family: monospace; }
.empty-state { grid-column: 1/-1; text-align: center; padding: 60px 0; color: var(--md-sys-color-outline); }
.empty-state svg { opacity: .4; }

/* ============ 按钮 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 24px;
    padding: 0 24px;
    height: 44px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, box-shadow .2s, opacity .2s, filter .2s;
    font-family: inherit;
}
.btn svg { flex-shrink: 0; }
.btn-filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.btn-filled:hover { filter: brightness(1.08); box-shadow: 0 2px 8px rgba(0,0,0,0.18); }
.btn-tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.btn-tonal:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.12); }
.btn-text { background: transparent; color: var(--md-sys-color-primary); padding: 0 12px; }
.btn-text:hover { background: rgba(0,0,0,0.05); }
.btn-danger { color: var(--md-sys-color-error) !important; }
.btn-danger-filled { background: var(--md-sys-color-error); color: #fff; }
.btn-danger-filled:hover { filter: brightness(1.08); }
.btn-block { width: 100%; }

/* 表单一行排版 */
.form-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; margin-bottom: 8px; }
.form-row .input-group { flex: 1 1 180px; margin-bottom: 0; }
.form-row .input-grow { flex: 2 1 260px; }
.form-row .btn { height: 56px; }

/* ============ 输入框（浮动标签） ============ */
.input-group { position: relative; margin-bottom: 24px; }
.md-input {
    width: 100%;
    height: 56px;
    padding: 18px 16px 0;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    font-size: 16px;
    background: #fff;
    outline: none;
    transition: border-color .2s;
    font-family: inherit;
    color: var(--md-sys-color-on-surface);
}
select.md-input { padding-top: 0; }
.md-input:focus { border-color: var(--md-sys-color-primary); border-width: 2px; }
.md-label {
    position: absolute;
    left: 16px;
    top: 18px;
    color: var(--md-sys-color-outline);
    font-size: 16px;
    pointer-events: none;
    transition: all .15s ease;
    background: #fff;
    padding: 0 4px;
}
.md-input:focus + .md-label,
.md-input:not(:placeholder-shown) + .md-label,
.md-label-fixed {
    top: -8px;
    font-size: 12px;
    color: var(--md-sys-color-primary);
}

/* ============ 表格 ============ */
.table-wrapper {
    background: #fff;
    border-radius: 16px;
    overflow-x: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 4px;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--md-sys-color-surface-variant); }
th { background: var(--md-sys-color-surface-container); font-weight: 600; color: var(--md-sys-color-on-surface); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.code-inline { background: var(--md-sys-color-surface-container-high); padding: 4px 8px; border-radius: 4px; font-weight: 600; color: var(--md-sys-color-primary); font-family: monospace; }

/* ============ 标签片 ============ */
.chip { display: inline-block; padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.chip-green { background: #E6F4EA; color: #1E6E34; }
.chip-red { background: #FCE8E6; color: #B3261E; }
.chip-gray { background: #EEE; color: #666; }

/* ============ FAB ============ */
.fab {
    position: fixed;
    right: 24px; bottom: 24px;
    width: 56px; height: 56px;
    border-radius: 18px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    cursor: pointer;
    z-index: 25;
}
.fab-extended { width: auto; padding: 0 20px; gap: 8px; font-size: 14px; font-weight: 600; }

/* ============ 模态框 ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 60;
    padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff;
    border-radius: 24px;
    padding: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
}
.modal-title { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

/* ============ 提示条 ============ */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.alert-ok, .alert-success { background: #E6F4EA; color: #1E6E34; border: 1px solid #34A853; font-family: monospace; font-weight: 600; }
.alert-err, .alert-error { background: #FCE8E6; color: var(--md-sys-color-error); }

/* ============ 主题选择 ============ */
.theme-swatches { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.theme-dot {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--md-sys-color-outline);
    cursor: pointer;
    padding: 0;
    flex: 0 0 auto;
    transition: transform .15s;
}
.theme-dot:hover { transform: scale(1.12); }
/* 画布取色区：宽度占满父容器，高度固定。
   关键：max-width:100% + display:block 防止 canvas 位图宽度撑破弹窗导致移动端溢出。 */
.theme-canvas-wrap { width: 100%; flex: 1 1 100%; margin-top: 4px; }
#themeCanvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 140px;
    border-radius: 12px;
    cursor: crosshair;
    touch-action: none;
    border: 1px solid var(--md-sys-color-surface-variant);
}
.theme-custom { margin-top: 16px; }
.theme-custom-label { font-size: 13px; color: var(--md-sys-color-outline); }
.theme-custom-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.theme-picker { width: 48px; height: 44px; border: none; background: none; cursor: pointer; padding: 0; flex: 0 0 auto; }
.theme-hex { font-family: monospace; font-size: 15px; font-weight: 600; flex: 1 1 80px; min-width: 80px; }

/* 登录/注册页 */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head svg { color: var(--md-sys-color-primary); }
.auth-head h2 { margin: 8px 0 4px; color: var(--md-sys-color-primary); }
.auth-head p { margin: 0; color: var(--md-sys-color-outline); font-size: 14px; }

/* 分页 */
.pager { padding: 16px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; border-top: 1px solid var(--md-sys-color-surface-variant); }
.pager-info { color: var(--md-sys-color-outline); font-size: 14px; }

/* ============ 动画 ============ */
.fade-in-up { animation: fadeInUp .35s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.hide-mobile { }
@media (max-width: 720px) {
    .hide-mobile { display: none; }
    .content { padding: 16px; }
    .form-row .btn { width: 100%; }
    .modal { padding: 20px; }
}
