/* TelinkHome — 对标 ESPHome Device Builder 皮肤 */

/* ── 浅色主题 (默认) ── */
:root, [data-theme="light"] {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --header-bg: #1565c0;
    --header-text: #ffffff;
    --text: #212121;
    --text-dim: #757575;
    --accent: #1976d2;
    --accent-hover: #1565c0;
    --border: #e0e0e0;
    --green: #43a047;
    --red: #e53935;
    --orange: #ef6c00;
    --badge-offline: #e91e63;
    --badge-online: #43a047;
    --shadow: 0 1px 3px rgba(0,0,0,.12);
    --radius: 8px;
}

/* ── 深色主题 ── */
[data-theme="dark"] {
    --bg: #121212;
    --surface: #1e1e1e;
    --header-bg: #0d47a1;
    --header-text: #e0e0e0;
    --text: #e0e0e0;
    --text-dim: #9e9e9e;
    --accent: #42a5f5;
    --accent-hover: #64b5f6;
    --border: #333333;
    --green: #66bb6a;
    --red: #ef5350;
    --orange: #ff9800;
    --badge-offline: #f06292;
    --badge-online: #66bb6a;
    --shadow: 0 2px 8px rgba(0,0,0,.4);
}

* { margin:0; padding:0; box-sizing:border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg); color: var(--text); min-height: 100vh;
}

/* ── Header (蓝色顶栏) ── */
.header {
    background: var(--header-bg); color: var(--header-text);
    height: 48px; display: flex; align-items: center; padding: 0 16px;
    position: sticky; top:0; z-index: 50; box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.header-brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; text-decoration: none; color: inherit; }
.header-brand svg { width: 22px; height: 22px; fill: #ffca28; }
.header-right { margin-left: auto; display: flex; gap: 8px; }

/* ── Container ── */
.container { max-width: 960px; margin: 0 auto; padding: 20px 16px; }

/* ── Search ── */
.search-bar {
    display: flex; align-items: center; background: var(--surface);
    border: 1px solid var(--border); border-radius: 20px; padding: 8px 16px;
    margin-bottom: 16px; box-shadow: var(--shadow);
}
.search-bar svg { width: 18px; height: 18px; fill: var(--text-dim); margin-right: 8px; flex-shrink: 0; }
.search-bar input {
    flex:1; border: none; background: transparent; color: var(--text);
    font-size: 14px; outline: none;
}
.search-bar input::placeholder { color: var(--text-dim); }

/* ── Filter Chips ── */
.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-chip {
    padding: 4px 14px; border-radius: 16px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-dim); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all .15s; letter-spacing: .3px;
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-count { margin-left: auto; align-self: center; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.file-time { color: var(--text-dim); font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── Card Grid ── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.device-card {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; display: flex; flex-direction: column; transition: box-shadow .15s;
}
.device-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; min-width: 0; }
.card-title {
    font-size: 17px; font-weight: 600; line-height: 1.3; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-file { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; opacity: 0.75; }
.card-status {
    display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600;
    padding: 2px 8px; border-radius: 10px; white-space: nowrap;
}
.status-built { background: rgba(67,160,71,.12); color: var(--green); }
.status-none  { background: rgba(233,30,99,.12); color: var(--badge-offline); }
.card-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 12px; align-items: center; }
.card-badges { display: inline-flex; gap: 4px; margin-left: auto; align-items: center; }
.badge {
    font-size: 10px; font-weight: 700; letter-spacing: .4px; padding: 2px 7px;
    border-radius: 9px; white-space: nowrap; line-height: 1.4;
}
.badge-tys { background: rgba(25,118,210,.14); color: var(--accent); }
.badge-standard { background: rgba(67,160,71,.14); color: var(--green); }
.badge-tlc { background: rgba(239,108,0,.14); color: var(--orange); }
.badge-dt { background: rgba(117,117,117,.14); color: var(--text-dim); }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    padding: 8px 14px; border: none; border-radius: 18px; font-size: 12px;
    font-weight: 600; cursor: pointer; text-decoration: none; transition: all .15s;
    letter-spacing: .3px; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: rgba(25,118,210,.08); }
.btn-text { background: transparent; color: var(--text-dim); padding: 8px 10px; }
.btn-text:hover { background: rgba(0,0,0,.06); color: var(--text); }
.btn-icon { padding: 6px; border-radius: 50%; min-width: 32px; min-height: 32px; }

/* ── Header icon buttons: 白底 + 彩色图标，避免和蓝色 header 背景混在一起看不清 ── */
.header .btn-icon { background: #fff; color: var(--accent) !important; }
.header .btn-icon:hover { background: rgba(255,255,255,.85); }
.header .btn-icon svg { fill: var(--accent); }
.header .btn-icon.icon-flash svg { fill: #ff8f00; }
.header .lang-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; min-height: 32px; padding: 0 10px; border-radius: 16px;
    background: #fff; color: var(--accent); font-size: 12px; font-weight: 700;
    cursor: pointer; border: none; letter-spacing: .3px;
}
.header .lang-toggle:hover { background: rgba(255,255,255,.85); }

/* ── FAB ── */
.fab {
    position: fixed; bottom: 24px; right: 24px; z-index: 60;
    background: var(--accent); color: #fff; border: none; border-radius: 24px;
    padding: 12px 20px; font-size: 14px; font-weight: 600;
    box-shadow: 0 4px 12px rgba(25,118,210,.4); cursor: pointer;
    display: flex; align-items: center; gap: 6px; transition: all .2s;
}
.fab:hover { background: var(--accent-hover); box-shadow: 0 6px 16px rgba(25,118,210,.5); }
.fab svg { width: 20px; height: 20px; fill: #fff; }

/* ── Dropdown menu ── */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right:0; top: 100%; margin-top: 4px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 180px; z-index: 100; display: none;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 13px;
    color: var(--text); cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.dropdown-item:hover { background: rgba(0,0,0,.05); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Editor ── */
.editor-toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.yaml-editor {
    width: 100%; min-height: 440px; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
    font-family: "Cascadia Code","Fira Code","Consolas",monospace;
    font-size: 13px; line-height: 1.6; resize: vertical;
}
.yaml-editor:focus { outline: none; border-color: var(--accent); }

/* ── CodeMirror（YAML 编辑器：行号 + 语法高亮） ── */
.CodeMirror {
    height: auto; min-height: 440px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font-family: "Cascadia Code","Fira Code","Consolas",monospace;
    font-size: 13px; line-height: 1.6;
}
.CodeMirror-focused { border-color: var(--accent); }
.CodeMirror-gutters { background: var(--surface); border-right: 1px solid var(--border); }
.CodeMirror-linenumber { color: var(--text-dim); }
.CodeMirror-cursor { border-left-color: var(--text); }
.cm-s-tlh .cm-comment { color: var(--text-dim); }
.cm-s-tlh .cm-atom { color: var(--accent); }
.cm-s-tlh .cm-string { color: #2e7d32; }
.cm-s-tlh .cm-number { color: #ef6c00; }
.cm-s-tlh .cm-meta { color: #8e24aa; }
[data-theme="dark"] .cm-s-tlh .cm-string { color: #81c784; }
[data-theme="dark"] .cm-s-tlh .cm-number { color: #ffb74d; }
[data-theme="dark"] .cm-s-tlh .cm-meta { color: #ce93d8; }

/* Delete button */
.btn-delete { color: var(--red); padding: 8px 6px; }
.btn-delete:hover { background: rgba(229,57,53,.1); }

/* ── Log ── */
.log-view, .modal-log {
    background: #1e1e1e; color: #d4d4d4; border-radius: var(--radius);
    padding: 14px; min-height: 300px; max-height: 500px; overflow-y: auto;
    font-family: "Cascadia Code","Fira Code","Consolas",monospace;
    font-size: 12px; line-height: 1.5; white-space: pre-wrap;
    border: 1px solid var(--border);
}

/* ── Footer ── */
.footer { text-align: center; padding: 16px; font-size: 12px; color: var(--text-dim); }

/* ── Modal ── */
.modal-overlay { position: fixed; inset:0; background: rgba(0,0,0,.5); display:flex; align-items:center; justify-content:center; z-index:200; }
.modal-overlay[hidden] { display: none; }
.modal-box { background: var(--surface); border-radius: 12px; padding: 20px; width: 90%; max-width: 680px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-log { flex: 1; min-height: 200px; overflow-y: auto; background: #1a1a1a; border-radius: var(--radius); padding:12px; margin:12px 0; }

/* ── Select (theme/lang) ── */
.selector { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 13px; }

@media (max-width: 600px) {
    .container { padding: 10px; }
    .card-grid { grid-template-columns: 1fr; }
    .fab { bottom: 12px; right: 12px; }
}

/* ── Toast 轻提示 ── */
.tlh-toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-8px);
    background: var(--green); color: #fff; padding: 8px 20px; border-radius: 8px;
    font-size: 13px; font-weight: 600; z-index: 9999;
    opacity: 0; transition: opacity .25s, transform .25s;
    box-shadow: 0 4px 16px rgba(0,0,0,.25); pointer-events: none;
}
.tlh-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
