:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e4e8f1;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #10b981;
  --success-soft: #ecfdf5;
  --warn: #f59e0b;
  --warn-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.logo-box {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.25);
  flex-shrink: 0;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  margin-right: 3px;
}

.status-dot.off {
  background: #f59e0b;
}

.today-side-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.today-main-punch {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
}

.today-sub-punch {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.today-ok-foot {
  font-size: 11px;
  font-weight: 600;
  color: #059669;
}

.today-ok-foot.warn {
  color: #dc2626;
}

.planner-warn {
  font-size: 11px;
  color: #b45309;
  font-weight: 600;
  margin-top: 1px;
}

.modal-info-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.45;
}

.toolbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.tool-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-tile.active-tile {
  cursor: pointer;
  border-color: #bfdbfe;
  transition: all 0.15s;
}

.tool-tile.active-tile:hover {
  background: #f8faff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.tool-tile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 12px;
}

.tool-tile p {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.brand-title {
  font-weight: 700;
  font-size: 14px;
  color: #0f172a;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.ai-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.ai-pill:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.dot.ok {
  background: var(--success);
}

/* Module Tabs */
.module-tabs {
  display: flex;
  background: var(--card);
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  gap: 4px;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 9px 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.shell-upgrade-bar {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  padding: 6px 12px;
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

/* Main Body */
.main-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month-picker-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.month-picker-wrap input {
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 12.5px;
  color: var(--text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #f8fafc;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* Auth Card */
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px 18px;
  text-align: center;
  margin-top: 8px;
}

.auth-icon {
  font-size: 34px;
  margin-bottom: 8px;
}

.auth-card h3 {
  font-size: 15px;
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 14px;
  line-height: 1.6;
}

.auth-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 16px;
  font-size: 11.5px;
  font-weight: 600;
  color: #334155;
}

.auth-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.auth-polling-tip {
  margin-top: 12px;
  font-size: 11.5px;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-block;
  animation: pulseAnim 1.2s infinite ease-in-out;
}

@keyframes pulseAnim {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

.engine-tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 600;
  background: #f1f5f9;
  color: #64748b;
}

.engine-tag.ai {
  background: linear-gradient(90deg, #eff6ff, #f5f3ff);
  color: #4f46e5;
  border: 1px solid #c7d2fe;
}

.plan-result-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: #1e293b;
  line-height: 1.6;
  white-space: normal;
  word-break: break-word;
}

.plan-result-box.ai-mode {
  background: linear-gradient(180deg, #f8faff 0%, #ffffff 100%);
  border-color: #c7d2fe;
}

/* 富文本 Markdown 干净排版样式 */
.md-content p {
  margin: 0 0 6px 0;
}

.md-content p:last-child {
  margin-bottom: 0;
}

.md-content ul,
.md-content ol {
  margin: 4px 0 7px 0;
  padding-left: 17px;
}

.md-content li {
  margin-bottom: 3px;
}

.md-content li:last-child {
  margin-bottom: 0;
}

.md-content strong {
  color: #0f172a;
  font-weight: 700;
}

.md-content .md-heading {
  font-weight: 700;
  font-size: 12.8px;
  color: #1e3a8a;
  margin: 6px 0 4px 0;
}

.md-content .md-heading:first-child {
  margin-top: 0;
}

.md-content code {
  background: #eef2ff;
  color: #3730a3;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

.rules-collapsible {
  border-top: 1px solid var(--border);
  padding: 10px 13px;
  background: #fafbff;
  font-size: 11.8px;
  color: #475569;
  line-height: 1.6;
}

.rules-cur-breakdown {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 7px 10px;
  border-radius: 7px;
  margin-bottom: 8px;
  font-size: 11.5px;
}

.rules-doc ul {
  margin-top: 4px;
  padding-left: 16px;
}

.chat-bubble {
  max-width: 92%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.58;
  white-space: normal;
  word-break: break-word;
}

.fallback-upsell {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px dashed #e2e8f0;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

.collapse-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 13px;
  background: var(--card);
  border: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.collapse-trigger:hover {
  background: #f8fafc;
}

.collapse-arrow {
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 600;
}

.details-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}

/* Alert Banner */
.alert-banner {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
}

.kpi-card.highlight {
  background: linear-gradient(135deg, #eff6ff 0%, #eef2ff 100%);
  border-color: #bfdbfe;
}

.kpi-card.full-span {
  grid-column: 1 / -1;
  padding: 9px 12px;
}

.kpi-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
  margin: 2px 0;
  letter-spacing: -0.3px;
}

.kpi-card.highlight .kpi-value {
  color: var(--primary);
}

.kpi-foot {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.today-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.today-time {
  font-weight: 600;
  font-size: 12.5px;
  margin-left: 4px;
}

.today-swipes {
  font-size: 11px;
  color: var(--muted);
}

/* Planner Card */
.planner-card {
  background: var(--card);
  border: 1px solid #dbeafe;
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.05);
}

.planner-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.planner-title {
  font-weight: 700;
  font-size: 13.5px;
  color: #0f172a;
}

.planner-desc {
  font-size: 11px;
  color: var(--muted);
}

.target-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-soft);
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  flex-shrink: 0;
}

.target-input-group input {
  width: 56px;
  border: 1px solid #93c5fd;
  border-radius: 5px;
  padding: 2px 5px;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
  color: var(--primary);
  background: #fff;
  appearance: textfield;
  -moz-appearance: textfield;
}

.target-input-group input::-webkit-outer-spin-button,
.target-input-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.math-baseline {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: #334155;
  margin-bottom: 9px;
  line-height: 1.55;
}

.math-baseline ul {
  margin-top: 4px;
  padding-left: 16px;
}

.ai-prompt-row {
  display: flex;
  gap: 6px;
}

.ai-prompt-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
}

.ai-output {
  margin-top: 9px;
  padding: 10px 11px;
  background: linear-gradient(180deg, #f8faff 0%, #ffffff 100%);
  border: 1px solid #c7d2fe;
  border-radius: 9px;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Table */
.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--muted);
  cursor: pointer;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.data-table tr.row-rest {
  color: #94a3b8;
  background: #fcfdff;
}

.data-table tr.row-danger {
  background: var(--danger-soft);
}

.data-table tr.row-weekend-work {
  background: var(--success-soft);
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 20px !important;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
}

.badge-ok { background: var(--success-soft); color: #047857; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: #f1f5f9; color: #64748b; }

/* Yearly View */
.yearly-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.empty-hint {
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  font-size: 12.5px;
}

.bar-row {
  display: grid;
  grid-template-columns: 58px 1fr 68px;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed #f1f5f9;
}

.bar-track {
  height: 16px;
  background: #f1f5f9;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #4f46e5);
  border-radius: 999px;
}

/* AI Assistant Tab */
#panel-assistant {
  height: calc(100vh - 118px);
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid #dbeafe;
  background: var(--card);
  color: var(--primary);
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  cursor: pointer;
}

.chip:hover {
  background: var(--primary-soft);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.chat-bubble {
  max-width: 90%;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: #f1f5f9;
  color: var(--text);
}

.chat-input-bar {
  display: flex;
  gap: 7px;
  align-items: flex-end;
}

.chat-input-bar textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 12.5px;
}

/* Settings Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.modal-sheet {
  background: var(--card);
  width: 100%;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-close {
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
}

.modal-tip {
  font-size: 11.5px;
  color: var(--muted);
}

.preset-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.preset-btn {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-size: 11.5px;
  cursor: pointer;
}

.preset-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
}

.form-group input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
}

.test-status {
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
}

.test-status.ok { background: var(--success-soft); color: #047857; }
.test-status.err { background: var(--danger-soft); color: #b91c1c; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
