:root {
  --canvas: #e8e7e2;
  --paper: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #eeede8;
  --ink: #171816;
  --muted: #74766f;
  --faint: #a6a79f;
  --line: #ddddd7;
  --line-dark: #c9cac2;
  --green: #147a59;
  --green-bright: #2ed39a;
  --green-soft: #e0f3eb;
  --amber: #b86e13;
  --amber-soft: #f8ead7;
  --red: #b13a34;
  --red-soft: #f9e6e3;
  --black: #171816;
  --shadow-lg: 0 25px 70px rgba(24, 25, 22, .22);
  --shadow-md: 0 12px 35px rgba(24, 25, 22, .11);
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; background: var(--canvas); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { color: inherit; cursor: pointer; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

.remote-app { position: relative; width: min(100%, 520px); height: 100dvh; margin: 0 auto; overflow: hidden; background: var(--paper); box-shadow: var(--shadow-lg); }
.screen-stack { height: 100%; overflow: hidden; }
.screen { display: none; height: 100%; overflow-y: auto; padding: max(25px, env(safe-area-inset-top)) 20px 0; scrollbar-width: none; }
.screen::-webkit-scrollbar { display: none; }
.screen.active { display: block; }
.screen-spacer { height: calc(96px + env(safe-area-inset-bottom)); }

.app-header, .page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.app-header { margin-bottom: 25px; }
.app-header h1, .page-header h1 { margin: 1px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 37px; line-height: 1; font-weight: 600; }
.product-label, .kicker { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; line-height: 1; letter-spacing: .14em; font-weight: 900; color: var(--green); }
.kicker.warning { color: var(--amber); }
.device-avatar, .round-action, .filter-icon, .header-icon, .composer-plus, .send-button, .sheet-close {
  display: grid; place-items: center; border: 0; padding: 0;
}
.device-avatar { position: relative; width: 46px; height: 46px; border-radius: 50%; background: var(--black); color: white; }
.device-avatar svg { width: 22px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green-bright); box-shadow: 0 0 0 3px rgba(46, 211, 154, .15); }
.device-avatar .live-dot { position: absolute; right: 0; bottom: 2px; border: 2px solid var(--paper); width: 11px; height: 11px; box-shadow: none; }
.live-dot.offline { background: var(--red); box-shadow: 0 0 0 3px rgba(177, 58, 52, .12); }

.device-panel { display: grid; grid-template-columns: 50px minmax(0, 1fr) 46px; align-items: center; gap: 13px; min-height: 92px; margin-bottom: 32px; padding: 16px; background: var(--black); color: white; border-radius: 18px; }
.device-visual { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 13px; background: #2a2c28; }
.device-visual svg { width: 25px; color: #eceee7; }
.device-copy { min-width: 0; display: grid; gap: 3px; }
.connection-line { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; color: #bfc2b9; }
.connection-line .live-dot { width: 6px; height: 6px; box-shadow: none; }
.device-copy strong { overflow: hidden; font-size: 15px; white-space: nowrap; text-overflow: ellipsis; }
.device-copy small { overflow: hidden; color: #989b94; font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.round-action { width: 44px; height: 44px; border-radius: 50%; background: white; color: var(--black); }
.round-action svg { width: 21px; }
.round-action.dark { background: var(--black); color: white; }

.section-head { display: flex; align-items: end; justify-content: space-between; margin: 0 2px 16px; }
.section-head h2 { margin: 3px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 29px; line-height: 1; }
.text-action { min-height: 34px; border: 0; background: transparent; color: var(--green); font-weight: 750; font-size: 13px; }
.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; flex: 1; height: 40px; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.segmented button { border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 750; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(24,25,22,.08); }
.filter-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); }
.filter-icon svg { width: 19px; }
.search-field { display: grid; grid-template-columns: 20px 1fr; align-items: center; gap: 9px; min-height: 44px; margin: -3px 0 14px; padding: 0 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.search-field svg { width: 18px; color: var(--faint); }
.search-field input { min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }

.task-feed { display: grid; gap: 11px; }
.task-card { position: relative; display: grid; grid-template-columns: 44px minmax(0,1fr) 18px; gap: 12px; align-items: center; width: 100%; min-height: 98px; padding: 15px 14px; text-align: left; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 4px 16px rgba(24,25,22,.035); }
.task-card:active { transform: scale(.992); }
.task-project-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--green-soft); color: var(--green); font-family: Georgia, "Times New Roman", serif; font-size: 17px; font-weight: 700; }
.task-project-mark.running { background: var(--black); color: white; }
.task-card-copy { min-width: 0; }
.task-card-top { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.task-state { display: inline-flex; align-items: center; gap: 5px; color: var(--green); font-size: 10px; font-weight: 850; text-transform: uppercase; }
.task-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.task-state.waiting { color: var(--amber); }
.task-state.quiet { color: var(--faint); }
.task-time { margin-left: auto; color: var(--faint); font-size: 10px; }
.task-card h3 { margin: 0; overflow: hidden; font-size: 14px; line-height: 1.35; white-space: nowrap; text-overflow: ellipsis; }
.task-card p { margin: 6px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.4; white-space: nowrap; text-overflow: ellipsis; }
.task-card > svg { width: 17px; color: var(--faint); }
.empty-feed { display: grid; place-items: center; min-height: 220px; padding: 30px; text-align: center; border: 1px dashed var(--line-dark); border-radius: 16px; color: var(--muted); }
.empty-feed svg { width: 30px; margin-bottom: 12px; color: var(--green); }
.empty-feed strong { display: block; color: var(--ink); margin-bottom: 5px; }
.empty-feed p { margin: 0; font-size: 12px; line-height: 1.6; }

.page-header { margin-bottom: 24px; }
.page-intro { margin: -9px 0 25px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.header-count { display: grid; place-items: center; min-width: 38px; height: 38px; padding: 0 10px; border-radius: 19px; background: var(--amber-soft); color: var(--amber); font-weight: 850; }
.project-grid { display: grid; gap: 12px; }
.project-card { position: relative; min-height: 142px; padding: 18px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.project-icon { display: grid; place-items: center; width: 38px; height: 38px; margin-bottom: 20px; border-radius: 10px; background: var(--black); color: white; }
.project-icon svg { width: 19px; }
.project-card h3 { margin: 0 0 7px; font-family: Georgia, "Times New Roman", serif; font-size: 21px; }
.project-card p { margin: 0; padding-right: 40px; overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.project-count { position: absolute; right: 16px; top: 16px; color: var(--muted); font-size: 11px; font-weight: 750; }

.approval-feed { display: grid; gap: 13px; }
.approval-card { padding: 17px; background: var(--surface); border: 1px solid #e7c9a5; border-radius: 16px; box-shadow: 0 6px 22px rgba(104,64,17,.06); }
.approval-card-head { display: flex; align-items: start; gap: 11px; }
.approval-symbol { display: grid; place-items: center; flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); }
.approval-symbol svg { width: 19px; }
.approval-card h3 { margin: 1px 0 3px; font-size: 14px; }
.approval-card .reason { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.approval-code { max-height: 150px; margin: 14px 0 0; overflow: auto; padding: 12px; border-radius: 9px; background: #22231f; color: #f3f3ed; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.approval-buttons button { min-height: 40px; border-radius: 9px; font-weight: 800; font-size: 12px; }
.approval-buttons .decline { background: var(--surface); border: 1px solid var(--line-dark); }
.approval-buttons .accept { background: var(--black); border: 1px solid var(--black); color: white; }
.approval-buttons .session { grid-column: 1 / -1; background: var(--green-soft); border: 1px solid #c2e4d5; color: var(--green); }

.connection-hero { display: grid; justify-items: center; padding: 25px 20px 29px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.connection-rings { position: relative; display: grid; place-items: center; width: 122px; height: 122px; margin-bottom: 17px; }
.connection-rings > span { position: absolute; inset: 9px; border: 1px solid #cae8dc; border-radius: 50%; }
.connection-rings > span:first-child { inset: 0; border-color: #e0eee8; }
.connection-rings svg { position: relative; width: 30px; color: var(--green); }
.connection-line.center { color: var(--green); font-weight: 800; }
.connection-hero h2 { margin: 9px 0 8px; font-family: Georgia, "Times New Roman", serif; font-size: 26px; }
.connection-hero p { max-width: 340px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.settings-list { margin-top: 18px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; min-height: 54px; padding: 0 16px; border-bottom: 1px solid var(--line); font-size: 12px; }
.settings-row:last-child { border-bottom: 0; }
.settings-row span { color: var(--muted); }
.settings-row strong { max-width: 60%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.bottom-nav { position: absolute; z-index: 8; left: 12px; right: 12px; bottom: var(--safe-bottom); display: grid; grid-template-columns: repeat(4,1fr); min-height: 67px; padding: 7px; border: 1px solid rgba(214,214,207,.9); border-radius: 18px; background: rgba(255,255,255,.94); box-shadow: 0 12px 34px rgba(24,25,22,.16); backdrop-filter: blur(18px); }
.bottom-nav button { position: relative; display: grid; place-items: center; align-content: center; gap: 4px; border: 0; border-radius: 12px; background: transparent; color: var(--faint); font-size: 9px; font-weight: 800; }
.bottom-nav button.active { background: var(--surface-2); color: var(--ink); }
.bottom-nav svg { width: 20px; height: 20px; }
.nav-badge { position: absolute; top: 1px; left: calc(50% + 6px); display: grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; border: 2px solid white; border-radius: 10px; background: var(--amber); color: white; font-size: 8px; }

.chat-view { position: absolute; z-index: 12; inset: 0; display: flex; flex-direction: column; background: var(--paper); transform: translateX(102%); transition: transform .25s ease; }
.chat-view.open { transform: translateX(0); }
.chat-header { display: grid; grid-template-columns: 42px minmax(0,1fr) 42px; align-items: center; gap: 8px; min-height: calc(68px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; border-bottom: 1px solid var(--line); background: rgba(247,246,242,.96); backdrop-filter: blur(15px); }
.header-icon { width: 42px; height: 42px; border-radius: 50%; background: transparent; }
.header-icon:active { background: var(--surface-2); }
.header-icon svg { width: 22px; }
.header-icon.danger { color: var(--red); }
.chat-heading { min-width: 0; text-align: center; }
.chat-heading h1 { margin: 0; overflow: hidden; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
.chat-heading span { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.conversation { flex: 1; overflow-y: auto; padding: 24px 17px 125px; scroll-behavior: smooth; }
.message { display: grid; grid-template-columns: 29px minmax(0,1fr); gap: 10px; margin: 0 0 24px; }
.message.user { grid-template-columns: minmax(0,1fr); }
.avatar { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 9px; background: var(--black); color: white; font-family: Georgia, "Times New Roman", serif; font-size: 13px; font-weight: 700; }
.message.user .avatar { display: none; }
.message-body { min-width: 0; }
.message.user .message-body { justify-self: end; max-width: 88%; padding: 11px 13px; border-radius: 15px 15px 3px 15px; background: var(--black); color: white; }
.message-role { margin: 0 0 6px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 9px; letter-spacing: .1em; font-weight: 900; }
.message.user .message-role { display: none; }
.message-content { font-size: 13px; line-height: 1.67; white-space: pre-wrap; overflow-wrap: anywhere; }
.tool-item { margin-top: 7px; padding: 10px 11px; border-left: 3px solid var(--line-dark); border-radius: 0 8px 8px 0; background: var(--surface-2); color: #50524c; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 9px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.tool-item.running { border-left-color: var(--amber); }
.tool-item.completed { border-left-color: var(--green); }
.composer { position: absolute; left: 10px; right: 10px; bottom: var(--safe-bottom); display: grid; grid-template-columns: 38px minmax(0,1fr) 42px; align-items: end; gap: 6px; min-height: 58px; padding: 8px; border: 1px solid var(--line-dark); border-radius: 18px; background: rgba(255,255,255,.97); box-shadow: var(--shadow-md); }
.composer textarea { align-self: center; max-height: 150px; resize: none; border: 0; outline: 0; padding: 8px 3px; background: transparent; color: var(--ink); font-size: 13px; line-height: 1.5; }
.composer-plus { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); }
.composer-plus svg { width: 19px; }
.send-button { width: 42px; height: 42px; border-radius: 50%; background: var(--green); color: white; }
.send-button svg { width: 18px; }
.send-button:disabled { opacity: .42; }

.sheet-backdrop { position: absolute; z-index: 18; inset: 0; background: rgba(20,21,18,.43); backdrop-filter: blur(2px); }
.bottom-sheet { position: absolute; z-index: 19; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; padding: 8px 20px calc(22px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; background: var(--surface); box-shadow: var(--shadow-lg); }
.sheet-handle { width: 42px; height: 4px; margin: 2px auto 17px; border-radius: 4px; background: var(--line-dark); }
.bottom-sheet header { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.bottom-sheet h2 { margin: 4px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 28px; }
.sheet-close { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); font-size: 22px; }
.bottom-sheet form { display: grid; gap: 17px; margin-top: 20px; }
.field-label { display: grid; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
.field-label input, .field-label select, .field-label textarea { width: 100%; border: 1px solid var(--line-dark); border-radius: 11px; outline: 0; padding: 12px; background: var(--paper); color: var(--ink); font-size: 13px; }
.field-label textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.field-label input:focus, .field-label select:focus, .field-label textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20,122,89,.1); }
.permission-switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 2px 0; }
.permission-switch span { display: grid; gap: 4px; }
.permission-switch strong { font-size: 12px; }
.permission-switch small { max-width: 310px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.permission-switch input { position: absolute; opacity: 0; }
.permission-switch i { position: relative; flex: 0 0 auto; width: 46px; height: 27px; border-radius: 15px; background: var(--line-dark); transition: .16s; }
.permission-switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: .16s; }
.permission-switch input:checked + i { background: var(--green); }
.permission-switch input:checked + i::after { transform: translateX(19px); }
.main-cta { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 50px; border: 0; border-radius: 12px; background: var(--black); color: white; font-weight: 850; }
.main-cta svg { width: 18px; }
.main-cta:disabled { opacity: .55; }
.toast { position: absolute; z-index: 30; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 36px); padding: 11px 15px; border-radius: 10px; background: var(--black); color: white; box-shadow: var(--shadow-md); font-size: 12px; text-align: center; }

@media (min-width: 760px) {
  body { padding: 18px 0; }
  .remote-app { height: calc(100dvh - 36px); border-radius: 26px; }
}

@media (max-width: 519px) {
  .remote-app { width: 100%; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
