/* ESP32 应用社区 · 参考 pockigo.com/apps 的浅色青绿风
   无构建、无外网依赖：字体走系统栈，图标用 emoji/SVG 内联 */

:root {
    --teal: #00c2a8;
    --teal-dark: #00a58f;
    --teal-soft: #e6fbf6;
    --ink: #17212b;
    --ink-2: #3d4a5c;
    --muted: #8b95a5;
    --line: #e9eef3;
    --bg: #f5f8fa;
    --card: #ffffff;
    --danger: #f5483b;
    --warn: #ff9f1a;
    --radius: 16px;
    --shadow: 0 1px 2px rgba(23, 33, 43, .04), 0 8px 24px rgba(23, 33, 43, .05);
}

* { box-sizing: border-box; }

/* hidden 属性必须真的隐藏：.user/.modal 这些类自带 display，会盖掉浏览器默认的 [hidden] */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

code, .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.w160 { width: 160px; }
.grow { flex: 1; min-width: 0; }

/* ---------------- 顶栏 ---------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 24px;
    height: 64px;
    padding: 0 24px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--ink);
    font-weight: 800;
    font-size: 18px;
    letter-spacing: -.2px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--teal);
    color: #fff;
    font-size: 16px;
}

.brand-name b { color: var(--teal); font-weight: 800; }

.brand-sub {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--teal-soft);
    color: var(--teal-dark);
    font-size: 11px;
    font-weight: 600;
}

.topnav { display: flex; gap: 6px; }

.nav-btn {
    border: 0;
    background: transparent;
    color: var(--ink-2);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 14px;
    cursor: pointer;
}

.nav-btn:hover { background: #f1f5f8; }

.nav-btn.active {
    background: var(--teal-soft);
    color: var(--teal-dark);
    font-weight: 600;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink-2);
    font-size: 13px;
    cursor: pointer;
}

.chip:hover { border-color: #d7e0e8; }

.chip.ghost { background: #f8fafb; }

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cfd8e3;
}

.dot.on { background: var(--teal); box-shadow: 0 0 0 3px rgba(0, 194, 168, .18); }

.gitee-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: #c71d23;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.gitee-btn:hover { filter: brightness(1.06); }

.user { display: flex; align-items: center; gap: 8px; }

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    background: #e8eef3;
}

.uname { font-size: 13px; color: var(--ink-2); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.link-btn {
    border: 0;
    background: transparent;
    color: var(--teal-dark);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
}

/* ---------------- 三栏布局 ---------------- */

.layout {
    display: grid;
    grid-template-columns: 224px minmax(0, 1fr) 328px;
    gap: 20px;
    max-width: 1560px;
    margin: 0 auto;
    padding: 20px 24px 48px;
    align-items: start;
}

.side-card, .panel-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.side-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: .4px;
    margin: 2px 6px 10px;
}

.side-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 9px 10px;
    margin-bottom: 2px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ink-2);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}

.side-item:hover { background: #f5f8fa; }

.side-item.active { background: var(--teal-soft); color: var(--teal-dark); font-weight: 600; }

.side-item b {
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
    background: #f1f5f8;
    color: var(--muted);
}

.side-item.active b { background: #fff; color: var(--teal-dark); }

.device-state {
    font-size: 13px;
    font-weight: 600;
    margin: 0 6px 4px;
}

.device-meta { font-size: 12px; color: var(--muted); margin: 0 6px 10px; min-height: 16px; word-break: break-all; }

.tip { text-align: center; padding: 18px 14px; }

.tip-emoji { font-size: 28px; }
.tip-title { font-weight: 700; margin-top: 6px; }
.tip-text { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.6; }

/* ---------------- 应用卡片区 ---------------- */

.content { min-width: 0; }

.content-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.content-title { font-size: 20px; font-weight: 800; letter-spacing: -.2px; }

.content-tools { display: flex; gap: 10px; align-items: center; }

.search {
    width: 260px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    font-size: 13px;
    outline: none;
}

.search:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 194, 168, .12); }

.select {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink-2);
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.select.sm { height: 30px; font-size: 12px; }

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

.app-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}

.app-card:hover {
    transform: translateY(-2px);
    border-color: #dbe4ec;
    box-shadow: 0 10px 28px rgba(23, 33, 43, .09);
}

.app-card.picked { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 194, 168, .12); }

.app-top { display: flex; gap: 12px; align-items: flex-start; }

.app-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: #f1f5f8;
    object-fit: cover;
    flex: none;
    image-rendering: auto;
}

.app-head { min-width: 0; flex: 1; }

.app-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.app-desc {
    font-size: 12px;
    color: var(--ink-2);
    line-height: 1.6;
    min-height: 38px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-top: 1px dashed var(--line);
    padding-top: 10px;
}

.app-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }

.fav-btn {
    border: 0;
    background: transparent;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    color: #c3ccd7;
}

.fav-btn:hover { background: #f5f8fa; }
.fav-btn.on { color: #ffb020; }

.install-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 32px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--teal);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.install-btn:hover { background: var(--teal-dark); }

.install-btn.added { background: var(--teal-soft); color: var(--teal-dark); }

.order-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--teal);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--muted);
}

.empty-emoji { font-size: 36px; }
.empty-title { font-size: 15px; font-weight: 700; color: var(--ink-2); margin-top: 8px; }
.empty-text { font-size: 12px; margin-top: 6px; }

/* ---------------- 右侧面板 ---------------- */

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
}

.sel-list {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
    max-height: 220px;
    overflow: auto;
}

.sel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: 10px;
    font-size: 13px;
}

.sel-item:hover { background: #f5f8fa; }

.sel-idx {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--teal-soft);
    color: var(--teal-dark);
    font-size: 11px;
    font-weight: 700;
    flex: none;
}

.sel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sel-del {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
}

.sel-del:hover { color: var(--danger); }

.sel-empty { font-size: 12px; color: var(--muted); padding: 10px 4px; }

.cap-bar {
    height: 8px;
    border-radius: 999px;
    background: #eef2f6;
    overflow: hidden;
}

.cap-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #00d6b8, #00b79d);
    transition: width .2s ease;
}

.cap-fill.overflow { background: linear-gradient(90deg, #ff7a6b, #f5483b); }

.cap-text { font-size: 12px; color: var(--muted); margin-top: 6px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.log {
    margin: 0;
    height: 160px;
    overflow: auto;
    padding: 10px;
    border-radius: 10px;
    background: #0f1720;
    color: #c8e6e0;
    font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-all;
}

.log.tall { height: 320px; margin-top: 10px; }

/* ---------------- 按钮 ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink-2);
    font-size: 13px;
    cursor: pointer;
}

.btn:hover { border-color: #d7e0e8; background: #fafcfd; }
.btn.block { width: 100%; }
.btn.primary { border: 0; background: var(--teal); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.ghost { background: #f8fafb; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.icon-btn {
    border: 0;
    background: transparent;
    font-size: 16px;
    color: var(--muted);
    cursor: pointer;
}

/* ---------------- 弹窗 ---------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 32, .42);
    backdrop-filter: blur(2px);
}

.modal[hidden] { display: none; }

.modal-card {
    width: 520px;
    max-width: 100%;
    max-height: 90vh;
    overflow: auto;
    background: var(--card);
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 32, .24);
}

.modal-card.wide { width: 760px; }

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }

.tab {
    border: 0;
    background: #f5f8fa;
    color: var(--ink-2);
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
}

.tab.active { background: var(--teal-soft); color: var(--teal-dark); font-weight: 600; }

.dropzone {
    display: grid;
    place-items: center;
    gap: 6px;
    min-height: 120px;
    border: 1.5px dashed #d7e0e8;
    border-radius: 14px;
    background: #fafcfd;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    padding: 16px;
}

.dropzone:hover, .dropzone.drag { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }

.text-input {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    font-size: 13px;
    outline: none;
}

.text-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 194, 168, .12); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 8px 0 0; }

/* ---------------- 提示 ---------------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%) translateY(10px);
    padding: 10px 18px;
    border-radius: 999px;
    background: #17212b;
    color: #fff;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    z-index: 80;
    max-width: 80vw;
}

.toast.show { opacity: .96; transform: translateX(-50%) translateY(0); }
.toast.err { background: #d92d20; }
.toast.ok { background: #047857; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1280px) {
    .layout { grid-template-columns: 200px minmax(0, 1fr); }
    .panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
    .panel .panel-card { margin: 0; }
}

@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; padding: 14px; }
    .sidebar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
    .sidebar .tip { display: none; }
    .panel { grid-template-columns: 1fr; }
    .topbar { gap: 10px; padding: 0 14px; }
    .topnav { display: none; }
    .search { width: 100%; }
    .content-tools { width: 100%; }
}
