/* =========================================================
   企业管理系统 - 主样式
   飞书风格 · 模块化 · 响应式
   ========================================================= */

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

:root {
  --sidebar-w: 220px;
  --sidebar-collapsed: 60px;
  --nav-bg: #166b4e;
  --nav-hover: #1a805c;
  --nav-active: #1DBF8A;
  --primary: #1DBF8A;
  --primary-light: #e0f7ef;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

html, body {
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ============== 登录页 ============== */
.login-overlay {
  position: fixed; inset:0; z-index:9999;
  display: flex; align-items:center; justify-content:center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.login-card {
  background: #fff; border-radius: 16px;
  padding: 40px 32px; width: 360px; max-width: 90vw;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-icon { font-size: 48px; margin-bottom: 8px; }
.login-card h2 { font-size: 22px; color: #1e293b; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: #94a3b8; margin-bottom: 24px; }
.login-input-wrap { margin-bottom: 16px; }
.login-input-wrap input {
  width: 100%; padding: 12px 16px; border: 2px solid #e2e8f0;
  border-radius: 10px; font-size: 16px; outline: none;
  transition: border .2s;
}
.login-input-wrap input:focus { border-color: var(--primary); }
.login-btn {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 16px;
  font-weight: 600; cursor: pointer; transition: background .2s;
}
.login-btn:active { background: #2563eb; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 20px; }

/* ============== 主布局 ============== */
.app-layout {
  display: flex; height: 100vh; overflow: hidden;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--nav-bg); color: #fff;
  display: flex; flex-direction: column;
  transition: width .25s, min-width .25s;
  overflow: hidden; position: relative; z-index: 100;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
  white-space: nowrap;
}
.sidebar-logo { font-size: 24px; flex-shrink: 0; }
.sidebar-title { font-size: 16px; font-weight: 600; }
.sidebar-menu {
  flex:1; overflow-y: auto; padding: 8px 0;
}
.sidebar-menu::-webkit-scrollbar { width: 4px; }
.sidebar-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; color: rgba(255,255,255,.6);
  text-decoration: none; cursor: pointer;
  transition: all .15s; white-space: nowrap;
  border-left: 3px solid transparent;
  font-size: 14px;
}
.nav-item:hover { background: var(--nav-hover); color: #fff; }
.nav-item.active {
  background: rgba(29,191,138,.12); color: #1DBF8A; font-weight: 600;
  border-left-color: #8df0c8; border-left-width: 3px;
}
.nav-item .nav-icon { font-size: 22px; width: 24px; text-align: center; flex-shrink: 0; }
.nav-item .nav-label { flex-shrink: 0; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 4px 0;
}
.logout-item { color: rgba(255,255,255,.4); }
.logout-item:hover { color: var(--danger) !important; background: rgba(239,68,68,.1) !important; }

.sidebar-toggle { display: none; }

/* ---------- 主内容 ---------- */
.main-content {
  flex:1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}
.content-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: #fff;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.content-header h2 { font-size: 18px; font-weight: 600; }
.mobile-menu-btn { display: none; font-size: 24px; background:none; border:none; cursor:pointer; padding:4px 8px; }
.module-content {
  flex:1; overflow-y: auto; padding: 20px 24px;
}

/* ---------- 移动端侧栏折叠 ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w); z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 199;
  }
  .sidebar-overlay.show { display: block; }
  .sidebar-toggle {
    display: flex; align-items:center; justify-content:center;
    position: absolute; right: -44px; top: 12px;
    width: 40px; height: 40px; background: var(--nav-bg);
    border: none; color: #fff; font-size: 22px;
    border-radius: 0 8px 8px 0; cursor: pointer;
  }
  .mobile-menu-btn { display: block; }
  .content-header { padding: 12px 16px; }
  .module-content { padding: 12px 16px; }
}

/* ============== 通用组件 ============== */

/* 加载 */
.loading { text-align: center; padding: 80px 20px; color: var(--text-secondary); }
.loading .spin {
  display: inline-block; width: 32px; height: 32px;
  border: 3px solid #e5e7eb; border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 表格 */
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th {
  background: var(--bg); padding: 10px 12px;
  text-align: left; font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: #f8fafc; }

/* 卡片 */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card-title {
  font-size: 15px; font-weight: 600; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: 6px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .15s; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* 输入框 */
.input, .textarea, .select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; outline: none;
  background: #fff; transition: border .15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--primary); }
.textarea { min-height: 80px; resize: vertical; }

/* 搜索条 */
.search-bar {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.search-bar .input { flex: 1; }

/* 标签 */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 500;
}
.tag-blue { background: #dbeafe; color: #2563eb; }
.tag-green { background: #dcfce7; color: #16a34a; }
.tag-red { background: #fee2e2; color: #dc2626; }
.tag-yellow { background: #fef3c7; color: #d97706; }
.tag-gray { background: #f1f5f9; color: #64748b; }

/* 空状态 */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-secondary);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: 14px; }

/* 模态框 */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.4);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #fff; border-radius: 12px;
  width: 560px; max-width: 100%; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { font-size: 22px; cursor: pointer; color: var(--text-secondary); padding: 4px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border);
}

/* 表单组 */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text-secondary); }

/* 响应式表格 */
.table-responsive { overflow-x: auto; }

/* Toast */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  padding: 12px 20px; border-radius: 8px;
  font-size: 14px; color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.15);
  transform: translateX(120%); transition: transform .3s;
  max-width: 360px;
}
.toast.show { transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

/* 统计卡片行 */
.stat-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 140px; background: var(--card-bg);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); text-align: center;
}
.stat-card .num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* 时间线 */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before {
  content: ''; position: absolute; left: -20px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary);
}
.timeline-item .time { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }
.timeline-item .text { font-size: 13px; }

/* 文件上传区 */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 30px; text-align: center; cursor: pointer;
  transition: all .2s; margin-bottom: 12px;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-zone .icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone p { font-size: 13px; color: var(--text-secondary); }

/* 图片列表 */
.img-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.img-item {
  position: relative; width: 80px; height: 80px;
  border-radius: 6px; overflow: hidden; border: 1px solid var(--border);
}
.img-item img { width: 100%; height: 100%; object-fit: cover; }
.img-item .del {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.5); color: #fff; border: none;
  font-size: 12px; cursor: pointer; display: flex; align-items:center; justify-content:center;
}

/* 进度条 */
.progress-bar-wrap {
  height: 6px; background: #e2e8f0; border-radius: 3px;
  overflow: hidden; margin: 6px 0;
}
.progress-bar-fill {
  height: 100%; border-radius: 3px; background: var(--primary);
  transition: width .5s;
}

/* 文件列表（内部文件库） */
.file-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.file-card {
  background: var(--card-bg); box-shadow: var(--shadow);
  border-radius: var(--radius); padding: 12px; cursor: pointer;
  transition: all .15s; border: 1px solid var(--border);
}
.file-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); transform: translateY(-1px); }
.file-card .f-icon { font-size: 36px; text-align: center; padding: 12px 0; }
.file-card .f-name {
  font-size: 13px; font-weight: 500; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; margin-bottom: 4px;
}
.file-card .f-meta { font-size: 11px; color: var(--text-secondary); }

/* 文件预览模态框 */
.preview-modal .modal { width: 90vw; max-width: 900px; }
.preview-body { padding: 0; }
.preview-body iframe { width: 100%; height: 70vh; border: none; }
.preview-body img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; }
.preview-watermark {
  position: relative; overflow: hidden;
}
.preview-watermark::after {
  content: attr(data-watermark);
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-30deg);
  font-size: 24px; color: rgba(200,0,0,.08);
  white-space: nowrap; pointer-events: none;
  font-weight: bold; letter-spacing: 4px;
}

/* 工具类 */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text-secondary); }
.font-bold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 可展开导航组 */
.nav-group { border-bottom: 1px solid var(--border); }
.nav-parent { display: flex; align-items: center; cursor: pointer; padding: 10px 16px; color: var(--text-secondary); transition: all .15s; border-bottom: none !important; }
.nav-parent:hover { background: var(--hover); color: var(--text); }
.nav-parent .nav-arrow { margin-left: auto; font-size: 10px; transition: transform .2s; }
.nav-parent .nav-arrow.open { transform: rotate(90deg); }
.nav-children { display: none; }
.nav-children.open { display: block; }
.nav-child { padding-left: 36px !important; font-size: 13px; border-bottom: none !important; }
.nav-child .nav-icon { font-size: 14px !important; }

/* 客户搜索建议下拉 */
.cust-suggest { max-height:160px; overflow-y:auto; border:1px solid #ddd; border-radius:6px; display:none; background:#fff; position:relative; z-index:10; font-size:13px; }
.cust-suggest div { padding:8px 12px; cursor:pointer; border-bottom:1px solid #f0f0f0; }
.cust-suggest div:hover { background:#f0f2f5; }
