/* ============================================
   Supplier PLM - 產品開發管理系統
   ============================================ */

:root {
  --bg: #0b1120;
  --bg-surface: #111827;
  --bg-elevated: #1a2332;
  --border: #1e293b;
  --border-light: #2d3a4e;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --primary: #22c55e;
  --primary-hover: #16a34a;
  --primary-bg: rgba(34, 197, 94, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.1);
  --sidebar-w: 220px;
  --header-h: 56px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* 通用隱藏 class */
.hidden { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang HK", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ TOAST ============ */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 24px; padding: 10px 20px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ LOGIN ============ */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(1400px 900px at 50% 30%, #0f1a2e, var(--bg));
}

/* 背景裝飾圓 */
.login-screen::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(34,197,94,0.03), transparent 70%);
  top: -200px; right: -200px;
  pointer-events: none;
}
.login-screen::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59,130,246,0.03), transparent 70%);
  bottom: -150px; left: -150px;
  pointer-events: none;
}

.login-card {
  position: relative;
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid var(--border); border-radius: 20px;
  padding: 44px 36px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
  backdrop-filter: blur(16px);
}
.login-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34,197,94,0.3), transparent);
  border-radius: 20px 20px 0 0;
}

.login-logo { margin-bottom: 20px; display: flex; justify-content: center; }
.login-logo svg { filter: drop-shadow(0 4px 12px rgba(34,197,94,0.3)); }

.login-card h1 {
  font-size: 26px; font-weight: 700; margin-bottom: 4px;
  text-align: center;
  background: linear-gradient(180deg, #e2e8f0, #94a3b8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-subtitle { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 2px; }
.login-hint { text-align: center; color: var(--text-muted); font-size: 12px; margin-bottom: 28px; letter-spacing: 0.3px; }
.login-card form { text-align: left; }

/* ============ APP SHELL ============ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh; overflow: hidden;
}
.app-shell.hidden { display: none; }

/* ============ HEADER ============ */
.app-header {
  grid-area: header;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: rgba(11, 17, 32, 0.85);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-brand { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 16px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 13px; color: var(--text-secondary); }

/* ============ SIDEBAR ============ */
.sidebar {
  grid-area: sidebar;
  display: flex; flex-direction: column;
  background: rgba(17, 24, 39, 0.6);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: transform 0.25s ease;
}
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none;
  font-size: 14px; transition: all 0.15s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); }
.nav-item .nav-icon { flex-shrink: 0; }
.nav-item.nav-hidden { display: none; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.sidebar-version { font-size: 12px; color: var(--text-muted); }

/* ============ ROLE BADGE (Header) ============ */
.role-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  white-space: nowrap;
}
.role-badge--admin     { background: #1e3a5f; color: #93c5fd; }
.role-badge--manager   { background: #1e4a2e; color: #86efac; }
.role-badge--technician{ background: #4a3510; color: #fcd34d; }

/* ============ MAIN CONTENT ============ */
.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 24px;
}

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }
.page-actions { display: flex; gap: 8px; }

/* ============ STATS CARDS ============ */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.stat-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* 技術員 Dashboard 狀態卡片顏色變體 */
.stat-card--warn    { border-left: 3px solid var(--danger); }
.stat-card--info    { border-left: 3px solid var(--info); }
.stat-card--shipped { border-left: 3px solid var(--warning); }
.stat-card--review  { border-left: 3px solid #a78bfa; }
.stat-card--ok      { border-left: 3px solid var(--primary); }
.stat-card--fix     { border-left: 3px solid var(--danger); }

/* 技術員工作台 - 任務項目 */
.tech-task-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: 6px;
  background: rgba(0,0,0,0.08);
  transition: background 0.15s;
}
.tech-task-item:hover { background: rgba(255,255,255,0.03); }

/* ============ CARD ============ */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--text-secondary); }

/* ============ TABLE ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 12px;
  color: var(--text-muted); font-weight: 500; font-size: 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.3px;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid rgba(30, 41, 59, 0.5); }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 4px; }

/* ============ BADGE ============ */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.badge-green { background: var(--primary-bg); color: #86efac; }
.badge-yellow { background: var(--warning-bg); color: #fdba74; }
.badge-red { background: var(--danger-bg); color: #fca5a5; }
.badge-blue { background: var(--info-bg); color: #93c5fd; }
.badge-gray { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elevated); color: var(--text);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.15s ease; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--border-light); background: #1e293b; }
.btn.primary {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border-color: #16a34a; color: #04120a; font-weight: 600;
}
.btn.primary:hover { background: linear-gradient(180deg, #2dd96b, #22c55e); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--text-secondary);
  cursor: pointer; transition: all 0.15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }

/* ============ FORM ============ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .field-full { grid-column: 1 / -1; }
.form-grid .field-half { grid-column: span 1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: rgba(11, 17, 32, 0.6);
  color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}
.field textarea { min-height: 80px; resize: vertical; }
.form-actions {
  grid-column: 1 / -1;
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px;
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  width: 100%; max-width: 640px; max-height: 85vh;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.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; margin: 0; color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }

/* ============ TABS ============ */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 18px; font-size: 13px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s ease; background: none; border-top: none; border-left: none; border-right: none;
  font-family: inherit;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============ TIMELINE ============ */
.timeline { position: relative; padding-left: 28px; }
.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:last-child { margin-bottom: 0; }
.timeline-dot {
  position: absolute; left: -24px; top: 4px;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--bg-surface);
}
.timeline-dot.green { border-color: var(--primary); background: var(--primary-bg); }
.timeline-dot.yellow { border-color: var(--warning); background: var(--warning-bg); }
.timeline-dot.red { border-color: var(--danger); background: var(--danger-bg); }
.timeline-dot.blue { border-color: var(--info); background: var(--info-bg); }
.timeline-content { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.timeline-content .tl-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.timeline-content .tl-version { font-weight: 600; font-size: 14px; }
.timeline-content .tl-date { font-size: 12px; color: var(--text-muted); }
.timeline-content .tl-body { font-size: 13px; color: var(--text-secondary); }
.timeline-content .tl-body p { margin-top: 4px; }

/* ============ BRAND LIST ============ */
.brand-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.brand-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: all 0.15s ease;
}
.brand-card:hover { border-color: var(--border-light); background: rgba(255,255,255,0.03); }
.brand-card .brand-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.brand-card .brand-contact { font-size: 13px; color: var(--text-secondary); }
.brand-card .brand-stats { display: flex; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-muted); }

/* ============ PRODUCT DETAIL ============ */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-field .dl { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 2px; }
.detail-field .dd { font-size: 14px; color: var(--text); }

/* ============ EMPTY STATE ============ */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state svg { margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ============ CHART CONTAINER ============ */
.chart-wrap { max-width: 100%; padding: 8px 0; }

/* ============ FILTER BAR ============ */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px;
}
.filter-bar input, .filter-bar select {
  padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: rgba(11, 17, 32, 0.6);
  color: var(--text); font-size: 13px; font-family: inherit;
}
.filter-bar input { min-width: 200px; }
.filter-bar select { min-width: 140px; }

/* ============ SAMPLE STATUS ============ */
.sample-status { display: inline-flex; align-items: center; gap: 5px; }
.sample-status .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--primary); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }
.dot-blue { background: var(--info); }
.dot-gray { background: var(--text-muted); }

/* ============ RESPONSIVE ============ */
.sidebar-toggle { display: none; }

@media (max-width: 1024px) {
  :root { --sidebar-w: 60px; }
  .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-footer { display: none; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: 220px; z-index: 200;
    transform: translateX(-100%);
    background: var(--bg-surface);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex !important; }
  .nav-item span { display: inline; }
  .nav-item { justify-content: flex-start; padding: 10px 14px; }
  .sidebar-footer { display: flex; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .brand-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .filter-bar input { min-width: 140px; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}
