/* ============================================
   GDK V1.96 — Apple Design System
   Inspired by macOS / iOS native aesthetics
   ============================================ */

/* --- Custom Font (方正苏新诗柳楷简体) --- */
@font-face {
  font-family: "FangZhengLiuKai";
  src: url("FangZhengSuXinShiLiuKaiJianTi.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* --- Design Tokens --- */
:root {
  /* Apple System Colors — Light / Frosted theme */
  --apple-bg: #f5f5f7;
  --apple-bg-grad-1: #eef1f6;
  --apple-bg-grad-2: #f7f8fa;
  --apple-surface: rgba(255, 255, 255, 0.72);
  --apple-surface2: rgba(255, 255, 255, 0.85);
  --apple-surface3: #e8e8ed;
  --apple-border: rgba(0, 0, 0, 0.10);
  --apple-border-light: rgba(0, 0, 0, 0.16);

  /* Text */
  --apple-text-primary: #1d1d1f;
  --apple-text-secondary: #6b6b6e;
  --apple-text-tertiary: #86868b;
  --apple-text-link: #007aff;

  /* Accent */
  --apple-blue: #007aff;
  --apple-blue-hover: #3395ff;
  --apple-blue-active: #0062cc;
  --apple-green: #34c759;
  --apple-red: #ff3b30;
  --apple-orange: #ff9500;
  --apple-yellow: #ffcc00;

  /* Semantic */
  --old-store-color: #fff2cc;
  --zero-order-color: #ddebf7;

  /* Spacing */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Legacy compat (light) */
  --nav: #ffffff;
  --primary: #007aff;
  --border: rgba(0,0,0,0.10);
  --header: rgba(255,255,255,0.85);
  --manual: #fff9df;
  --text: #1d1d1f;
  --muted: #6b6b6e;
  --bg: #f5f5f7;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 "FangZhengLiuKai", -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  color: var(--apple-text-primary);
  background:
    radial-gradient(1200px 600px at 80% -10%, #e9eefc 0%, transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, #f3eefb 0%, transparent 55%),
    linear-gradient(180deg, var(--apple-bg-grad-1), var(--apple-bg-grad-2));
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Top Navigation Bar (macOS Toolbar style) --- */
.topbar {
  height: 52px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--apple-border);
  color: var(--apple-text-primary);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  color: var(--apple-text-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.2px;
  white-space: nowrap;
  opacity: 0.92;
  transition: opacity 0.2s;
}
.brand:hover { opacity: 1; }

.mainnav {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 2px;
}
.mainnav > a {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--apple-text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.mainnav > a:hover {
  color: var(--apple-text-primary);
  background: rgba(0,0,0,0.04);
}
.mainnav a.active {
  color: var(--apple-text-primary);
  border-bottom-color: var(--apple-blue);
  font-weight: 600;
}

/* --- Page Layout --- */
.page { display: none; padding: 24px 28px 40px; max-width: 1440px; margin: 0 auto; }
.page.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}
.page-heading h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0 0 4px;
  color: var(--apple-text-primary);
}
.page-heading p {
  margin: 0;
  color: var(--apple-text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

/* --- Buttons (Apple HIG) --- */
.btn, input, select {
  font: inherit;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  transition: all 0.15s ease;
}
.btn {
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  font-size: 13px;
  background: var(--apple-surface2);
  color: var(--apple-text-primary);
  border: 0.5px solid var(--apple-border-light);
}
.btn:hover { background: var(--apple-surface3); border-color: rgba(0,0,0,0.25); }
.btn.primary {
  background: var(--apple-blue);
  color: #fff;
  border-color: transparent;
}
.btn.primary:hover { background: var(--apple-blue-hover); }
.btn.primary:active { background: var(--apple-blue-active); }
.btn.quiet { background: transparent; border-color: transparent; }
.btn.quiet:hover { background: rgba(255,255,255,0.08); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

input, select {
  background: var(--apple-surface);
  color: var(--apple-text-primary);
  border: 0.5px solid var(--apple-border);
  padding: 8px 12px;
  min-width: 200px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25);
}

/* --- Sync Card (Glass Card) --- */
.sync-card {
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.sync-fields {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.sync-fields label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: var(--apple-text-secondary);
  font-weight: 500;
}
.sync-fields input {
  min-width: 210px;
  color: var(--apple-text-primary);
}
.last-sync {
  font-weight: 600;
  color: var(--apple-blue);
  margin: 12px 0 0;
  font-size: 13px;
}
.sync-hint {
  font-size: 12px;
  color: var(--apple-text-tertiary);
  margin: 6px 0 4px;
  line-height: 1.55;
}
.notice {
  min-height: 20px;
  color: var(--apple-text-secondary);
  white-space: pre-wrap;
  font-size: 13px;
}

/* --- Summary Cards (Apple Widget Style) --- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.summary-item {
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 0.2s, transform 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.summary-item span {
  display: block;
  color: var(--apple-text-secondary);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
}
.summary-item strong {
  display: block;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--apple-text-primary);
}
.summary-item small {
  display: block;
  color: var(--apple-blue);
  margin-top: 4px;
  font-size: 11px;
  font-weight: 500;
}
.summary-action { cursor: pointer; }
.summary-action:hover {
  border-color: var(--apple-blue);
  background: rgba(10, 132, 255, 0.06);
  transform: translateY(-1px);
}

/* --- Result Heading --- */
.result-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin: 8px 0 12px;
}
.result-heading h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 2px;
  letter-spacing: -0.2px;
}
.result-heading p {
  font-size: 12px;
  color: var(--apple-text-tertiary);
  margin: 0;
}
.result-count {
  color: var(--apple-text-tertiary);
  font-size: 13px;
  font-weight: 500;
}

/* --- Data Table (Apple Tables) --- */
.sheet-shell {
  overflow: auto;
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.organizer-shell {
  height: calc(100vh - 420px);
  min-height: 300px;
}
.sheet-table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 12px;
  min-width: 4400px;
}
.sheet-table th,
.sheet-table td {
  height: 36px;
  padding: 6px 10px;
  border-right: 0.5px solid var(--apple-border);
  border-bottom: 0.5px solid var(--apple-border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--apple-surface);
  color: var(--apple-text-primary);
}
.sheet-table th {
  height: 42px;
  background: var(--apple-surface2);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  font-weight: 600;
  font-size: 12px;
  color: var(--apple-text-secondary);
  position: sticky;
  top: 26px;
  z-index: 4;
  letter-spacing: 0.2px;
  text-transform: none;
}
.sheet-table .letter-row th {
  top: 0;
  height: 26px;
  padding: 3px 8px;
  text-align: center;
  background: rgba(0,0,0,0.05);
  color: var(--apple-text-tertiary);
  font-weight: 600;
  font-size: 11px;
  z-index: 5;
}
.sheet-table .group-row th {
  background: #e8edf5;
  color: #3a3a3c;
  font-weight: 650;
  text-align: center;
  border-bottom: 1px solid rgba(0,0,0,.12);
}
.sheet-table .group-row th:nth-child(2){background:#e2f0d9}
.sheet-table .group-row th:nth-child(3){background:#fff2cc}
.sheet-table .group-row th:nth-child(4){background:#ddebf7}
.sheet-table .group-row th:nth-child(5){background:#fce4d6}
.sheet-table .group-row th:nth-child(6){background:#e4dfec}
.assignment-select{width:100%;min-width:88px;height:30px;border:1px solid rgba(0,0,0,.14);border-radius:7px;background:#fff;padding:0 6px;font:inherit;color:inherit}
.sheet-table tbody tr { transition: background 0.1s; }
.sheet-table tbody tr:hover { background: rgba(255,255,255,0.04); }
.sheet-table td:hover {
  outline: 2px solid rgba(10, 132, 255, 0.35);
  outline-offset: -2px;
  border-radius: 2px;
}
.empty-cell {
  text-align: center !important;
  color: var(--apple-text-tertiary);
  height: 100px !important;
}

/* --- Color Cells --- */
.old-store-cell { background: var(--old-store-color) !important; color: #1f2937 !important; }
.zero-order-cell { background: var(--zero-order-color) !important; color: #1f2937 !important; }
.manual-status-cell { font-weight: 700; color: var(--apple-orange); }
.zero-manual-notice {
  display: inline-block !important;
  margin: 6px 0 0 !important;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 159, 10, 0.15);
  color: var(--apple-orange) !important;
  font-weight: 600;
  font-size: 12px;
}
.zero-manual-notice[hidden] { display: none !important; }

/* --- Dialog (Apple Sheet Style) --- */
.zero-dialog {
  width: min(1100px, 94vw);
  border: 0;
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.25), 0 0 0 0.5px var(--apple-border);
  background: var(--apple-surface2);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  color: var(--apple-text-primary);
}
.zero-dialog::backdrop { background: rgba(0,0,0,0.3); backdrop-filter: blur(4px); }
.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 16px;
}
.dialog-heading h2 {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 700;
}
.dialog-heading p { margin: 0; color: var(--apple-text-secondary); font-size: 13px; }
.zero-dialog-table { max-height: 62vh; }

/* --- Simple Table (Rules / Data pages) --- */
.simple-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.simple-toolbar input {
  min-width: 320px;
  background: var(--apple-surface);
  color: var(--apple-text-primary);
  border: 0.5px solid var(--apple-border);
}
.save-state {
  min-width: 90px;
  color: var(--apple-green);
  font-weight: 500;
  font-size: 13px;
}
.simple-table-shell {
  overflow: auto;
  max-height: calc(100vh - 170px);
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.simple-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.simple-table th,
.simple-table td {
  border-bottom: 0.5px solid var(--apple-border);
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  color: var(--apple-text-primary);
}
.simple-table th {
  position: sticky;
  top: 0;
  background: var(--apple-surface2);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  z-index: 2;
  font-weight: 600;
  font-size: 12px;
  color: var(--apple-text-secondary);
}
.simple-table td {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.simple-table tbody tr { transition: background 0.1s; }
.simple-table tbody tr:hover { background: rgba(255,255,255,0.03); }

.rule-editable {
  background: rgba(255,255,255,0.04);
  cursor: cell;
}
.rule-editable:hover {
  outline: 2px solid var(--apple-yellow);
  outline-offset: -2px;
}
.rule-actions { display: flex; gap: 4px; }
.rule-cell-editor {
  width: 100%;
  min-width: 120px;
  border: 1px solid var(--apple-blue);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  background: var(--apple-bg);
  color: var(--apple-text-primary);
}
.rule-new-row td { background: rgba(10, 132, 255, 0.06); }

/* --- Rule Tabs (Segmented Control) --- */
.rule-tabs {
  display: flex;
  gap: 0;
  margin: 0 0 14px;
  background: var(--apple-surface2);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-radius: var(--radius-md);
  padding: 3px;
  width: fit-content;
  border: 0.5px solid var(--apple-border);
}
.rule-tab {
  border: 0;
  border-bottom: 0;
  background: transparent;
  padding: 7px 20px;
  color: var(--apple-text-secondary);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.rule-tab:hover { color: var(--apple-text-primary); }
.rule-tab.active {
  background: var(--apple-blue);
  color: #fff;
  font-weight: 600;
}

/* --- Rule Guide Cards --- */
.rule-guides {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.rule-guide-card {
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.rule-guide-card h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--apple-text-primary);
}
.rule-guide-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--apple-text-secondary);
}
.rule-guide-card li + li { margin-top: 6px; }
.color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 0.5px solid var(--apple-border-light);
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 6px;
}

/* --- Version Panel --- */
.version-panel {
  margin: 12px 0 18px;
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.version-title { font-weight: 600; margin-bottom: 8px; }
.version-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.version-table th,
.version-table td {
  padding: 8px 10px;
  border-bottom: 0.5px solid var(--apple-border);
  text-align: left;
  color: var(--apple-text-primary);
}
.version-table th { background: var(--apple-surface2); font-weight: 600; }
.version-empty { color: var(--apple-text-tertiary); }

/* --- Advanced Card --- */
.advanced-card {
  background: var(--apple-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--apple-border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.advanced-content { padding: 18px; }

/* --- Scrollbar (WebKit) --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--apple-surface3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #c7c7cc; }

/* --- Selection --- */
::selection { background: var(--apple-blue); color: #fff; }

/* --- Responsive --- */
@media (max-width: 900px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 12px 16px;
    gap: 12px;
    flex-wrap: wrap;
  }
  .mainnav { height: auto; flex-wrap: wrap; gap: 0; }
  .mainnav > a { height: 36px; padding: 0 10px; font-size: 12px; }
  .page { padding: 16px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .rule-guides { grid-template-columns: 1fr; }
  .organizer-shell { height: calc(100vh - 500px); }
  .sync-fields { align-items: stretch; }
  .sync-fields > * { flex: 1 1 180px; }
  .simple-toolbar input { min-width: 180px; flex: 1; }
  .page-heading h1 { font-size: 22px; }
}
