/* 左右邊距跟 header 共用 --clc-pad（手機 16、≥640 起 24） */
#dx-main { padding-inline: var(--clc-pad, 16px); }
@media (min-width: 640px) { #dx-main { padding-inline: var(--clc-pad, 24px); } }

.widget-grid[data-dashboard-grid] {
  display: grid;
  grid-template-columns: repeat(var(--widget-columns), minmax(0, 1fr));
  grid-auto-rows: 48px;
  gap: 12px;
  align-items: stretch;
  position: relative;
}

.widget-grid > .dash-widget {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 24px 14px 20px;
}

.widget-content {
  height: 100%;
  min-width: 0;
  overflow: auto;
  overscroll-behavior-y: contain;
  padding: 2px 3px 6px;
}

[data-widget="todo"] > .widget-content,
[data-widget="clock"] > .widget-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.widget-grid > [data-widget="apps"] { padding: 10px 14px 12px; }
[data-widget="apps"] > .widget-content > .slot-grid {
  margin: 3px 4px 0;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 82px));
}
@media (min-width: 1024px) {
  [data-widget="apps"] > .widget-content > .slot-grid {
    grid-template-columns: repeat(auto-fill, minmax(0, 82px));
  }
}
[data-widget="apps"] .is-app-add-target { border-color: #007e8a; }
.widget-app-heading {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding-inline: 4px;
}
.widget-app-heading h2 { margin: 0; min-width: 0; }
.widget-app-heading h2:has(.widget-heading-input) { flex: 1; }
.widget-app-add {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #597386;
}
.widget-app-add::before {
  content: "";
  width: 11px;
  height: 11px;
  background: linear-gradient(currentColor, currentColor) center / 100% 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) center / 1.5px 100% no-repeat;
  transition: scale 120ms ease-out;
}
.dark .widget-app-add { color: #a3b4c6; }
.widget-app-add[hidden] { display: none; }
.widget-app-add:disabled { opacity: .4; }
@media (hover: hover) { .widget-app-add:not(:disabled):hover::before { scale: 1.25; } }
@media (prefers-reduced-motion: reduce) { .widget-app-add::before { transition: none; } }
.widget-app-heading > .slot-cancel { margin-inline-start: auto; }
.app-dialog.is-slot-anchored {
  position: fixed;
  inset: auto;
  margin: 0;
  max-height: calc(100dvh - 16px);
  overflow: auto;
}
.widget-content .todo-add-input { resize: none; margin: 4px 0; }

.widget-heading {
  color: inherit;
  font: inherit;
  text-align: start;
  overflow-wrap: anywhere;
  cursor: text;
  border-radius: 4px;
}
.widget-content h2:has(.widget-heading-input) { min-width: 0; }
.widget-heading-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 1px 6px;
  border: 1px solid #6b8c9b;
  border-radius: 6px;
  background: #fff;
  color: inherit;
  font: inherit;
  outline: none;
}
.dark .widget-heading-input { border-color: #4b687b; background: #202734; }
.widget-heading-input:focus { border-color: #007e8a; }
.dark .widget-heading-input:focus { border-color: #54a8b2; }
.widget-heading:focus-visible, .widget-resize:focus-visible { outline: 2px solid #00A3B4; }
.widget-resize {
  position: absolute;
  z-index: 3;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  touch-action: none;
}
.widget-resize:is([data-edge="n"], [data-edge="s"]) { left: 12px; right: 12px; height: 10px; }
.widget-resize:is([data-edge="e"], [data-edge="w"]) { top: 12px; bottom: 12px; width: 10px; }
.widget-resize:is([data-edge="ne"], [data-edge="se"], [data-edge="sw"], [data-edge="nw"]) { width: 16px; height: 16px; }
.widget-resize[data-edge^="n"] { top: -4px; }
.widget-resize[data-edge^="s"] { bottom: -4px; }
.widget-resize[data-edge$="e"] { right: -4px; }
.widget-resize[data-edge$="w"] { left: -4px; }
.widget-resize:is([data-edge="n"], [data-edge="s"]),
.widget-grid .is-resizing:is([data-resize-edge="n"], [data-resize-edge="s"]) { cursor: ns-resize; }
.widget-resize:is([data-edge="e"], [data-edge="w"]),
.widget-grid .is-resizing:is([data-resize-edge="e"], [data-resize-edge="w"]) { cursor: ew-resize; }
.widget-resize:is([data-edge="ne"], [data-edge="sw"]),
.widget-grid .is-resizing:is([data-resize-edge="ne"], [data-resize-edge="sw"]) { cursor: nesw-resize; }
.widget-resize:is([data-edge="nw"], [data-edge="se"]),
.widget-grid .is-resizing:is([data-resize-edge="nw"], [data-resize-edge="se"]) { cursor: nwse-resize; }
[data-widget="todo"] > .widget-content { overflow: hidden; }
[data-widget="todo"] > .widget-content > :not(.todo-scroll) { flex-shrink: 0; }
.todo-scroll {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior-y: contain;
  padding: 2px 4px;
  cursor: auto;
}
.todo-scroll .todo-row.reorder-source { opacity: 0; }
.todo-scroll .todo-row { transition: translate 220ms cubic-bezier(.2,.75,.25,1); }
@media (prefers-reduced-motion: reduce) {
  .todo-scroll .todo-row.reorder-source { opacity: 0; }
.todo-scroll .todo-row { transition: none; }
}
/* 區塊移動把手 */
.drag-handle { position:absolute; top:0; left:50%; transform:translateX(-50%); width:56px; height:22px; display:flex; align-items:center; justify-content:center; background:none; border:0; padding:0; cursor:grab; touch-action:none; z-index:2; }
.drag-handle:focus-visible { outline:2px solid #00A3B4; border-radius:8px; }
.dash-widget.is-dragging { z-index:30; box-shadow:0 18px 40px rgba(0,0,0,.35); }
.dash-widget.is-resizing { z-index:30; }
body.dash-dragging { user-select:none; -webkit-user-select:none; }
.widget-grid .drag-handle { touch-action: auto; }
.widget-grid .drag-handle:focus-visible::after { content: "↕"; }
.widget-grid .widget-resize { opacity: 0; transition: opacity 140ms ease; }
.widget-grid .widget-resize:focus-visible,
.widget-grid .is-widget-selected > .widget-resize,
.widget-grid .is-resizing > .widget-resize { opacity: 1; }
.widget-grid .is-dragging, .widget-grid .is-dragging * { cursor: grabbing; }
@media (hover: hover) {
  .widget-grid .dash-widget { cursor: grab; }
  .widget-grid .dash-widget:hover:not(.is-widget-selected) {
    outline: 1px solid #8b9aab4d;
    outline-offset: 2px;
    border-radius: 24px;
  }
  .widget-grid :is(a, button:not(.drag-handle, .widget-resize, .widget-heading)) { cursor: pointer; }
  .widget-grid :is(.widget-heading, textarea, input:not([type="checkbox"])) { cursor: text; }
  .widget-grid .is-dragging { cursor: grabbing; }
  .widget-grid .dash-widget:hover > .widget-resize { opacity: 1; }
}
@media (pointer: coarse) {
  .widget-grid .widget-resize:not(:focus-visible) { pointer-events: none; }
  .widget-grid .is-widget-selected > .widget-resize { pointer-events: auto; }
  .widget-grid .dash-widget { -webkit-touch-callout: none; }
}

.widget-context-menu {
  position: fixed;
  z-index: 1100;
  display: grid;
  padding: 7.5px 0;
}
.widget-context-menu[hidden] { display: none; }
.widget-context-menu > button { text-align: start; font-weight: 600; }
.widget-context-menu button:is(:focus-visible, :hover) { background: #f1f5f9; outline: none; }
.dark .widget-context-menu button:is(:focus-visible, :hover) { background: #ffffff0d; }

.widget-grid > .dash-widget[hidden] { display: none !important; }
.widget-empty-button {
  align-self: flex-start;
  border-radius: 10px;
  padding: 8px 14px;
  background: #007E8A;
  color: white;
}
.widget-empty-button[hidden] { display: none; }
.widget-context-menu {
  max-width: calc(100vw - 8px);
  max-height: calc(100dvh - 8px);
  overflow: auto;
}
.widget-context-menu .widget-menu-delete { color: #e11d48; font-weight: 700; }
.dark .widget-context-menu .widget-menu-delete { color: #fb7185; }

.widget-grid .is-widget-selected {
  outline: 2px solid #8796a5;
  outline-offset: 4px;
  border-radius: 24px;
}
.widget-drawer-handle {
  position: absolute;
  z-index: 4;
  inset: auto auto 0 50%;
  translate: -50% 0;
  display: grid;
  place-items: center;
  width: 76px;
  height: 23px;
  border: 0;
  background: transparent;
  color: #64748b;
  cursor: pointer;
}
.widget-drawer-handle::before {
  content: "";
  width: 33px;
  height: 4px;
  border-radius: 9px;
  background: currentColor;
}
.widget-drawer-handle[hidden] { display: none; }
.dark .widget-drawer-handle { color: #9ba6b8; }

.widget-drawer[open] {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  max-height: none;
  height: 100dvh;
  margin: 0;
  padding: max(18px, env(safe-area-inset-top)) 16px max(38px, calc(env(safe-area-inset-bottom) + 32px));
  background: #fff;
  color: #0f172a;
  overflow: hidden;
}
.dark .widget-drawer { background: #161924; color: #f1f5f9; }
body:has(.widget-drawer[open]) { overflow: hidden; }
.widget-drawer > .widget-drawer-handle {
  bottom: env(safe-area-inset-bottom);
  height: 34px;
}
.widget-drawer[data-widget="apps"] > .widget-content > .slot-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1023px) {
  .widget-grid[data-dashboard-grid] { grid-auto-rows: auto; gap: 24px; }
  .widget-grid > .dash-widget:not([data-widget="clock"]) { height: var(--mobile-height); }
  .widget-grid > [data-widget="clock"] {
    padding: 18px 16px calc(18px + var(--clock-height-extra, 0px));
  }
  .widget-grid > [data-widget="clock"] > .widget-content { height: auto; padding: 0; }
  .widget-grid > .dash-widget > .widget-content,
  .widget-grid .todo-scroll { overflow: clip; }
  .widget-grid > .dash-widget.has-open-drawer { min-height: var(--drawer-collapsed-height, 0px); }
  .widget-resize:is([data-edge="e"], [data-edge="w"]) { display: none; }
  .widget-resize:is([data-edge^="n"], [data-edge^="s"]) { cursor: ns-resize; }
  .widget-resize[data-edge="s"] { left: 12px; right: 12px; bottom: -8px; }

}
.widget-context-menu.is-card-popup {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  padding: 4px 0 7.5px;
}
.widget-popup-title {
  grid-column: 1 / -1;
  margin: 0;
  padding: 7.5px 15px;
  text-align: center;
  color: #64748b;
  font-size: 11.25px;
  line-height: 15px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.dark .widget-popup-title { color: #94a3b8; }
.widget-context-menu.is-card-popup button { text-align: center; min-height: 44px; }
.widget-context-menu.is-card-popup button:last-child:nth-child(4) { grid-column: 1 / -1; }
.widget-popup-title { border-bottom: 1px solid #93a1b533; }
.widget-context-menu.is-card-popup :is(.widget-menu-add, .widget-menu-delete)::before {
  display: block;
  margin: 2px auto 3px;
  line-height: 18px;
  font-size: 20px;
}
.widget-context-menu.is-card-popup .widget-menu-add::before { content: "+" / ""; }
.widget-context-menu.is-card-popup .widget-menu-delete::before {
  content: "" / "";
  width: 12px;
  height: 15px;
  margin-top: 4px;
  margin-bottom: 4px;
  border: 2px solid currentColor;
  border-radius: 1px 1px 3px 3px;
  box-shadow: 0 -3px 0 -1px currentColor;
}

@media (min-width: 1024px) {
  .widget-grid :is(.widget-content, .todo-scroll) { overscroll-behavior-y: auto; }
  .widget-grid > .is-compact-clock { padding: 16px; }
  .is-compact-clock > .widget-content {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
    align-items: center;
    gap: 12px;
    padding: 0;
    container-type: inline-size;
  }
  .is-compact-clock .clock-weather {
    min-width: 0;
    border-top: 0;
    border-left: 1px solid #94a3b840;
    padding: 0 0 0 12px;
    gap: 8px;
  }
  .is-compact-clock .clock-main { min-width: 0; }
  .is-compact-clock :is(#clockTime, [data-widget-field="clockTime"]) { font-size: clamp(30px, 11cqi, 54px); }
  .is-compact-clock :is(#clockSec, [data-widget-field="clockSec"]) { font-size: clamp(12px, 4cqi, 20px); }
  .is-compact-clock :is(#clockDate, [data-widget-field="clockDate"]) { font-size: 12px; line-height: 1.45; }
  .is-compact-clock :is(#wxIcon, [data-widget-field="wxIcon"]) { width: 25px; height: 25px; }
  .is-compact-clock .clock-weather > div:last-child > p:first-child { flex-wrap: wrap; gap: 3px 7px; }
  .is-compact-clock :is(#wxTemp, [data-widget-field="wxTemp"]) { font-size: 26px; }
  .is-compact-clock :is(#wxDesc, [data-widget-field="wxDesc"]) { font-size: 13px; }
  .is-compact-clock :is(#wxMeta, [data-widget-field="wxMeta"]) { font-size: 11px; line-height: 1.45; }
  .is-compact-clock .clock-weather-detail { display: block; }
  .is-compact-clock .clock-weather-detail:first-child { font-weight: 600; }
  .is-compact-clock .clock-weather-separator { display: none; }
  .is-compact-clock :is(#wxRefresh, [data-widget-field="wxRefresh"]) { font-size: 11px; padding: 4px 6px; }
}
