/* =========================================================
   TopBar Widgets — 右上角工具列元件樣式
   搭配 erp-topbar-widgets.jsx 的 window.TopBarWidgets 使用。
   顏色一律吃 tokens.css 的語意變數，深色模式不必另外覆寫。
   ========================================================= */

/* ── 圖示按鈕語意重置（<button> 版；尺寸與既有 .tbar-icon-btn 對齊）── */
.tbar-icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0;
  font: inherit;
  appearance: none;
  transition: background var(--dur-micro), color var(--dur-micro);
}
.tbar-icon-btn:hover { background: var(--surface-hover); color: var(--fg); }
.tbar-icon-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.tbar-icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tbar-icon-btn .dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 6px; height: 6px;
  background: var(--danger);
  border-radius: 999px;
  border: 2px solid var(--surface);
}

/* ── 重新整理旋轉動畫 ── */
@keyframes kx-spin-rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.kx-spin { animation: kx-spin-rotate 600ms linear; }

/* ── 字型大小調整 ── */
.tbar-fontsize {
  display: flex; align-items: center; gap: 2px;
  height: 34px; padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-sizing: border-box;
}
.tbar-fontsize-btn {
  width: 26px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  border-radius: var(--radius-xs);
  color: var(--fg-muted);
  font-family: var(--font-sans); font-weight: var(--fw-semibold); font-size: 12px;
  cursor: pointer;
  transition: background var(--dur-micro), color var(--dur-micro);
}
.tbar-fontsize-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--fg); }
.tbar-fontsize-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.tbar-fontsize-value {
  min-width: 20px;
  text-align: center;
  font-size: 11px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* ── 彈出層共用外殼 ── */
.tbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.tbar-popover-anchor { position: relative; display: flex; }
.tbar-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 200;
  width: 300px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  box-sizing: border-box;
}
.tbar-popover-title {
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  color: var(--fg-strong);
  margin-bottom: 8px;
}
.tbar-popover-title-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.tbar-popover-title-row .tbar-popover-title { margin-bottom: 0; }
.tbar-popover-section + .tbar-popover-section { margin-top: 12px; }
.tbar-popover-label {
  font-size: var(--fs-caption);
  color: var(--fg-muted);
  margin-bottom: 6px;
}
.tbar-popover-link {
  display: inline-block;
  border: none; background: transparent;
  color: var(--primary);
  font-size: var(--fs-label);
  font-weight: var(--fw-medium);
  cursor: pointer;
  padding: 4px 0;
}
.tbar-popover-link:hover:not(:disabled) { color: var(--primary-hover); text-decoration: underline; }
.tbar-popover-link:disabled { color: var(--fg-subtle); cursor: not-allowed; }
.tbar-empty {
  padding: 12px 0;
  text-align: center;
  color: var(--fg-subtle);
  font-size: var(--fs-caption);
}

/* ── 風格設定：主題 / 導覽 / 密度切換膠囊 ── */
.tbar-toggle-pair { display: flex; gap: 6px; }
.tbar-toggle-pill {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--fg-muted);
  font-size: var(--fs-caption);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--dur-micro), color var(--dur-micro), border-color var(--dur-micro);
}
.tbar-toggle-pill:hover { background: var(--surface-hover); }
.tbar-toggle-pill.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-press);
  font-weight: var(--fw-medium);
}

/* ── 行事曆 / 今日日程 ── */
.tbar-cal-summary { display: flex; gap: 8px; margin-bottom: 10px; }
.tbar-cal-summary-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
}
.tbar-cal-summary-num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-h3);
  font-weight: var(--fw-semibold);
  color: var(--fg-strong);
}
.tbar-cal-summary-label { font-size: var(--fs-caption); color: var(--fg-muted); }
.tbar-cal-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 200px; overflow-y: auto;
  margin-bottom: 8px;
}
.tbar-cal-card {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: var(--fs-caption);
}
.tbar-cal-card-code { font-weight: var(--fw-medium); color: var(--fg); white-space: nowrap; }
.tbar-cal-card-customer { flex: 1; min-width: 0; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbar-cal-card-due { color: var(--danger); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── 系統通知 ── */
.tbar-notif-list { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow-y: auto; }
.tbar-notif-item { display: flex; gap: 8px; padding: 8px; border-radius: var(--radius-md); }
.tbar-notif-item.unread { background: var(--primary-soft); }
.tbar-notif-item-dot {
  flex: 0 0 auto;
  width: 6px; height: 6px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--primary);
  visibility: hidden;
}
.tbar-notif-item.unread .tbar-notif-item-dot { visibility: visible; }
.tbar-notif-item-body { flex: 1; min-width: 0; }
.tbar-notif-item-title { font-size: var(--fs-label); font-weight: var(--fw-medium); color: var(--fg-strong); }
.tbar-notif-item-message { font-size: var(--fs-caption); color: var(--fg-muted); margin-top: 2px; }
.tbar-notif-item-time { font-size: 11px; color: var(--fg-subtle); margin-top: 4px; }
