/* ============================================
   SupShare - 全局样式
   基于设计稿 colors_and_type.css 的变量系统
   ============================================ */

:root {
  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-primary-light: #DBEAFE;
  --color-primary-lighter: #EFF6FF;
  --color-primary-dark: #1E3A8A;

  --color-bg: #F8FAFC;
  --color-bg-secondary: #F1F5F9;
  --color-bg-elevated: #FFFFFF;
  --color-bg-sunken: #E2E8F0;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F8FAFC;
  --color-border: #E2E8F0;
  --color-border-light: #F1F5F9;
  --color-border-focus: #2563EB;

  --color-text-primary: #0F172A;
  --color-text-secondary: #475569;
  --color-text-tertiary: #94A3B8;
  --color-text-inverse: #FFFFFF;
  --color-text-link: #2563EB;
  --color-text-link-hover: #1D4ED8;

  --state-success: #059669;
  --state-success-bg: #ECFDF5;
  --state-warning: #D97706;
  --state-warning-bg: #FFFBEB;
  --state-error: #DC2626;
  --state-error-bg: #FEF2F2;
  --state-info: #2563EB;
  --state-info-bg: #EFF6FF;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.05);

  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
  --header-height: 56px;

  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
}

/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text-primary);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--color-text-link); text-decoration: none; }
a:hover { color: var(--color-text-link-hover); }

img { max-width: 100%; height: auto; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* === Utility Classes === */
.flex-center { display: flex; align-items: center; justify-content: center; }
.text-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-tertiary); }

/* === Layout: App Shell === */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: #1E293B;
  color: #F1F5F9;
  display: flex;
  flex-direction: column;
  transition: width var(--transition-slow);
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 40;
  overflow: hidden;
  /* 默认隐藏侧边栏（移动端优先） */
  transform: translateX(-100%);
  box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  bottom: auto;
  height: 100vh;
  pointer-events: none;
}

.app-sidebar.mobile-open {
  transform: translateX(0);
  pointer-events: auto;
  z-index: 100;
}

.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.app-sidebar.collapsed .nav-text,
.app-sidebar.collapsed .sidebar-storage,
.app-sidebar.collapsed .logo-text {
  display: none;
}

.app-sidebar.collapsed .nav-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-sidebar.collapsed .logo-area {
  justify-content: center;
  padding: 16px 0;
}

.app-main {
  margin-left: 0;
  flex: 1;
  transition: margin-left var(--transition-slow);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-main.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}

.app-header {
  min-height: var(--header-height);
  height: auto;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}

.app-content {
  flex: 1;
  padding: 16px 16px 100px 16px;
  overflow-y: auto;
}

/* === Sidebar Nav === */
.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  margin: 2px 8px;
  border-radius: var(--radius-md);
  color: #94A3B8;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  color: #E2E8F0;
  background: rgba(255,255,255,0.05);
}

.nav-item.active {
  color: #DBEAFE;
  background: rgba(37, 99, 235, 0.12);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}

.nav-separator {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 8px 16px;
}

.sidebar-storage {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.storage-bar {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.storage-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  transition: width var(--transition-slow);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1.25rem;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

.btn-outline {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn-outline:hover { background: var(--color-bg-secondary); border-color: var(--color-text-tertiary); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: none;
  padding: 6px 8px;
}
.btn-ghost:hover { background: var(--color-bg-secondary); color: var(--color-text-primary); }

.btn-danger {
  background: transparent;
  color: var(--state-error);
  border: none;
  padding: 6px 8px;
}
.btn-danger:hover { background: var(--state-error-bg); }

.btn-sm { padding: 4px 10px; font-size: 0.8125rem; }
.btn-lg { padding: 10px 24px; font-size: 1rem; height: 44px; }
.btn-block { width: 100%; }

/* === Form Controls === */
.form-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-size: 0.875rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder { color: var(--color-text-tertiary); }

.form-input-icon {
  position: relative;
}

.form-input-icon .icon-left {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.form-input-icon .form-input {
  padding-left: 36px;
}

/* === Badge / Tag === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25rem;
}

.badge-success { background: var(--state-success-bg); color: var(--state-success); }
.badge-warning { background: var(--state-warning-bg); color: var(--state-warning); }
.badge-error { background: var(--state-error-bg); color: var(--state-error); }
.badge-info { background: var(--state-info-bg); color: var(--state-info); }
.badge-neutral { background: var(--color-bg-secondary); color: var(--color-text-secondary); }

/* === Table === */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--color-text-primary);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--color-surface-hover);
}

.data-table .checkbox-cell {
  width: 40px;
  text-align: center;
}

.data-table .sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table .sortable:hover {
  color: var(--color-primary);
}

.data-table .sort-icon {
  display: inline-block;
  font-size: 0.75rem;
  opacity: 0.3;
  color: var(--color-text-tertiary);
  transition: all 0.15s ease;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: -1px;
}

.data-table .sortable:hover .sort-icon {
  opacity: 0.6;
}

/* === Card === */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* === Modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

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

.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.98);
  transition: transform var(--transition-normal);
}

.modal-backdrop.active .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border-light);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* === Toggle Switch === */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--color-bg-sunken);
  border-radius: 11px;
  cursor: pointer;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.toggle.active { background: var(--color-primary); }

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-fast);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle.active::after { transform: translateX(18px); }

/* === Toast / Notification === */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.3s ease;
  max-width: 360px;
}

.toast.toast-out { animation: toast-out 0.2s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* === Loading === */
.table-loading {
  text-align: center;
  padding: 60px 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #E2E8F0;
  border-top-color: #3B82F6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 14px;
}

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

.loading-text {
  color: #64748B;
  font-size: 0.875rem;
}

.loading-dots::after {
  content: '';
  display: inline-block;
  width: 1.5em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* === Context Menu === */
.context-menu {
  position: fixed;
  z-index: 60;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px 0;
  min-width: 160px;
  display: none;
}

.context-menu.visible { display: block; }

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.context-menu-item:hover {
  background: var(--color-primary-lighter);
  color: var(--color-primary);
}

.context-menu-item.danger { color: var(--state-error); }
.context-menu-item.danger:hover { background: var(--state-error-bg); }

.context-menu-separator {
  height: 1px;
  background: var(--color-border-light);
  margin: 4px 0;
}

/* === Upload Progress === */
.upload-progress {
  height: 3px;
  background: var(--color-bg-secondary);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* === Responsive === */
@media (max-width: 1024px) {
  .app-sidebar {
    transform: translateX(-100%);
    z-index: 40;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    bottom: auto;
    height: 100vh;
    pointer-events: none;
  }
  .app-sidebar.mobile-open {
    transform: translateX(0);
    pointer-events: auto;
    z-index: 100;
  }
  .app-main {
    margin-left: 0 !important;
  }
  .app-content {
    padding: 16px 16px 100px 16px; /* bottom padding for tab bar + safe area */
  }
  .app-header {
    padding: 10px 16px;
    flex-wrap: wrap;
  }
  .hide-mobile { display: none !important; }
}

/* Mobile bottom tab bar - visible by default (mobile-first) */
body.is-mobile .hide-mobile { display: none !important; }
.mobile-tab-bar {
  display: flex;
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  z-index: 9999 !important;
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  height: calc(56px + env(safe-area-inset-bottom));
  min-height: 56px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  transform: translateZ(0);
}

body.is-desktop .mobile-tab-bar { display: none !important; }

body.is-desktop .app-sidebar {
  transform: translateX(0);
  z-index: 40;
  box-shadow: none;
  pointer-events: auto;
}
body.is-desktop .app-main {
  margin-left: var(--sidebar-width) !important;
}
/* 桌面端折叠侧边栏时，内容区必须同步左移，否则会留下空白 */
body.is-desktop .app-main.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width) !important;
}
body.is-desktop .app-content {
  padding: 24px;
}
body.is-desktop .app-header {
  padding: 12px 24px;
}

.mobile-tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--color-text-tertiary); font-size: 0.6875rem;
  text-decoration: none;
}
.mobile-tab-item.active { color: var(--color-primary); }
.mobile-tab-item svg { width: 22px; height: 22px; }
.mobile-sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 99;
}
.mobile-sidebar-overlay.visible { display: block; }

@media (min-width: 1025px) {
  .hide-desktop { display: none !important; }
}

/* === Mobile App Adaptation (for HBuilderX packaged APP) === */
html, body {
  width: 100%;
  min-height: 100vh;
}

/* Force mobile layout on small screens */
@media (max-width: 1024px) {
  html { font-size: 14px; }
  body { min-width: 320px; }
  .app-layout { min-width: 320px; }
  .app-main { min-width: 320px; }
  .app-content { min-width: 320px; }
}

/* For APP webview, ensure content fills viewport */
#app, .app-layout, .login-page, .app-main {
  width: 100%;
  max-width: 100vw;
}

/* === Tooltip (for collapsed sidebar) === */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 10px;
  background: var(--color-text-primary);
  color: var(--color-text-inverse);
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 50;
  pointer-events: none;
}