      :root {
        --bg: #ffffff;
        --surface: #fafafa;
        --surface-2: #f4f4f4;
        --ink: #1a1a1a;
        --mute: #6b6b6b;
        --mute-soft: #9a9a9a;
        --line: #e7e7e7;
        --line-soft: #f0f0f0;
        --accent: #0078d7;
        --accent-soft: rgba(0, 120, 215, 0.1);
        --accent-tint: rgba(0, 120, 215, 0.18);
        --green: #107c10;
        --orange: #d83b01;
        --red: #e81123;
      }
      * { box-sizing: border-box; margin: 0; padding: 0; }
      html, body { height: 100%; }
      body {
        font-family: "Inter", "Segoe UI", system-ui, sans-serif;
        font-size: 13.5px; line-height: 1.5;
        background: var(--bg); color: var(--ink);
        font-weight: 400; -webkit-font-smoothing: antialiased;
      }
      .mono, code { font-family: "JetBrains Mono", monospace; }
      ::selection { background: var(--accent); color: #fff; }
      * { scrollbar-width: none; }
      ::-webkit-scrollbar { display: none; width: 0; height: 0; }

      .shell {
        display: grid;
        grid-template-columns: 232px 1fr;
        grid-template-rows: 56px 1fr;
        grid-template-areas: "brand topbar" "tabs main";
        height: 100vh;
      }

      .brand-cell {
        grid-area: brand;
        background: var(--surface-2);
        border-right: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
        display: flex; align-items: center;
        padding: 0 20px;
      }

      .topbar {
        grid-area: topbar;
        border-bottom: 1px solid var(--line);
        background: var(--bg);
        display: flex; align-items: center;
        padding: 0 20px; gap: 10px;
      }
      .topbar h1 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
      .topbar .spacer { flex: 1; }
      .back-link {
        display: inline-flex; align-items: center; gap: 6px;
        color: var(--mute); text-decoration: none;
        font-size: 12.5px; font-weight: 500;
        padding: 6px 10px; border-radius: 4px;
        border: 1px solid var(--line);
        transition: all 0.1s;
      }
      .back-link:hover { color: var(--ink); background: var(--surface); }

      .tabs {
        grid-area: tabs;
        background: var(--surface);
        border-right: 1px solid var(--line);
        padding: 10px 0;
        overflow-y: auto;
      }
      .tab-section {
        color: var(--mute); font-size: 10px;
        text-transform: uppercase; letter-spacing: 0.08em;
        font-weight: 600; padding: 10px 18px 6px;
      }
      .tab-item {
        display: flex; align-items: center; gap: 10px;
        padding: 9px 18px; cursor: pointer;
        font-size: 13px; font-weight: 500; color: var(--ink);
        border-left: 3px solid transparent;
        transition: background 0.08s, border-color 0.08s;
      }
      .tab-item i { width: 14px; text-align: center; color: var(--mute); }
      .tab-item:hover { background: var(--accent-soft); }
      .tab-item.active {
        background: var(--accent-soft);
        border-left-color: var(--accent);
        color: var(--accent); font-weight: 600;
      }
      .tab-item.active i { color: var(--accent); }

      main {
        grid-area: main; overflow-y: auto; padding: 28px 32px;
      }
      .tab-panel { display: none; max-width: 720px; }
      .tab-panel.active { display: block; }
      .panel-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
      .panel-desc { font-size: 12.5px; color: var(--mute); margin-bottom: 22px; }

      .section-head {
        display: flex; align-items: center; justify-content: space-between;
        margin: 24px 0 10px;
      }
      .section-head:first-of-type { margin-top: 0; }
      .section-head h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--mute); }

      .btn {
        font-family: "Inter", sans-serif;
        font-size: 12.5px; font-weight: 600;
        padding: 7px 14px; border-radius: 5px;
        border: 1px solid var(--line);
        background: var(--bg); color: var(--ink);
        cursor: pointer; transition: all 0.1s;
      }
      .btn:hover { background: var(--surface); }
      .btn:disabled { opacity: 0.5; cursor: not-allowed; }
      a.btn { text-decoration: none; display: inline-block; }
      .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
      .btn-primary:hover { background: #005ba1; }
      .btn-ghost { border-color: transparent; color: var(--mute); }
      .btn-ghost:hover { color: var(--ink); background: var(--surface); }

      .model-list { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
      .model-row {
        display: flex; align-items: center; gap: 10px;
        padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
        font-family: "JetBrains Mono", monospace; font-size: 12.5px;
      }
      .model-row:last-child { border-bottom: none; }
      .panel-divider { height: 6px; background: var(--surface); border-bottom: 1px solid var(--line-soft); }
      .model-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
      .model-row .meta { flex: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--mute); }
      .model-row .btn-remove, .model-row .btn-run {
        border: none; background: none; color: var(--mute-soft); cursor: pointer;
        padding: 4px 6px; border-radius: 4px; font-size: 12px; line-height: 1;
      }
      .model-row .btn-remove:hover { color: #d33; background: rgba(221, 51, 51, 0.1); }
      .model-row .btn-run:hover { color: var(--accent); background: var(--accent-soft); }

      /* automation rows: skill name on top, session tag + schedule on the line below */
      .model-row.stacked { display: block; }
      .model-row.stacked .row-top { display: flex; align-items: center; gap: 10px; }
      .model-row.stacked .row-tag { margin-top: 6px; display: flex; align-items: center; gap: 8px; }
      .session-tag {
        display: inline-block; font-family: "JetBrains Mono", monospace; font-size: 11px;
        font-weight: 600; padding: 2px 8px; border-radius: 10px;
        background: var(--accent-soft); color: var(--accent);
      }

      /* Torii error-memory rows: free-text fields (symptom/cause/action/outcome) are
         way too long for the compact nowrap-ellipsis .row-tag/.meta pattern used by
         Automation/MCP/Sessions — each field gets its own row with the label pinned
         to a fixed-width column and the text wrapping normally underneath it. */
      /* .torii-row is now a <details> — summary shows just tool name + symptom
         (collapsed default) so a long list of records doesn't dump cause/action/
         outcome/keywords for every row at once; only "show details" expands that. */
      .torii-row { border-bottom: 1px solid var(--line-soft); }
      .torii-row:last-child { border-bottom: none; }
      /* the list container is itself .model-list (#torii-error-list), so the generic
         .model-list details summary rule below (display:flex, single-line layout)
         has higher specificity than a plain ".torii-row summary" and wins — this has
         to match/beat that specificity explicitly to force it back to block layout */
      .model-list details.torii-row summary {
        display: block; padding: 14px 16px; cursor: pointer; list-style: none;
        font-family: inherit; font-size: inherit;
      }
      .torii-row summary::-webkit-details-marker { display: none; }
      .torii-row .row-top {
        display: flex; align-items: baseline; justify-content: space-between;
        gap: 10px;
      }
      .torii-row .row-top .name { font-weight: 700; font-size: 13.5px; }
      .torii-row .row-top .meta { flex: none; font-size: 11.5px; color: var(--mute-soft); }
      .torii-summary-symptom {
        margin-top: 6px; font-family: "JetBrains Mono", monospace;
        font-size: 12px; line-height: 1.6; color: var(--ink);
      }
      .torii-toggle-label { margin-top: 8px; font-size: 11px; color: var(--accent); }
      .torii-row .open-label { display: none; }
      .torii-row[open] .open-label { display: inline; }
      .torii-row[open] .closed-label { display: none; }
      .torii-row-body { padding: 0 16px 14px; }
      .torii-field { display: flex; gap: 10px; margin-top: 6px; align-items: flex-start; }
      /* line-height matches .value's 12px*1.6 so the pill's text sits level with
         the first line of content, regardless of content type */
      .torii-field .session-tag { flex: none; width: 64px; text-align: center; line-height: 19px; }
      .torii-field .value {
        flex: 1; min-width: 0; font-family: "JetBrains Mono", monospace;
        font-size: 12px; line-height: 1.6; color: var(--ink);
        white-space: pre-wrap; word-break: break-word;
      }
      /* rendered markdown (headings/tables/code blocks) manages its own block
         spacing — the plain-text .value defaults above would otherwise force every
         line (including block elements) through monospace pre-wrap */
      /* the shared .md-render rule below caps height + scrolls internally (for the
         schedule-details popup) — here the whole modal-body should scroll instead,
         so this un-does that box for the history-file "結果" field specifically */
      .torii-field .value.md-render {
        white-space: normal; font-family: "Inter", sans-serif;
        max-height: none; overflow: visible;
      }
      /* a leading heading's own 1rem top padding (markdown.css) would otherwise push
         the first line down well past the session-tag pill it's supposed to align
         with — only the very first block needs this killed */
      .torii-field .value.md-render > :first-child { margin-top: 0; padding-top: 0; }
      .torii-keywords { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
      .allow-cmd-tags { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; }

      /* MCP server connection indicator */
      .mcp-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--mute-soft); }
      .mcp-dot.online { background: var(--green); }
      .mcp-dot.idle { background: var(--mute-soft); }

      /* schedule details popup: box sizing only — markdown content styling
         (md-h1..h6, md-bold, md-list, md-code, ...) lives in shared markdown.css */
      .md-render {
        max-height: 320px; overflow-y: auto;
        font-family: "JetBrains Mono", monospace; font-size: 12.5px; line-height: 1.6;
        color: var(--ink); overflow-wrap: anywhere;
      }

      .empty-hint { padding: 16px; color: var(--mute-soft); font-style: italic; font-size: 12.5px; }

      /* per-session log lists (Daemon/Action/Usage) — <details> per session, content
         only fetched on first expand (see sessionlogs.js's "toggle" listener) — and
         the same convention for the History modal's per-tool-result <details>, which
         needed .md-render on its wrapper (below) since without it the base
         .torii-field .value's white-space:pre-wrap preserved this template's own
         indentation/newlines as visible blank lines between rows. */
      .model-list details, .torii-field .value.md-render details {
        border-bottom: 1px solid var(--line-soft);
      }
      .model-list details:last-child, .torii-field .value.md-render details:last-child {
        border-bottom: none;
      }
      .model-list details summary, .torii-field .value.md-render details summary {
        padding: 10px 14px; cursor: pointer; list-style: none;
        font-family: "JetBrains Mono", monospace; font-size: 12.5px;
        display: flex; align-items: center; gap: 10px;
      }
      .model-list details summary::-webkit-details-marker,
      .torii-field .value.md-render details summary::-webkit-details-marker { display: none; }
      .model-list details summary::before, .torii-field .value.md-render details summary::before {
        content: "\25B8"; color: var(--mute-soft); font-size: 11px; width: 10px;
      }
      .model-list details[open] summary::before, .torii-field .value.md-render details[open] summary::before {
        content: "\25BE";
      }
      .model-list details .log-body-content, .torii-field .value.md-render details .log-body-content {
        padding: 0 14px 14px;
      }

      /* ===== Add Model modal ===== */
      .modal-overlay {
        position: fixed; inset: 0; z-index: 500;
        background: rgba(0,0,0,0.32);
        display: flex; align-items: center; justify-content: center;
      }
      .modal-card {
        width: 480px; max-width: calc(100vw - 40px); max-height: 82vh;
        display: flex; flex-direction: column;
        background: var(--bg); border: 1px solid var(--line);
        border-radius: 10px; box-shadow: 0 24px 64px rgba(0,0,0,0.28);
        overflow: hidden;
      }
      .modal-head {
        display: flex; align-items: center; gap: 8px;
        padding: 14px 18px; border-bottom: 1px solid var(--line);
      }
      .modal-head .title {
        flex: 1; min-width: 0; font-weight: 700; font-size: 14px;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
      }
      .modal-head .step { font-size: 11px; color: var(--mute-soft); margin-left: auto; }
      .modal-close { background: none; border: none; color: var(--mute); font-size: 18px; cursor: pointer; padding: 2px 4px; }
      .modal-close:hover { color: var(--ink); }
      .modal-body { padding: 16px 18px; overflow-y: auto; }
      .modal-foot {
        display: flex; justify-content: space-between; gap: 8px;
        padding: 12px 18px; border-top: 1px solid var(--line);
      }

      .field { margin-bottom: 14px; }
      .field label { display: block; font-size: 11.5px; font-weight: 600; color: var(--mute); margin-bottom: 5px; }
      .field input, .field select, .field textarea {
        width: 100%; font-family: "JetBrains Mono", monospace; font-size: 12.5px;
        padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px;
        outline: none; background: var(--bg); color: var(--ink);
      }
      .field textarea { resize: vertical; }
      .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
      .field input[readonly] { background: var(--surface-2); color: var(--mute); }

      .model-row select {
        font-family: "JetBrains Mono", monospace; font-size: 12.5px;
        padding: 6px 8px; border: 1px solid var(--line); border-radius: 5px;
        outline: none; background: var(--bg); color: var(--ink); margin-left: auto;
      }
      .model-row select:focus { border-color: var(--accent); }
      .field .hint { font-size: 11px; color: var(--mute-soft); margin-top: 4px; }

      .pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
      .pick-item {
        display: flex; align-items: center; gap: 10px;
        padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px;
        cursor: pointer; transition: all 0.1s;
      }
      .pick-item:hover { border-color: var(--accent); background: var(--accent-soft); }
      .pick-item.selected { border-color: var(--accent); background: var(--accent-soft); }
      .pick-item .pi-label { font-weight: 600; font-size: 13px; flex: 1; }
      .pick-item .pi-meta { font-size: 11px; color: var(--mute); font-family: "JetBrains Mono", monospace; }

      .method-row { display: flex; gap: 8px; margin-bottom: 14px; }
      .method-chip {
        flex: 1; text-align: center; padding: 8px 10px;
        border: 1px solid var(--line); border-radius: 5px;
        cursor: pointer; font-size: 12px; font-weight: 600; color: var(--mute);
        transition: all 0.1s;
      }
      .method-chip:hover { border-color: var(--accent); color: var(--ink); }
      .method-chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

      .oauth-box {
        text-align: center; padding: 18px 10px; border: 1px dashed var(--line); border-radius: 6px;
      }
      .oauth-box .code { font-family: "JetBrains Mono", monospace; font-size: 20px; font-weight: 700; letter-spacing: 0.06em; margin: 10px 0; }
      .oauth-box a { color: var(--accent); font-weight: 600; }
      .spinner {
        display: inline-block; width: 14px; height: 14px; margin-right: 6px;
        border: 2px solid var(--line); border-top-color: var(--accent);
        border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px;
      }
      @keyframes spin { to { transform: rotate(360deg); } }

      .status-msg { font-size: 12px; margin-top: 10px; }
      .status-msg.error { color: var(--red); }
      .status-msg.ok { color: var(--green); }

      @media (max-width: 799px) {
        .shell { grid-template-columns: 52px 1fr; grid-template-areas: "brand topbar" "tabs main"; }
        .tab-item span { display: none; }
        .tab-section { display: none; }
      }
