/* UI overlay — safe to edit; Excel re-export does not touch this file */

/* ── 深色（預設）── */
:root,
html[data-theme="dark"] {
  --ui-bg: #0f1117;
  --ui-surface: #1a1d27;
  --ui-header: #0a0e18;
  --ui-header-accent: #151b2e;
  --ui-primary: #4d9fff;
  --ui-primary-hover: #7ab8ff;
  --ui-text: #e8ecf4;
  --ui-text-muted: #9aa3b8;
  --ui-border: #2a3042;
  --ui-tab-active: #2563b8;
  --ui-tab-hover: #222838;
  --ui-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --ui-radius: 8px;
  --ui-font: "Microsoft JhengHei UI", "微軟正黑體", system-ui, sans-serif;

  --sheet-page-bg: #0d0f14;
  --sheet-table-bg: #181c26;
  --sheet-cell-bg: #222733;
  --sheet-cell-alt: #2a3040;
  --sheet-text: #f0f3f9;
  --sheet-text-dim: #b8c0d0;
  --sheet-border: #4a5268;
  --sheet-link: #7ec0ff;
  --sheet-link-visited: #d4a8e8;
  --sheet-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  --sheet-title-color: #ffffff;
  --sheet-status-green: #4ade80;
  --sheet-status-red: #ff7b7b;
}

/* ── 淺色 ── */
html[data-theme="light"] {
  --ui-bg: #f0f4f8;
  --ui-surface: #ffffff;
  --ui-header: #0f2b4a;
  --ui-header-accent: #1a4a7a;
  --ui-primary: #1565c0;
  --ui-primary-hover: #0d47a1;
  --ui-text: #1a2332;
  --ui-text-muted: #5a6a7e;
  --ui-border: #d8e2ec;
  --ui-tab-active: #1565c0;
  --ui-tab-hover: #e8f0fa;
  --ui-shadow: 0 1px 3px rgba(15, 43, 74, 0.08);

  --sheet-page-bg: #f5f7fa;
  --sheet-table-bg: #ffffff;
  --sheet-cell-bg: transparent;
  --sheet-cell-alt: transparent;
  --sheet-text: inherit;
  --sheet-text-dim: #5a6a7e;
  --sheet-border: #c5cdd8;
  --sheet-link: #0563c1;
  --sheet-link-visited: #954f72;
  --sheet-shadow: 0 2px 12px rgba(15, 43, 74, 0.08);
  --sheet-title-color: inherit;
  --sheet-status-green: #00b050;
  --sheet-status-red: red;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--ui-font);
  background: var(--ui-bg);
  color: var(--ui-text);
}

/* ── Shell layout ── */

.ui-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.ui-header {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--ui-header) 0%, var(--ui-header-accent) 100%);
  color: #fff;
  padding: 0.75rem 1.25rem;
  box-shadow: var(--ui-shadow);
  border-bottom: 1px solid var(--ui-border);
}

.ui-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 100%;
}

.ui-brand {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.ui-brand-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ui-brand-sub {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.75;
  font-weight: 400;
}

html[data-theme="dark"] .ui-brand-sub {
  color: var(--ui-text-muted);
}

.ui-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.ui-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  font-family: var(--ui-font);
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ui-theme-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.4);
}

.ui-theme-toggle-icon {
  font-size: 0.875rem;
  line-height: 1;
}

.ui-badge {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* ── Navigation tabs ── */

.ui-nav {
  flex-shrink: 0;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
}

.ui-nav-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--ui-border) transparent;
}

.ui-nav-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.75rem;
  gap: 0.375rem;
  min-width: max-content;
}

.ui-nav-item a {
  display: block;
  padding: 0.45rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ui-text-muted);
  text-decoration: none;
  border-radius: var(--ui-radius);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.ui-nav-item a:hover {
  background: var(--ui-tab-hover);
  color: var(--ui-primary);
}

.ui-nav-item.is-active a {
  background: var(--ui-tab-active);
  color: #fff;
}

html[data-theme="dark"] .ui-nav-item.is-active a {
  box-shadow: 0 0 0 1px rgba(77, 159, 255, 0.25);
}

/* ── Content frame ── */

.ui-content {
  flex: 1;
  min-height: 0;
  background: var(--sheet-page-bg);
}

.ui-content iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
  background: var(--sheet-page-bg);
}

/* ── Sheet content (共用) ── */

body.ui-enhanced {
  background: var(--sheet-page-bg) !important;
  overflow-x: auto;
  padding: 0.75rem;
}

body.ui-enhanced > table {
  background: var(--sheet-table-bg);
  border: 1px solid var(--sheet-border);
  border-radius: 6px;
  box-shadow: var(--sheet-shadow);
}

body.ui-enhanced table {
  border-collapse: collapse;
}

body.ui-enhanced td,
body.ui-enhanced th {
  border-color: var(--sheet-border) !important;
}

body.ui-enhanced a:link {
  color: var(--sheet-link) !important;
}

body.ui-enhanced a:visited {
  color: var(--sheet-link-visited) !important;
}

body.ui-enhanced a:hover {
  color: var(--ui-primary-hover) !important;
}

body.ui-enhanced .xl500,
body.ui-enhanced [style*="color:#00B050"],
body.ui-enhanced [style*="color: green"] {
  color: var(--sheet-status-green) !important;
}

body.ui-enhanced .xl511,
body.ui-enhanced [style*="color:red"],
body.ui-enhanced [style*="color: red"] {
  color: var(--sheet-status-red) !important;
}

body.ui-enhanced span[style*="color:#0563C1"] {
  color: var(--sheet-link) !important;
}

/* ── Sheet 深色專用 ── */

html[data-theme="dark"] body.ui-enhanced {
  color: var(--sheet-text) !important;
}

html[data-theme="dark"] body.ui-enhanced .style0,
html[data-theme="dark"] body.ui-enhanced .style16 {
  color: var(--sheet-text) !important;
}

html[data-theme="dark"] body.ui-enhanced .xl504,
html[data-theme="dark"] body.ui-enhanced .xl103,
html[data-theme="dark"] body.ui-enhanced .xl70,
html[data-theme="dark"] body.ui-enhanced .xl71,
html[data-theme="dark"] body.ui-enhanced .xl73 {
  color: var(--sheet-title-color) !important;
  background-color: var(--sheet-cell-alt) !important;
}

html[data-theme="dark"] body.ui-enhanced font[color="#000000"],
html[data-theme="dark"] body.ui-enhanced font[color="black"] {
  color: var(--sheet-text) !important;
}

/* ── Sheet 淺色：保留 Excel 原色，僅加外框 ── */

html[data-theme="light"] body.ui-enhanced {
  color: inherit !important;
}

/* ── Responsive ── */

@media (max-width: 640px) {
  .ui-header {
    padding: 0.625rem 1rem;
  }

  .ui-brand-title {
    font-size: 1rem;
  }

  .ui-theme-toggle-label {
    display: none;
  }

  .ui-badge {
    display: none;
  }

  .ui-nav-list {
    padding: 0.375rem 0.5rem;
  }

  .ui-nav-item a {
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
  }
}
