:root {
  --card-bg: rgba(255,255,255,0.82);
  --card-border: rgba(255,255,255,0.6);
  --text: #1f2d3d;
  --text-sub: #5b6b7b;
  --accent: #2b7de9;
  --accent-soft: rgba(43,125,233,0.12);
  --shadow: 0 18px 50px rgba(30,50,80,0.28);
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}

#bg {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(160deg, #7fc3ff 0%, #a9dcff 28%, #cdeeff 55%, #eaf7ff 100%);
  transition: background 1.2s ease;
}
#bg.night { background: linear-gradient(160deg, #14213d 0%, #1d3557 40%, #26456e 100%); }
#bg.rain  { background: linear-gradient(160deg, #4b6a8a 0%, #6d87a3 45%, #8fa8c0 100%); }
#bg.rain.night { background: linear-gradient(160deg, #1a2330 0%, #28374c 50%, #3b4f69 100%); }
#bg.dusk  { background: linear-gradient(160deg, #6a5b8c 0%, #c07a6a 55%, #f2b27a 100%); }
#bg.fog   { background: linear-gradient(160deg, #99a8b5 0%, #c3cfd9 60%, #dde5ec 100%); }

.widget {
  position: fixed; z-index: 10;
  top: 26px; bottom: 26px; left: 50%;
  transform: translateX(-50%);
  width: min(calc(100vw - 52px), 1540px);
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 460px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "header header" "main side" "footer footer";
  overflow: hidden;
}
.widget.pinned { z-index: 9999; }
.main-col { grid-area: main; overflow-y: auto; padding: 16px 36px 32px; min-width: 0; }
.side-col {
  grid-area: side; overflow-y: auto; padding: 18px 20px;
  border-left: 1px solid rgba(0,0,0,.07);
  background: rgba(255,255,255,.35);
}

#restoreBtn {
  position: fixed; z-index: 2000; right: 20px; bottom: 20px;
  width: 52px; height: 52px; border-radius: 50%;
  border: none; font-size: 24px; cursor: pointer;
  background: var(--card-bg); box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
#restoreBtn[hidden] { display: none; }

/* header */
.widget-header {
  grid-area: header;
  padding: 14px 24px 12px;
  cursor: default;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid rgba(0,0,0,.05);
}
.loc-meta { display: flex; align-items: baseline; gap: 8px; }
.loc-name { font-size: 20px; font-weight: 700; }
.loc-sub { font-size: 12px; color: var(--text-sub); }
.source-tag {
  margin-left: 8px; font-size: 10px; padding: 2px 7px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.source-tag.warn { background: rgba(240,150,40,.15); color: #c07a10; }

.win-controls { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 15px; color: var(--text-sub); width: 30px; height: 30px;
  border-radius: 10px; transition: .15s;
}
.icon-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
.icon-btn.ai-toggle {
  font-weight: 700; font-size: 12px; letter-spacing: .5px;
  background: linear-gradient(135deg,#2b7de9,#7a5cff); color: #fff;
}
.icon-btn.ai-toggle:hover { filter: brightness(1.08); }
.icon-btn.pinned-on { color: var(--accent); font-size: 17px; }

/* search */
.search-row { position: relative; padding: 0 14px 10px; display: flex; gap: 8px; }
#searchInput {
  flex: 1; border: 1px solid rgba(0,0,0,.08); background: rgba(255,255,255,.7);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; color: var(--text);
  outline: none; -webkit-user-select: text; user-select: text;
}
#searchInput:focus { border-color: var(--accent); }
#searchBtn {
  border: none; border-radius: 10px; padding: 0 16px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 13px;
}
#searchBtn:hover { filter: brightness(1.06); }
.search-results {
  position: absolute; top: 100%; left: 14px; right: 14px; z-index: 50;
  background: #fff; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18);
  max-height: 240px; overflow: auto; display: none;
}
.search-results.show { display: block; }
.sr-item { padding: 10px 14px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f0f2f5; }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--accent-soft); }
.sr-item .sr-name { font-weight: 600; }
.sr-item .sr-sub { font-size: 11px; color: var(--text-sub); margin-left: 6px; }
.sr-empty { padding: 12px 14px; font-size: 12px; color: var(--text-sub); }

.quick-cities { padding: 0 14px 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.qc {
  font-size: 11px; padding: 4px 10px; border-radius: 20px; cursor: pointer;
  background: rgba(255,255,255,.6); border: 1px solid rgba(0,0,0,.06); color: var(--text-sub);
}
.qc:hover { border-color: var(--accent); color: var(--accent); }

/* current */
.current { padding: 4px 16px 12px; }
.current-main { display: flex; align-items: center; gap: 16px; }
.big-icon { font-size: 66px; line-height: 1; }
.cur-temp-num { font-size: 58px; font-weight: 700; letter-spacing: -1px; }
.cur-temp .unit { font-size: 20px; color: var(--text-sub); }
.cur-desc { font-size: 15px; font-weight: 600; margin-top: 2px; }
.cur-feel { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.cur-metrics {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px;
}
.cm { text-align: center; padding: 8px 2px; border-radius: var(--radius-sm); background: rgba(255,255,255,.55); }
.cm .cm-ico { font-size: 15px; }
.cm .cm-val { font-size: 13px; font-weight: 700; margin-top: 2px; }
.cm .cm-lab { font-size: 10px; color: var(--text-sub); }

/* rain bars */
.rain { padding: 0 16px 6px; }
.sec-title { font-size: 12px; font-weight: 700; color: var(--text-sub); margin: 0 0 8px; }
.sec-hint { font-weight: 400; color: var(--text-sub); font-size: 11px; margin-left: 6px; }
.rain-bars { display: flex; gap: 5px; align-items: flex-end; height: 64px; }
.rb { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.rb .bar {
  width: 100%; max-width: 22px; border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg,#4aa3ff,#2b7de9); min-height: 3px;
  transition: height .3s;
}
.rb .bar.dry { background: #dbe7f5; }
.rb .lbl { font-size: 9px; color: var(--text-sub); margin-top: 3px; }
.rb:hover .bar { filter: brightness(0.9); }

/* hourly */
.hourly { padding: 4px 16px 8px; }
.hourly-strip { display: flex; gap: 2px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.hourly-strip::-webkit-scrollbar { height: 5px; }
.hourly-strip::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 5px; }
.hc {
  flex: 0 0 56px; text-align: center; padding: 8px 2px; border-radius: 10px;
  background: rgba(255,255,255,.45);
}
.hc.now { background: var(--accent-soft); outline: 1px solid var(--accent); }
.hc .h-t { font-size: 11px; color: var(--text-sub); }
.hc .h-t.now-txt { color: var(--accent); font-weight: 700; }
.hc .h-ico { font-size: 18px; margin: 3px 0; }
.hc .h-temp { font-size: 13px; font-weight: 700; }
.hc .h-rain { font-size: 9px; color: #2b7de9; min-height: 12px; }

/* advice / offduty */
.advice { margin: 0 16px 10px; padding: 12px 14px; border-radius: var(--radius-sm); background: linear-gradient(135deg, rgba(122,92,255,.12), rgba(43,125,233,.12)); }
.advice .ad-title { font-size: 12px; font-weight: 700; color: #6a4fd0; margin-bottom: 5px; }
.advice .ad-text { font-size: 13px; line-height: 1.6; }
.offduty { margin: 0 16px 10px; padding: 12px 14px; border-radius: var(--radius-sm); background: rgba(255,200,80,.18); }
.offduty .od-title { font-size: 12px; font-weight: 700; color: #b87800; margin-bottom: 4px; }
.offduty .od-text { font-size: 13px; line-height: 1.6; }

/* actions */
.action-row { display: flex; gap: 8px; padding: 0 16px 12px; }
.action-btn {
  flex: 1; padding: 9px 4px; border-radius: 10px; border: 1px solid rgba(0,0,0,.08);
  background: rgba(255,255,255,.6); cursor: pointer; font-size: 12px; color: var(--text); white-space: nowrap;
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* panels */
.panel { padding: 2px 0 12px; }
.panel[hidden] { display: none; }
.panel-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.loading { text-align: center; color: var(--text-sub); font-size: 13px; padding: 30px 0; }

/* daily list */
.daily-list { display: flex; flex-direction: column; }
.dl { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid #f0f2f5; }
.dl:last-child { border-bottom: none; }
.dl .d-date { flex: 0 0 68px; font-size: 12px; color: var(--text-sub); }
.dl .d-ico { font-size: 20px; flex: 0 0 28px; text-align: center; }
.dl .d-desc { flex: 1; font-size: 12px; }
.dl .d-rain { font-size: 10px; color: #2b7de9; }
.dl .d-wind { font-size: 10px; color: var(--text-sub); margin-left: auto; flex: 0 0 auto; text-align: right; }
.dl .d-temp { flex: 0 0 64px; text-align: right; font-size: 12px; font-weight: 700; }
.dl .d-temp .lo { color: var(--text-sub); font-weight: 400; }

/* detail */
.detail-hourly {
  display: grid; grid-template-columns: 1fr; max-height: 300px; overflow: auto;
  border-radius: 10px; background: rgba(255,255,255,.5);
}
.dh { display: grid; grid-template-columns: 52px 30px 1fr 40px 56px 44px; gap: 6px; align-items: center; padding: 7px 10px; font-size: 12px; border-bottom: 1px solid #f0f2f5; }
.dh:last-child { border-bottom: none; }
.dh .hd { color: var(--text-sub); }
.dh.now-row { background: var(--accent-soft); }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.dg { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.55); }
.dg .dg-lab { font-size: 11px; color: var(--text-sub); }
.dg .dg-val { font-size: 14px; font-weight: 700; margin-top: 3px; }
.dg .dg-sub { font-size: 10px; color: var(--text-sub); margin-top: 2px; }
.detail-tips { margin-top: 12px; font-size: 12px; line-height: 1.7; color: var(--text-sub); }

/* AI */
.ai-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.ai-head .panel-title { margin-bottom: 0; }
.mini-btn { border: none; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 5px 12px; cursor: pointer; font-size: 12px; }
.ai-tabs { display: flex; flex-wrap: wrap; gap: 6px 4px; padding-bottom: 8px; }
.aid-tab {
  padding: 6px 11px; border-radius: 20px; border: 1px solid rgba(0,0,0,.08);
  background: rgba(255,255,255,.55); cursor: pointer; font-size: 12px; white-space: nowrap; color: var(--text-sub);
}
.aid-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.ai-content { font-size: 13px; }
.dc-card { padding: 11px 13px; border-radius: 10px; background: rgba(255,255,255,.6); margin-bottom: 8px; }
.dc-card .dc-t { font-weight: 700; font-size: 13px; }
.dc-card .dc-t .lvl { float: right; font-size: 11px; padding: 1px 8px; border-radius: 12px; color: #fff; }
.dc-card .dc-s { font-size: 12px; color: var(--text-sub); margin-top: 3px; line-height: 1.6; }
.lvl.l0 { background:#4caf50; } .lvl.l1 { background:#8bc34a; }
.lvl.l2 { background:#ffc107; color:#5b4a00 !important; }
.lvl.l3 { background:#ff9800; } .lvl.l4 { background:#f44336; }

.index-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.idx-card { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.6); }
.idx-card .idx-t { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.idx-card .idx-info { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 10px; }
.idx-card .idx-s { font-size: 11px; color: var(--text-sub); margin-top: 4px; line-height: 1.6; }

.win-card { padding: 11px 13px; border-radius: 10px; background: rgba(255,255,255,.6); margin-bottom: 8px; }
.win-card .w-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.win-card .w-score { margin-left: auto; font-size: 11px; color: #fff; background: var(--accent); padding: 2px 9px; border-radius: 12px; }
.win-card .w-time { font-size: 12px; color: var(--text-sub); }
.win-card .w-reason { font-size: 12px; color: var(--text-sub); margin-top: 4px; line-height: 1.6; }

.ai-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.ai-form label { font-size: 12px; color: var(--text-sub); }
.ai-form input, .ai-form select {
  border: 1px solid rgba(0,0,0,.08); border-radius: 9px; padding: 9px 11px; font-size: 13px; outline: none;
  -webkit-user-select: text; user-select: text; background: rgba(255,255,255,.85);
}
.ai-form .form-row { display: flex; gap: 8px; }
.ai-form .form-row > * { flex: 1; }
.primary-btn {
  border: none; border-radius: 10px; padding: 10px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
}
.primary-btn:hover { filter: brightness(1.06); }
.ghost-btn {
  border: 1px solid rgba(0,0,0,.12); border-radius: 10px; padding: 8px; cursor: pointer;
  background: rgba(255,255,255,.6); color: var(--text-sub); font-size: 12px;
}

.chat-box { max-height: 260px; overflow: auto; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 9px 11px; border-radius: 12px; font-size: 13px; line-height: 1.6; max-width: 90%; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.ai { align-self: flex-start; background: rgba(255,255,255,.8); -webkit-user-select: text; user-select: text; }
.msg.sys { align-self: center; font-size: 11px; color: var(--text-sub); background: transparent; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; }

.prof-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pf-card { padding: 11px; border-radius: 10px; background: rgba(255,255,255,.6); cursor: pointer; border: 1px solid transparent; }
.pf-card.on { border-color: var(--accent); background: var(--accent-soft); }
.pf-card .pf-t { font-weight: 700; font-size: 13px; }
.pf-card .pf-s { font-size: 11px; color: var(--text-sub); margin-top: 3px; }

.settings-body { display: flex; flex-direction: column; gap: 10px; }
.settings-body label { font-size: 12px; color: var(--text-sub); }
.settings-body select, .settings-body input {
  border: 1px solid rgba(0,0,0,.08); border-radius: 9px; padding: 9px 11px; font-size: 13px; outline: none;
  background: rgba(255,255,255,.85); -webkit-user-select: text; user-select: text;
}
.set-note { font-size: 11px; color: var(--text-sub); line-height: 1.6; }
.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch { position: relative; width: 42px; height: 24px; border-radius: 20px; background: #d3dbe2; cursor: pointer; transition: .2s; }
.switch.on { background: var(--accent); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
.switch.on::after { left: 21px; }

/* confidence */
.conf-box { font-size: 12px; line-height: 1.7; }
.conf-src { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 9px; background: rgba(255,255,255,.55); margin-bottom: 6px; }
.conf-ok { width: 9px; height: 9px; border-radius: 50%; background: #4caf50; }
.conf-fail { width: 9px; height: 9px; border-radius: 50%; background: #f44336; }
.conf-bar { height: 8px; border-radius: 5px; background: #edf1f5; overflow: hidden; margin-top: 6px; }
.conf-bar > i { display: block; height: 100%; background: linear-gradient(90deg,#ffc107,#4caf50); border-radius: 5px; }

/* timeline */
.tl { position: relative; padding-left: 24px; }
.tl::before { content: ""; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: #dbe3ec; }
.tl-item { position: relative; padding: 6px 0 10px; }
.tl-item::before { content: ""; position: absolute; left: -21px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(43,125,233,.2); }
.tl-item .tl-t { font-weight: 700; font-size: 13px; }
.tl-item .tl-s { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.warn-card { padding: 11px 13px; border-radius: 10px; margin-bottom: 8px; color: #fff; }
.warn-card.red { background: linear-gradient(135deg,#f44336,#e91e63); }
.warn-card.orange { background: linear-gradient(135deg,#ff9800,#ff5722); }
.warn-card.yellow { background: linear-gradient(135deg,#ffc107,#ff9800); color:#5b4a00; }
.warn-card.blue { background: linear-gradient(135deg,#2196f3,#3f51b5); }
.warn-card .w-t { font-weight: 700; font-size: 13px; }
.warn-card .w-s { font-size: 12px; margin-top: 3px; line-height: 1.6; }

/* footer */
.footer { grid-area: footer; padding: 10px 24px; font-size: 10px; color: var(--text-sub); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; border-top: 1px solid rgba(0,0,0,.05); }
.footer a { color: var(--accent); text-decoration: none; }

.tip-callout { font-size: 11px; color: var(--text-sub); background: rgba(0,0,0,.03); border-radius: 8px; padding: 7px 10px; margin-top: 8px; line-height: 1.5; }

@media (max-width: 899px) {
  body { overflow: auto; }
  .widget {
    position: static; transform: none; width: 100%; height: auto; min-height: 100vh;
    border-radius: 0; border: none; box-shadow: none;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "header" "main" "side" "footer";
    overflow: visible;
  }
  .main-col { overflow: visible; padding: 8px 16px 16px; }
  .side-col { overflow: visible; border-left: none; border-top: 1px solid rgba(0,0,0,.07); padding: 16px; }
  .widget-header { padding: 12px 16px 10px; flex-wrap: wrap; gap: 8px; }
  .footer { padding: 10px 16px; }
}
@media (max-width: 480px) {
  .cur-metrics { grid-template-columns: repeat(2, 1fr); }
  .big-icon { font-size: 46px; }
  .cur-temp-num { font-size: 44px; }
}