/* Investment OS — 共享组件库（温暖纸感 × 深色奢华）
   锚点纪律：本文件所有类名与 JS 选择器对齐，重命名需同步改 JS。 */

/* ═══════════════ 按钮 ═══════════════ */
button,
[role="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast);
}

/* 图标按钮防御：SVG 作为 flex 子项不可压缩。
   否则固定尺寸按钮（如 34×34）受全局 padding:0 16px 挤压后，
   内容区宽度归零，图标会被压缩成 0 宽完全不可见。 */
button svg,
[role="button"] svg { flex-shrink: 0; }

button:hover:not(:disabled),
[role="button"]:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

button:active:not(:disabled),
[role="button"]:active:not(:disabled) {
  transform: translateY(0.5px);
}

/* ── Primary：实心强调色（浅色陶土 / 深色琥珀金） ── */
button.primary,
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--text-inverse);
}

button.primary:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: transparent;
  color: var(--text-inverse);
}

:root[data-theme="dark"] button.primary,
:root[data-theme="dark"] .btn-primary {
  color: #14161a;
}

/* ── Danger ── */
button.danger,
.btn-danger {
  color: var(--danger);
  border-color: var(--border-strong);
}

button.danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Success / Ghost ── */
button.success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

button.ghost:hover:not(:disabled) {
  background: var(--bg-surface-muted);
  color: var(--text);
}

button:disabled,
[role="button"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ═══════════════ 表单控件 ═══════════════ */
input,
select,
textarea {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

textarea {
  height: auto;
  min-height: 80px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

/* select 箭头用 mask + currentColor，自动适配双主题 */
select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  -webkit-mask-image: none;
}

@supports (-webkit-mask-image: url("")) {
  select {
    background-image: none;
    -webkit-mask-image: none;
    background-color: var(--bg-surface);
  }
  select {
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-size: 6px 6px;
    background-position: calc(100% - 16px) 50%, calc(100% - 10px) 50%;
    background-repeat: no-repeat;
  }
}

/* ═══════════════ 面板 / 卡片 ═══════════════ */
.panel,
.card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.panel:hover,
.card:hover {
  border-color: var(--border-strong);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-head > div:first-child { min-width: 0; flex: 1 1 200px; }
.panel-toolbar { flex-shrink: 0; }

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
}

/* 移动端面板头：标题在上、按钮在下。
   注意：必须放在本文件基础规则之后定义，确保层叠覆盖生效，
   不要移到先加载的 layout.css 中（会被此处基础规则反向覆盖）。 */
@media (max-width: 768px) {
  .panel-head {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
  }

  /* 重置桌面端 flex-basis:200px——column 方向下 basis 会作用到高度上，
     把标题区撑出 200px 空白 */
  .panel-head > div:first-child { flex: 0 1 auto; }

  .panel-head > .panel-toolbar { justify-content: flex-end; }
}

/* ═══════════════ 表格 ═══════════════ */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: var(--text-sm);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 12px;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--table-head-text, var(--text-muted));
  background: var(--table-head-bg, var(--bg-surface-muted));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--table-head-border, var(--border-strong));
  user-select: none;
}

td { color: var(--text); }

/* 金额/数字列自动等宽 */
td.num, th.num { font-variant-numeric: tabular-nums; }

tr:hover > td { background: var(--accent-soft); }
tr:last-child > td { border-bottom: none; }

/* ═══════════════ 指标卡 ═══════════════ */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.metric {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.metric:hover {
  border-color: var(--accent-lighter);
  box-shadow: var(--shadow-sm);
}

.metric span {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

.metric strong {
  display: block;
  font-size: 24px;
  font-weight: var(--font-bold);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}

.metric small {
  display: block;
  margin-top: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.4;
}

/* ═══════════════ 状态 / 提示 ═══════════════ */
.status {
  min-height: 22px;
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-4);
  white-space: pre-wrap;
  line-height: 1.5;
}

.status.ok  { color: var(--success); }
.status.err { color: var(--danger); }

.hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.5;
  margin: 0;
  padding: var(--space-4) var(--space-4) 0;
}

/* ═══════════════ 标签 ═══════════════ */
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.tag.done { background: var(--success-soft); color: var(--success); }
.tag.todo { background: var(--bg-surface-muted); color: var(--text-muted); }
.tag.warning { background: var(--warning-soft); color: var(--warning); }

/* ═══════════════ Pre / Code ═══════════════ */
pre {
  background: #16191d;
  color: #e6e1d6;
  border-radius: var(--radius-md);
  padding: 14px;
  overflow: auto;
  max-height: 420px;
  max-width: 100%; /* 长行在 pre 内部横向滚动，绝不允许撑宽容器 */
  line-height: 1.55;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-surface-muted);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

/* ═══════════════ 弹窗 ═══════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(14, 16, 19, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: translateY(12px);
  transition: transform var(--transition-base), opacity var(--transition-base);
  opacity: 0;
}

.modal-overlay.active .modal {
  transform: translateY(0);
  opacity: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--text); }

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--bg-surface-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ═══════════════ Toast ═══════════════ */
.toast {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  padding: 12px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  color: var(--text);
  max-width: 380px;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity var(--transition-base), transform var(--transition-base);
  pointer-events: auto;
}

.toast.show { opacity: 1; transform: translateY(0); }

.toast.success {
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  background: color-mix(in srgb, var(--success) 7%, var(--bg-elevated));
  color: var(--success);
}

.toast.error {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: color-mix(in srgb, var(--danger) 7%, var(--bg-elevated));
  color: var(--danger);
}

/* ═══════════════ 空状态 ═══════════════ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
  color: var(--text);
}

/* ═══════════════ 帮助面板 ═══════════════ */
.help-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  overflow: hidden;
}

.help-panel summary {
  padding: 12px 16px;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
  list-style: none;
}

.help-panel summary::-webkit-details-marker { display: none; }
.help-panel summary::before { content: "▸ "; color: var(--text-muted); font-size: 11px; }
.help-panel[open] summary::before { content: "▾ "; }
.help-panel summary:hover { color: var(--accent); }
.help-panel[open] summary { border-bottom: 1px solid var(--border); color: var(--accent); }

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-3);
  padding: var(--space-4);
}

.help-item { display: flex; flex-direction: column; gap: var(--space-1); }
.help-item strong { font-size: var(--text-sm); color: var(--text); }
.help-item span { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.5; }

/* ═══════════════ Service Toast（fetch 守卫，app.js 锚点） ═══════════════ */
.ios-service-toast {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  max-width: 400px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px);
  transition: opacity var(--transition-base), transform var(--transition-base);
}

.ios-service-toast.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ═══════════════ 响应式（仅 768/480 两档） ═══════════════ */
@media (max-width: 768px) {
  button, [role="button"] { min-height: 44px; }
  input, select { height: 44px; }

  .modal { width: calc(100vw - 32px); max-height: 90vh; }

  .toast {
    right: var(--space-2);
    left: var(--space-2);
    max-width: unset;
  }

  .ios-service-toast {
    right: var(--space-2);
    left: var(--space-2);
    max-width: unset;
  }
}

@media (max-width: 480px) {
  .summary { grid-template-columns: 1fr 1fr; }
}
