:root {
  --bg: #f4f5f7;
  --card: #fff;
  --border: #e8eaed;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #0071e3;
  --accent-hover: #0060c0;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
  --nav-bg: #1d1d1f;
  --nav-text: #f5f5f7;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Helvetica Neue', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }

/* ── Navbar ── */
#app-header { position: sticky; top: 0; z-index: 50; }
.navbar { display: flex; align-items: center; padding: 0 20px; height: 48px; background: var(--nav-bg); color: var(--nav-text); gap: 16px; backdrop-filter: blur(20px); }
.nav-brand { display: flex; align-items: center; gap: 8px; }
.brand-text { color: #fff; font-weight: 600; font-size: 1em; letter-spacing: -.01em; }
.nav-toggle { display: none; background: none; border: none; color: var(--nav-text); font-size: 1.2em; cursor: pointer; padding: 4px 8px; }
.nav-links { display: flex; gap: 2px; flex: 1; }
.nav-link { color: var(--nav-text); padding: 5px 12px; border-radius: 6px; font-size: .82em; opacity: .6; transition: all .15s; }
.nav-link:hover, .nav-link.active { opacity: 1; background: rgba(255,255,255,.1); }
.nav-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-name { font-size: .82em; opacity: .7; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 14px; border: none; border-radius: 8px; background: var(--bg); color: var(--text); font-size: .82em; font-weight: 500; cursor: pointer; transition: all .15s; }
.btn:hover { background: #e8e8ed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .78em; }


/* ── Forms ── */
input, select, textarea { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: .85em; width: 100%; background: var(--card); color: var(--text); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,113,227,.12); }
label { display: block; font-size: .82em; font-weight: 500; margin-bottom: 4px; color: var(--muted); }
.form-group { margin-bottom: 16px; }

/* ── Filter bar ── */
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-bar select, .filter-bar input { width: auto; min-width: 0; max-width: 180px; padding: 5px 10px; font-size: .78em; border-radius: 20px; background: var(--card); border: 1px solid var(--border); appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2386868b'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 26px; cursor: pointer; }
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,113,227,.1); }
.filter-bar .filter-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }
.filter-bar .filter-label { font-size: .75em; color: var(--muted); font-weight: 500; white-space: nowrap; }

/* ── Cards ── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }

/* ── Login ── */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(135deg, #667eea11 0%, #764ba211 100%); }
.login-card { width: 100%; max-width: 380px; }
.login-title { font-size: 1.5em; font-weight: 700; text-align: center; margin-bottom: 24px; color: var(--text); }
.login-tabs { display: flex; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.login-tab { flex: 1; text-align: center; padding: 10px; cursor: pointer; font-size: .88em; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.login-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.login-error { background: #fff2f2; color: var(--red); padding: 8px 12px; border-radius: 8px; font-size: .82em; margin-bottom: 12px; display: none; }

/* ── Console layout ── */
.console-layout { display: flex; flex-direction: column; height: calc(100vh - 48px); }

/* ── Center area ── */
.center-area { display: flex; flex-direction: column; flex: 1; overflow: hidden; background: var(--bg); }

/* ── Phone toolbar ── */
.phone-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.toolbar-group { display: flex; align-items: center; gap: 4px; }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.toolbar-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border: none; border-radius: 8px; background: transparent; font-size: 1em; cursor: pointer; transition: background .12s; color: var(--text); }
.toolbar-btn:hover { background: var(--bg); }
.toolbar-btn:active { background: #e0e0e5; }
.toolbar-btn-sm { width: 28px; height: 28px; font-size: .85em; }
.toolbar-input { flex: 1; max-width: 280px; position: relative; }
.toolbar-text { padding: 6px 36px 6px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: .82em; height: 34px; }
.toolbar-send { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; font-size: .9em; color: var(--accent); font-weight: 700; }
.device-upload-status { max-width: 180px; color: var(--muted); font-size: .72em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-upload-status.ok { color: #15803d; }
.device-upload-status.err { color: #dc2626; }

/* ── Phone row ── */
.phone-row { display: flex; flex: 1; overflow: hidden; }

/* ── Phone screen ── */
.phone-area { display: flex; justify-content: center; align-items: center; padding: 16px; flex: 1; min-height: 300px; overflow: hidden; }
.phone-frame { background: #1a1a1a; border-radius: 32px; padding: 10px 8px; box-shadow: var(--shadow-md), 0 0 0 1px rgba(0,0,0,.1); max-height: 100%; }
.phone-notch { width: 72px; height: 4px; background: #333; border-radius: 2px; margin: 0 auto 6px; opacity: .4; }
.screen-wrap { position: relative; overflow: hidden; border-radius: 22px; }
.screen-wrap.device-drop-active { outline: 3px dashed #60a5fa; outline-offset: 6px; background: #eff6ff; }
.screen-wrap img { display: block; max-height: calc(100vh - 180px); width: auto; cursor: crosshair; border-radius: 22px; }
.screen-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 260px; height: min(560px, calc(100vh - 220px)); background: #222; border-radius: 22px; color: #666; gap: 8px; }
.screen-placeholder-icon { font-size: 2.2em; opacity: .4; }
.screen-placeholder-text { font-size: .82em; opacity: .5; }

/* ── Node overlay ── */
.node-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; border-radius: 22px; overflow: hidden; }
.node-overlay.active { pointer-events: auto; }
.node-rect { position: absolute; border: 1.5px solid rgba(0,113,227,.5); background: rgba(0,113,227,.06); cursor: pointer; transition: background .1s; }
.node-rect:hover { background: rgba(0,113,227,.2); border-color: rgba(0,113,227,.8); }
.node-rect-label { position: absolute; bottom: 100%; left: 0; background: rgba(29,29,31,.88); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; pointer-events: none; display: none; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.node-rect:hover .node-rect-label, .node-rect-active .node-rect-label { display: block; }
.node-rect-active { background: rgba(0,113,227,.25) !important; border-color: var(--accent) !important; }

/* ── Nodes panel ── */
.nodes-panel { width: 260px; flex-shrink: 0; background: var(--card); border-left: 1px solid var(--border); display: none; flex-direction: column; }
.nodes-panel.open { display: flex; }
.nodes-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.nodes-panel-title { font-size: .82em; font-weight: 600; color: var(--muted); }
.nodes-list { flex: 1; overflow-y: auto; }

/* ── Sidebar ── */
.sidebar { background: var(--card); overflow-y: auto; }
.panel { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-grow { flex: 1; display: flex; flex-direction: column; }
.panel-title { font-size: .75em; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }

/* ── Chat ── */
.chat-area { position: relative; flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.chat-header h3 { font-size: .88em; font-weight: 600; color: var(--text); }
.chat-header-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chat-icon-btn { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 9px; background: var(--card); color: var(--muted); cursor: pointer; transition: background .12s, border-color .12s, color .12s, box-shadow .12s; }
.chat-icon-btn:hover, .chat-icon-btn.active { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; box-shadow: 0 1px 4px rgba(0,113,227,.08); }
.chat-icon-btn-sm { width: 26px; height: 26px; border-radius: 8px; font-size: .78em; }
.conv-popover { display: none; position: absolute; top: 58px; right: 12px; width: min(360px, calc(100% - 24px)); max-height: min(420px, calc(100% - 96px)); z-index: 20; background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-md); overflow: hidden; flex-direction: column; }
.conv-popover.open { display: flex; }
.conv-popover-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: .78em; font-weight: 700; letter-spacing: .04em; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 88%; padding: 8px 12px; border-radius: 14px; font-size: .82em; line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.chat-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-ai { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 4px; }
.chat-card-msg { padding: 0; background: transparent; white-space: normal; max-width: 94%; }
.ai-card { width: min(360px, 100%); background: linear-gradient(180deg, #fff 0%, #f8fafc 100%); border: 1px solid #e5e7eb; border-radius: 16px; box-shadow: 0 6px 22px rgba(15,23,42,.07); overflow: hidden; }
.ai-card-head { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px 10px; }
.ai-card-icon { width: 30px; height: 30px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: #e3f2fd; color: #1565c0; font-weight: 700; font-size: .78em; }
.ai-card-confirm .ai-card-icon { background: #fff7ed; color: #c2410c; }
.ai-card-running .ai-card-icon { background: #ecfdf5; color: #047857; }
.ai-card-title-wrap { min-width: 0; flex: 1; }
.ai-card-title { font-weight: 700; font-size: .98em; color: var(--text); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; }
.ai-card-subtitle { margin-top: 2px; color: var(--muted); font-size: .78em; line-height: 1.35; }
.ai-card-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0 14px 10px; }
.ai-card-meta-item { min-width: 0; padding: 7px 9px; border-radius: 10px; background: #f1f5f9; }
.ai-card-meta-item span { display: block; color: var(--muted); font-size: .72em; margin-bottom: 1px; }
.ai-card-meta-item strong { display: block; color: var(--text); font-size: .82em; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-card-desc { position: relative; margin: 0 14px 10px; padding: 10px 11px; background: #fff; border: 1px solid #eef2f7; border-radius: 12px; color: var(--text); font-size: .88em; line-height: 1.6; }
.ai-card-desc-body { white-space: pre-wrap; overflow: hidden; }
.ai-card-desc.collapsible.collapsed .ai-card-desc-body { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; max-height: 6.4em; }
.ai-card-desc.collapsible.collapsed::after { content: ''; position: absolute; left: 11px; right: 11px; bottom: 32px; height: 26px; pointer-events: none; background: linear-gradient(180deg, rgba(255,255,255,0) 0%, #fff 85%); border-radius: 0 0 12px 12px; }
.ai-card-desc-toggle { display: block; margin-top: 6px; padding: 2px 0; background: none; border: 0; color: var(--accent); font-size: .8em; cursor: pointer; font-weight: 600; }
.ai-card-desc-toggle:hover { text-decoration: underline; }
.ai-card-media { display: grid; grid-template-columns: repeat(auto-fit, minmax(78px, 1fr)); gap: 6px; padding: 0 14px 10px; }
.ai-card-media-item { position: relative; aspect-ratio: 1 / 1; border-radius: 8px; overflow: hidden; background: #f1f5f9; cursor: pointer; }
.ai-card-media-item img, .ai-card-media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-card-media-item.loading { background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%); background-size: 200% 100%; animation: ai-card-shimmer 1.2s infinite; }
@keyframes ai-card-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.ai-card-media-badge { position: absolute; right: 4px; bottom: 4px; padding: 1px 5px; border-radius: 999px; background: rgba(15,23,42,.7); color: #fff; font-size: .65em; line-height: 1.3; }
.ai-card-body { margin: 0 14px 12px; padding: 10px 11px; background: #fff; border: 1px solid #eef2f7; border-radius: 12px; color: #334155; font-size: .86em; line-height: 1.65; white-space: pre-wrap; }
.chat-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-attach-item { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; background: #e8eaed; cursor: pointer; }
.chat-attach-item img, .chat-attach-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-attach-item.loading { background: linear-gradient(90deg, #eef1f4 0%, #dde2e7 50%, #eef1f4 100%); background-size: 200% 100%; animation: ai-card-shimmer 1.2s infinite; }
.chat-attach-badge { position: absolute; right: 4px; bottom: 4px; padding: 1px 5px; border-radius: 999px; background: rgba(15,23,42,.7); color: #fff; font-size: .65em; line-height: 1.3; }
.lightbox { display: none; position: fixed; inset: 0; z-index: 1200; background: rgba(15,23,42,.88); align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; }
.lightbox.open { display: flex; }
.lightbox img, .lightbox video { max-width: min(92vw, 900px); max-height: 88vh; object-fit: contain; border-radius: 12px; box-shadow: 0 16px 60px rgba(0,0,0,.5); }
.lightbox-close { position: absolute; top: 16px; right: 20px; color: #fff; font-size: 1.6em; cursor: pointer; background: none; border: none; }
.ai-card-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 14px 12px; border-top: 1px solid #eef2f7; background: rgba(255,255,255,.65); }
.ai-card-action { border: 1px solid #dbeafe; background: #eff6ff; color: #1d4ed8; border-radius: 999px; padding: 5px 10px; font-size: .78em; font-weight: 600; cursor: pointer; }
.ai-card-action:hover { background: #dbeafe; }
.ai-card-action.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.ai-card-action.primary:hover { background: var(--accent-hover); }
.ai-card-action.secondary { border-color: #e5e7eb; background: #fff; color: #64748b; }
.ai-card-action.secondary:hover { background: #f8fafc; }
.ai-card-action:disabled { cursor: not-allowed; opacity: .45; }
.ai-card-action.selected:disabled { opacity: .85; box-shadow: 0 0 0 2px rgba(0,113,227,.16); }
.chat-step { align-self: flex-start; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; font-size: .75em; color: #92400e; font-family: 'SF Mono', Menlo, Consolas, monospace; }
.chat-step.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.chat-step.fail { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.chat-input { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; background: var(--card); }
.chat-input textarea { flex: 1; min-height: 36px; max-height: 80px; resize: none; border-radius: 10px; }
.conv-new-btn { justify-content: center; flex-shrink: 0; white-space: nowrap; }

/* ── Task icon animation ── */
.chat-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-screen-sync { display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: .72em; font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; background: var(--card); }
.chat-screen-sync input { width: auto; margin: 0; accent-color: var(--accent); }
.chat-screen-sync:has(input:checked) { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
.chat-screen-sync.syncing { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.chat-screen-sync.waiting { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.task-current { font-size: .74em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 28px; }
.task-monitor { padding: 10px 16px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, #f8fafc 0%, #fff 100%); }
.task-monitor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.task-monitor-title { font-size: .82em; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.task-monitor-sub { margin-top: 2px; font-size: .72em; color: var(--muted); }
.task-progress-track { height: 5px; overflow: hidden; border-radius: 999px; background: #e5e7eb; margin-bottom: 8px; }
.task-progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.task-event-list { max-height: 104px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.task-event { display: grid; grid-template-columns: 56px 1fr auto; gap: 6px; align-items: center; font-size: .72em; color: #334155; }
.task-event-time { color: var(--muted); font-family: 'SF Mono', Menlo, Consolas, monospace; }
.task-event-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-event-status { color: var(--muted); font-size: .9em; }
.task-event.ok .task-event-status { color: var(--green); }
.task-event.fail .task-event-status { color: var(--red); }
.task-icon { width: 20px; height: 20px; display: none; }
.task-icon.spinning { display: block; border: 2.5px solid #e3f2fd; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.task-icon.done { display: block; width: 20px; height: 20px; background: var(--green); border-radius: 50%; position: relative; animation: pop .3s ease; }
.task-icon.done::after { content: ''; position: absolute; left: 6px; top: 3px; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.task-icon.failed { display: block; width: 20px; height: 20px; background: var(--red); border-radius: 50%; position: relative; animation: pop .3s ease; }
.task-icon.failed::after { content: '\00d7'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; font-weight: 700; line-height: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(0); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* ── Step message icons ── */
.chat-step { position: relative; padding-left: 28px; }
.chat-step::before { content: ''; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; border-radius: 50%; }
.chat-step.ok::before { background: var(--green); box-shadow: 0 0 0 3px rgba(52,199,89,.15); }
.chat-step.fail::before { background: var(--red); box-shadow: 0 0 0 3px rgba(255,59,48,.15); }
.step-pending { align-self: flex-start; padding: 6px 12px 6px 28px; font-size: .75em; color: var(--muted); position: relative; }
.step-pending::before { content: ''; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 12px; height: 12px; border: 2px solid #e3f2fd; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

/* ── Status badges ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: .72em; font-weight: 600; }
.badge-online { background: #e8f8ee; color: #1a7f37; }
.badge-offline { background: var(--bg); color: var(--muted); }
.ts-idle { background: var(--bg); color: var(--muted); }
.ts-running { background: #e3f2fd; color: #1565c0; animation: pulse 2s infinite; }
.ts-done { background: #e8f8ee; color: #1a7f37; }
.ts-failed { background: #ffeef0; color: #cf222e; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ── Admin ── */
.admin-layout { padding: 24px; max-width: 1200px; margin: 0 auto; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { text-align: center; }
.stat-card .stat-num { font-size: 2em; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { font-size: .82em; color: var(--muted); }
.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid var(--border); }
.admin-tab { padding: 8px 16px; cursor: pointer; font-size: .88em; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.admin-section { display: none; }
.admin-section.active { display: block; }
table { width: 100%; border-collapse: collapse; font-size: .82em; }
th { text-align: left; padding: 10px 12px; background: var(--bg); font-weight: 600; color: var(--muted); border-bottom: 2px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #f8f9fa; }

/* ── UI tree nodes ── */
.node-item { padding: 7px 12px; font-size: .78em; cursor: pointer; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 6px; transition: background .1s; }
.node-item:hover { background: #e3f2fd; }
.node-hover { background: #bbdefb !important; }
.node-idx { background: #e3f2fd; color: var(--accent); padding: 1px 5px; border-radius: 4px; font-size: .72em; font-weight: 600; font-family: monospace; min-width: 22px; text-align: center; }
.node-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-tag { background: var(--bg); color: var(--muted); padding: 1px 6px; border-radius: 4px; font-size: .68em; }
.node-tag.clickable { background: #e8f8ee; color: #1a7f37; }
.node-tag.editable { background: #fff8e1; color: #e65100; }

/* ── Log area ── */
.log-area { font-size: .7em; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 10px; font-family: 'SF Mono', Menlo, Consolas, monospace; white-space: pre-wrap; line-height: 1.6; overflow-y: auto; flex: 1; min-height: 60px; }

/* ── Device cards ── */
.device-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.device-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start; align-items: start; grid-auto-rows: max-content; }
.device-log { font-size: .7em; color: var(--muted); margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--border); line-height: 1.5; max-height: 5.5em; overflow: hidden; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 12px; font-size: .75em; color: var(--muted); }
.pager button { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 2px 8px; font-size: .85em; cursor: pointer; color: var(--text); }
.pager button:disabled { opacity: .3; cursor: default; }
.pager button:hover:not(:disabled) { background: var(--bg); }
.device-card { padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px; transition: all .15s; }
.device-card:hover:not(.offline) { background: #f0f4ff; border-color: #c7d2fe; }
.device-card.selected { border-color: var(--accent); background: #eff6ff; box-shadow: 0 0 0 3px rgba(0,113,227,.1); }
.device-card.offline { opacity: .45; cursor: default; }
.device-card-main { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.device-model { font-weight: 600; font-size: .85em; }
.device-card-info { font-size: .7em; color: var(--muted); }
.device-card-tags { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.device-tag { font-size: .62em; padding: 2px 6px; border-radius: 4px; font-weight: 500; }
.tag-ok { background: #e8f8ee; color: #1a7f37; }
.tag-warn { background: #ffeef0; color: #cf222e; }
.tag-help { display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px; border-radius: 50%; background: rgba(0,0,0,.1); color: inherit; font-size: 8px; font-weight: 700; margin-left: 2px; cursor: pointer; vertical-align: middle; }
.tag-tip-popup { position: absolute; left: 0; top: calc(100% + 6px); background: var(--nav-bg); color: #fff; font-size: .72em; padding: 6px 10px; border-radius: 8px; white-space: nowrap; z-index: 50; box-shadow: var(--shadow-md); font-weight: 400; letter-spacing: 0; }
.device-empty { text-align: center; padding: 28px 10px; color: var(--muted); }
.device-empty p:first-child { font-size: .88em; margin-bottom: 4px; }

/* ── Conversation list ── */
.conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.conv-item { padding: 8px 10px; cursor: pointer; border-radius: 8px; transition: background .1s; margin-bottom: 2px; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #e3f2fd; }
.conv-title { font-size: .82em; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: .7em; color: var(--muted); }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.4); z-index: 200; justify-content: center; align-items: center; padding: 20px; backdrop-filter: blur(4px); }
.modal-card { background: var(--card); border-radius: 16px; width: 100%; max-width: 380px; box-shadow: 0 24px 60px rgba(0,0,0,.2); overflow: hidden; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1em; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.4em; cursor: pointer; color: var(--muted); padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; text-align: center; }
.modal-divider { border-top: 1px solid var(--border); margin: 0 20px; }
.modal-footer-section { padding: 14px 20px; }

/* ── QR / Pairing ── */
.qr-container { display: flex; justify-content: center; margin: 16px 0; }
.qr-image { border-radius: 10px; border: 3px solid var(--card); box-shadow: var(--shadow); }
.pairing-code-display { font-size: 1.8em; font-weight: 700; letter-spacing: .3em; color: var(--accent); font-family: 'SF Mono', Menlo, Consolas, monospace; margin: 8px 0; }
.pairing-timer { font-size: .82em; color: var(--muted); }
.code-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.code-item:last-child { border-bottom: none; }
.code-text { font-family: 'SF Mono', Menlo, Consolas, monospace; font-weight: 600; letter-spacing: .12em; font-size: .85em; }
.code-expiry { font-size: .75em; }

/* ── Device guide ── */
.device-guide { display: none; max-width: 420px; width: 100%; padding: 40px 28px; text-align: center; }
.device-guide.visible { display: block; }
.guide-icon { font-size: 2.8em; margin-bottom: 10px; }
.guide-title { font-size: 1.3em; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.guide-subtitle { font-size: .85em; color: var(--muted); margin-bottom: 28px; }
.guide-steps { text-align: left; display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.guide-step { display: flex; gap: 12px; align-items: flex-start; }
.guide-step-num { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: .78em; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.guide-step-content { flex: 1; }
.guide-step-title { font-weight: 600; font-size: .88em; margin-bottom: 1px; }
.guide-step-desc { font-size: .78em; color: var(--muted); line-height: 1.4; }
.guide-step-desc strong { color: var(--accent); font-weight: 600; }
.guide-btn { width: 100%; justify-content: center; padding: 10px; font-size: .92em; border-radius: 10px; }

/* ── Text helpers ── */
.text-sm { font-size: .78em; }
.text-muted { color: var(--muted); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Responsive: Desktop ── */
@media (min-width: 768px) {
  .nav-toggle { display: none; }
  .console-layout { flex-direction: row; }
  .sidebar-left { width: 520px; flex-shrink: 0; border-right: 1px solid var(--border); }
  .sidebar-right { width: 480px; flex-shrink: 0; border-left: 1px solid var(--border); display: flex; flex-direction: column; }
  .center-area { flex: 1; }
  .mobile-tabs { display: none; }
}

/* ── Responsive: Mobile ── */
@media (max-width: 767px) {
  .navbar { height: 44px; padding: 0 12px; }
  .nav-toggle { display: block; }
  .nav-links { display: none; position: absolute; top: 44px; left: 0; right: 0; background: var(--nav-bg); flex-direction: column; padding: 8px; z-index: 100; }
  .nav-links.open { display: flex; }
  .nav-user .user-name { display: none; }
  .sidebar-left, .sidebar-right { display: none; }
  .nodes-panel { display: none !important; }
  .sidebar-left.open, .sidebar-right.open { display: flex; flex-direction: column; position: fixed; top: 44px; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--card); }
  #controls-panel.open { display: flex; flex-direction: column; position: fixed; top: 44px; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--card); width: 100%; }
  .mobile-tabs { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--border); z-index: 100; }
  .mobile-tab { flex: 1; text-align: center; padding: 8px 0; font-size: .72em; color: var(--muted); cursor: pointer; }
  .mobile-tab.active { color: var(--accent); font-weight: 600; }
  .phone-area { min-height: calc(100vh - 44px - 42px); padding: 8px; }
  .phone-toolbar { padding: 6px 8px; gap: 4px; flex-wrap: wrap; }
  .toolbar-input { max-width: none; }
  .admin-layout { padding: 12px; }
  .console-layout { height: calc(100vh - 44px); }
}
