/* ============================================
   WeCom × Notion Sync - Mobile-first UI
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --primary: #4a6cf7;
  --primary-light: #e8edff;
  --text-dark: #1a1a2e;
  --text-gray: #6c757d;
  --text-light: #adb5bd;
  --border: #e8e8ed;
  --success: #28a745;
  --error: #e15554;
  --warning: #f0a500;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text-dark);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

/* ============================================ Screens */

.screen {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ============================================ Loading */

#loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-wrap {
  text-align: center;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-wrap p {
  color: var(--text-gray);
  font-size: 0.875rem;
}

.loading-actions {
  margin-top: 24px;
  text-align: center;
}

.loading-actions .fallback-hint {
  color: var(--text-light);
  font-size: 0.75rem;
  margin-bottom: 12px;
}

.loading-actions .btn-fallback {
  display: inline-block;
  padding: 12px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.loading-actions .btn-fallback:active {
  opacity: 0.9;
}

/* ============================================ WeCom Entry */

.entry-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 24px;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.entry-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.entry-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.entry-desc {
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 40px;
}

.entry-btn {
  display: inline-block;
  padding: 16px 48px;
  background: #fff;
  color: #4a6cf7;
  font-size: 1.125rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 50px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}

.entry-btn:active {
  transform: scale(0.96);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.entry-hint {
  margin-top: 16px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

/* ============================================ Login */

.login-header {
  text-align: center;
  padding: 48px 24px 32px;
  background: linear-gradient(135deg, var(--primary), #6a5acd);
  color: #fff;
  border-radius: 0 0 24px 24px;
}

.login-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.login-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-header p {
  font-size: 0.8125rem;
  opacity: 0.85;
}

.error-banner {
  margin: 16px;
  padding: 12px 16px;
  background: #fff5f5;
  border: 1px solid #ffd6d6;
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 0.8125rem;
  text-align: center;
}

.loading-status {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-gray);
  text-align: center;
  max-width: 260px;
  line-height: 1.4;
}

.loading-error {
  margin-top: 16px;
  padding: 12px;
  background: #fff5f5;
  border: 1px solid #ffd6d6;
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 0.75rem;
  text-align: left;
  max-width: 320px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-all;
}

.role-section {
  padding: 24px 16px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.section-desc {
  font-size: 0.8125rem;
  color: var(--text-gray);
  margin-bottom: 20px;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.role-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.role-card:active {
  transform: scale(0.96);
}

.role-card .role-card-icon {
  font-size: 2rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-light);
}

.role-card .role-card-label {
  font-size: 0.9375rem;
  font-weight: 600;
}

.role-card .role-card-dept {
  font-size: 0.6875rem;
  color: var(--text-gray);
}

.role-card .role-card-desc {
  font-size: 0.6875rem;
  color: var(--text-light);
  line-height: 1.3;
}

.login-footer {
  text-align: center;
  padding: 24px;
  font-size: 0.75rem;
  color: var(--text-light);
}

/* ============================================ Main App */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
}

.header-info {
  display: flex;
  flex-direction: column;
}

.header-role {
  font-size: 0.9375rem;
  font-weight: 600;
}

.header-user {
  font-size: 0.75rem;
  color: var(--text-gray);
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-gray);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:active {
  background: var(--bg);
}

/* ============================================ Tabs */

.tab-nav {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 64px;
  z-index: 90;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 12px;
  font-size: 0.8125rem;
  color: var(--text-gray);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

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

.tab-icon {
  font-size: 1rem;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ============================================ Form */

.form-section {
  padding: 16px;
}

.form-desc {
  background: var(--primary-light);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--primary);
  margin-bottom: 16px;
}

.field-group {
  margin-bottom: 24px;
}

.field-group-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.field-group-grid {
  display: grid;
  gap: 12px;
}

.field-group-grid.cols-2 {
  grid-template-columns: 1fr 1fr;
}

.field-group-grid.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

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

.field-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-dark);
}

.field-required {
  color: var(--error);
  font-size: 0.75rem;
}

.field-help {
  font-size: 0.6875rem;
  color: var(--text-light);
}

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  background: var(--card);
  color: var(--text-dark);
  transition: border-color 0.2s;
  font-family: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.field textarea {
  resize: vertical;
  min-height: 72px;
}

.field input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

/* Checkbox field */
.field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.field-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.field-checkbox .field-label {
  cursor: pointer;
}

/* Select styling */
.field select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236c757d' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  min-height: 44px;
}

/* Size number grid */
.size-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.size-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.size-field label {
  font-size: 0.6875rem;
  color: var(--text-gray);
  text-align: center;
  font-weight: 500;
}

.size-field input {
  text-align: center;
  padding: 8px 4px !important;
  font-size: 0.875rem !important;
}

/* Form Actions */
.form-actions {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-submit {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-submit:active {
  transform: scale(0.98);
  opacity: 0.9;
}

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

.btn-icon {
  font-size: 1.125rem;
}

.btn-reset {
  width: 100%;
  padding: 10px;
  background: none;
  color: var(--text-gray);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  cursor: pointer;
}

/* ============================================ Recent */

.recent-section {
  padding: 16px;
}

.recent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.recent-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.btn-refresh {
  background: none;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.75rem;
  color: var(--text-gray);
  cursor: pointer;
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recent-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 14px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.15s;
}

.recent-card:active {
  transform: scale(0.98);
}

.recent-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.recent-card-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-bottom: 6px;
}

.recent-card-item {
  font-size: 0.6875rem;
  color: var(--text-gray);
}

.recent-card-item strong {
  color: var(--text-dark);
}

.recent-card-time {
  font-size: 0.6875rem;
  color: var(--text-light);
}

.loading-text {
  text-align: center;
  color: var(--text-gray);
  padding: 32px;
  font-size: 0.8125rem;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* ============================================ Overlays */

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.success-card,
.error-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.success-icon,
.error-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.success-card h2,
.error-card h2 {
  font-size: 1.125rem;
  margin-bottom: 8px;
}

.success-card p,
.error-card p {
  font-size: 0.8125rem;
  color: var(--text-gray);
  margin-bottom: 20px;
  word-break: break-word;
}

.btn-view-notion {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
  text-align: center;
}

.btn-continue,
.btn-retry {
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-gray);
  cursor: pointer;
}

/* ============================================ Style Picker (款式搜索选择器) */

.field-style-picker .style-input-wrap {
  position: relative;
}

.field-style-picker .style-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 280px;
  overflow-y: auto;
  z-index: 200;
  margin-top: 4px;
}

.field-style-picker .style-dropdown.hidden {
  display: none;
}

.style-searching,
.style-error,
.style-empty {
  padding: 16px 12px;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-gray);
}

.style-error {
  color: var(--error);
}

.style-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.style-result-item:last-child {
  border-bottom: none;
}

.style-result-item:active {
  background: var(--primary-light);
}

.style-result-code {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 2px;
}

.style-result-name {
  font-size: 0.75rem;
  color: var(--text-gray);
  margin-bottom: 4px;
}

.style-result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.style-tag {
  font-size: 0.625rem;
  padding: 1px 6px;
  background: var(--bg);
  border-radius: 4px;
  color: var(--text-gray);
}

/* Style info card (shown after selecting a style) */
.style-info {
  background: var(--primary-light);
  border: 1px solid #c8d4ff;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 6px;
}

.style-info.hidden {
  display: none;
}

.style-info-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.style-info-icon {
  font-size: 1rem;
}

.style-info-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
}

.style-info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.style-info-tag {
  font-size: 0.6875rem;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  color: var(--text-dark);
}

/* ============================================ Responsive */

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

  .size-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 481px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.04);
  }
}

/* ============================================ Role Switcher (multi-role users) */

.role-switcher {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--bg-light, #f4f5fa);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.role-switcher-label {
  font-size: 0.8125rem;
  color: var(--text-gray);
  font-weight: 600;
}

.role-switcher-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.role-switch-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-dark);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.role-switch-btn.active {
  background: var(--primary, #4a6cf7);
  border-color: var(--primary, #4a6cf7);
  color: #fff;
  font-weight: 600;
}

.role-switch-btn:active {
  transform: scale(0.96);
}
