:root{
      --bg:#f5f5f7;
      --card:rgba(255,255,255,.92);
      --border:rgba(0,0,0,.08);
      --text:rgba(0,0,0,.88);
      --muted:rgba(0,0,0,.58);
      --muted2:rgba(0,0,0,.42);
      --shadow:0 18px 50px rgba(0,0,0,.08);
      --shadow2:0 10px 30px rgba(0,0,0,.07);
      --accent:#0071e3;
      --accent2:#0a84ff;
      --danger:#ff3b30;
      --ok:#34c759;
      --radius:20px;
    }

    *{box-sizing:border-box}
    html,body{height:100%}
    body{
      margin:0;
      font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Microsoft JhengHei", sans-serif;
      background:
        radial-gradient(900px 500px at 20% -10%, rgba(0,113,227,.10), transparent 60%),
        radial-gradient(900px 500px at 90% 10%, rgba(0,0,0,.05), transparent 60%),
        var(--bg);
      color:var(--text);
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    a{color:inherit;text-decoration:none}

    .wrap{
      max-width: 980px;
      margin: 0 auto;
      padding: 18px 14px calc(102px + env(safe-area-inset-bottom));
      min-height: 100%;
      display:flex;
      flex-direction:column;
      gap: 12px;
    }

    /* Top bar */
    .nav{
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap:10px;
      padding: 12px 14px;
      border-radius: 999px;
      background: rgba(255,255,255,.78);
      border: 1px solid var(--border);
      box-shadow: var(--shadow2);
      backdrop-filter: blur(12px);
      position: sticky;
      top: 10px;
      z-index: 10;
    }
    .left{
      display:flex; align-items:center; gap:10px; min-width: 140px;
      white-space: nowrap;
    }
    .mark{
      width: 28px; height: 28px;
      border-radius: 10px;
      background: linear-gradient(180deg, rgba(0,113,227,.95), rgba(10,132,255,.75));
      box-shadow: 0 10px 18px rgba(0,113,227,.20);
      flex: 0 0 auto;
    }
    .brand{
      font-weight: 900;
      letter-spacing: .2px;
      white-space: nowrap;
    }

    .actions{
      display:flex; gap:8px; align-items:center;
      flex-wrap: nowrap;
    }

    .btn{
      display:inline-flex;
      align-items:center;
      justify-content:center;
      padding: 10px 12px;
      border-radius: 999px;
      border: 1px solid rgba(0,0,0,.10);
      background: rgba(255,255,255,.88);
      color: rgba(0,0,0,.78);
      font-weight: 800;
      font-size: 14px;
      white-space: nowrap;          /* ✅ 修正：不讓按鈕文字直排 */
      word-break: keep-all;
      transition: transform .08s ease, background .15s ease, opacity .15s ease;
      -webkit-tap-highlight-color: transparent;
      user-select:none;
    }
    .btn:active{ transform: translateY(1px); }
    .btn.primary{
      background: var(--accent);
      color: #fff;
      border-color: transparent;
      box-shadow: 0 10px 20px rgba(0,113,227,.18);
    }
    .btn.primary:hover{ background: var(--accent2); }
    .btn.danger{
      background: rgba(255,59,48,.10);
      color: rgba(0,0,0,.78);
      border-color: rgba(255,59,48,.18);
    }
    .btn:disabled{ opacity:.45; cursor:not-allowed; }

    /* Status chip */
    .status{
      display:flex; align-items:center; gap:8px;
      padding: 8px 12px;
      border-radius: 999px;
      border: 1px solid rgba(0,0,0,.08);
      background: rgba(0,0,0,.03);
      color: rgba(0,0,0,.72);
      font-weight: 800;
      font-size: 13px;
      white-space: nowrap;
      flex: 0 0 auto;
    }
    .dot{ width: 9px; height: 9px; border-radius:999px; background: rgba(0,0,0,.20); }
    .dot.ok{ background: var(--ok); }
    .dot.busy{ background: var(--accent); }
    .dot.bad{ background: var(--danger); }

    /* ✅ 修正截圖選單問題：小螢幕改兩列（不擠、不直排、不超出） */
    @media (max-width: 620px){
      .nav{
        border-radius: 18px;
        padding: 12px;
        display:grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        gap: 10px;
        align-items:center;
      }
      .left{ grid-column: 1 / 2; grid-row: 1; }
      .status{ grid-column: 2 / 3; grid-row: 1; justify-self:end; }
      .actions{
        grid-column: 1 / 3;
        grid-row: 2;
        justify-content: space-between;
        gap: 8px;
      }
      .btn{
        flex: 1 1 0;
        padding: 12px 10px;
        font-size: 13px;
      }
      .actions a.btn{ text-align:center; }
    }

    /* Chat card */
    .chatCard{
      flex: 1 1 auto;
      border-radius: var(--radius);
      border: 1px solid var(--border);
      background: var(--card);
      box-shadow: var(--shadow);
      overflow:hidden;
      display:flex;
      flex-direction:column;
      min-height: 420px;
      position: relative;
    }
    #chatBox{
      padding: 16px;
      overflow:auto;
      height: 100%;
    }
    .hint{
      padding: 12px 16px;
      border-top: 1px solid rgba(0,0,0,.06);
      background: rgba(0,0,0,.02);
      color: var(--muted);
      font-size: 13px;
      line-height: 1.6;
    }

    /* Empty state */
    .empty{
      position:absolute;
      inset: 0;
      display:flex;
      align-items:center;
      justify-content:center;
      pointer-events:none;
      padding: 24px;
    }
    .emptyCard{
      max-width: 520px;
      width: 100%;
      border-radius: 20px;
      border: 1px dashed rgba(0,0,0,.10);
      background: rgba(255,255,255,.70);
      box-shadow: 0 14px 28px rgba(0,0,0,.06);
      padding: 18px;
      display:flex;
      gap: 14px;
      align-items:center;
    }
    .illus{
      width: 64px; height: 64px;
      border-radius: 18px;
      border: 1px solid rgba(0,0,0,.08);
      background:
        radial-gradient(18px 18px at 30% 35%, rgba(255,255,255,.95), rgba(255,255,255,0) 60%),
        linear-gradient(180deg, rgba(0,113,227,.18), rgba(0,113,227,.06));
      display:grid;
      place-items:center;
      box-shadow: 0 12px 20px rgba(0,113,227,.10);
      flex: 0 0 auto;
      position: relative;
      overflow:hidden;
    }
    .illus:before{
      content:"";
      position:absolute;
      inset:-20%;
      background: radial-gradient(circle at 20% 20%, rgba(255,255,255,.7), transparent 50%);
      transform: rotate(18deg);
      opacity:.8;
    }
    .illus svg{ position: relative; z-index: 1; }
    .emptyTitle{
      margin:0;
      font-weight: 900;
      letter-spacing: -.2px;
      font-size: 16px;
    }
    .emptyDesc{
      margin:6px 0 0;
      color: var(--muted);
      line-height: 1.65;
      font-size: 13px;
    }
    .empty.hide{ display:none; }

    /* Bubbles + fade-in */
    .msg{ display:flex; margin: 10px 0; }
    .msg.mine{ justify-content:flex-end; }

    .bubble{
      max-width: 84%;
      padding: 10px 12px;
      border-radius: 16px;
      border: 1px solid rgba(0,0,0,.08);
      background: rgba(255,255,255,.92);
      line-height: 1.45;
      color: rgba(0,0,0,.85);
      white-space: pre-wrap;
      word-break: break-word;
      box-shadow: 0 10px 22px rgba(0,0,0,.06);
    }
    .mine .bubble{
      border-color: rgba(0,113,227,.20);
      background: rgba(0,113,227,.08);
    }

    @keyframes msgIn {
      from { opacity: 0; transform: translateY(6px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    .msg.new .bubble{
      animation: msgIn .18s ease-out both;
    }

    /* Composer fixed bottom */
    .composer{
      position: fixed;
      left: 0; right: 0; bottom: 0;
      padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
      background: rgba(245,245,247,.78);
      border-top: 1px solid rgba(0,0,0,.06);
      backdrop-filter: blur(12px);
    }
    .composerInner{
      max-width: 980px;
      margin: 0 auto;
      display:flex;
      gap: 10px;
      align-items:center;
    }
    input[type="text"]{
      flex: 1 1 auto;
      padding: 12px 12px;
      border-radius: 16px;
      border: 1px solid rgba(0,0,0,.10);
      background: rgba(255,255,255,.92);
      color: rgba(0,0,0,.86);
      outline: none;

      /* ✅ iOS 不放大關鍵 */
      font-size: 16px;
      -webkit-text-size-adjust: 100%;
      touch-action: manipulation;
    }
    input[type="text"]::placeholder{ color: rgba(0,0,0,.40); }
    input[type="text"]:focus{
      border-color: rgba(0,113,227,.40);
      box-shadow: 0 0 0 3px rgba(0,113,227,.12);
    }

    .send{
      min-width: 110px;
      padding: 12px 14px;
      border-radius: 16px;
      border: 1px solid transparent;
      background: var(--accent);
      color: #fff;
      font-weight: 900;
      font-size: 14px;
      box-shadow: 0 10px 20px rgba(0,113,227,.16);
      touch-action: manipulation;
      display:inline-flex;
      align-items:center;
      justify-content:center;
      gap:10px;
    }
    .send:hover{ background: var(--accent2); }
    .send:disabled{
      background: rgba(0,0,0,.10);
      color: rgba(0,0,0,.35);
      box-shadow: none;
      border: 1px solid rgba(0,0,0,.08);
    }

    /* ✅ loading spinner */
    .spinner{
      width: 14px; height: 14px;
      border-radius: 999px;
      border: 2px solid rgba(255,255,255,.55);
      border-top-color: rgba(255,255,255,1);
      animation: spin .7s linear infinite;
      display:none;
    }
    @keyframes spin { to { transform: rotate(360deg); } }
    .send.loading .spinner{ display:inline-block; }
    .send.loading .sendText{ opacity:.95; }

    @media (max-width: 420px){
      .brand{ font-size: 14px; }
      .bubble{ max-width: 92%; }
      .send{ min-width: 92px; }
    }