:root {
  --primary: #1a6b3c;
  --primary-light: #2d9a5a;
  --primary-dark: #0f4a28;
  --accent: #f5a623;
  --danger: #e74c3c;
  --warning: #f39c12;
  --success: #27ae60;
  --info: #3498db;
  --bg: #f0f4f1;
  --card: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dce4dd;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 10px;
}

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

body {
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px;
  width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
}

.login-card .logo { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; color: var(--primary-dark); margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-light); margin-bottom: 28px; font-size: 14px; }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group select, .form-group input, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-group select:focus, .form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 80px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #d4891a; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Layout */
.app-layout { display: none; min-height: 100vh; }
.app-layout.active { display: flex; }

.sidebar {
  width: 240px;
  background: var(--primary-dark);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header .logo-sm { font-size: 28px; }
.sidebar-header h2 { font-size: 15px; margin-top: 4px; opacity: 0.9; }

.sidebar-user {
  padding: 16px 20px;
  background: rgba(255,255,255,0.08);
  margin: 12px;
  border-radius: 8px;
  font-size: 13px;
}
.sidebar-user .dept-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  margin-top: 4px;
}

.sidebar-nav { flex: 1; padding: 8px 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  margin-bottom: 4px;
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-item.active { background: rgba(255,255,255,0.15); color: white; font-weight: 600; }
.nav-badge {
  position: absolute;
  right: 12px;
  background: var(--danger);
  color: white;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 700;
  animation: pulse 1.5s infinite;
}

.main-content {
  margin-left: 240px;
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 24px; color: var(--primary-dark); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.urgent { border-left-color: var(--danger); }
.stat-card.success { border-left-color: var(--success); }
.stat-card .stat-value { font-size: 32px; font-weight: 700; color: var(--primary-dark); }
.stat-card .stat-label { font-size: 13px; color: var(--text-light); margin-top: 4px; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 15px;
}
.card-body { padding: 20px; }

/* Order cards */
.order-list { display: flex; flex-direction: column; gap: 12px; }

.order-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  border-left: 4px solid var(--primary);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.order-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.12); }
.order-card.urgent { border-left-color: var(--danger); animation: urgentGlow 2s infinite; }
.order-card.completed { border-left-color: var(--success); opacity: 0.85; }
.order-card.rejected { border-left-color: var(--text-light); }

.order-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}
.order-no { font-weight: 700; font-size: 16px; color: var(--primary-dark); }
.order-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-standard { background: #e8f5e9; color: #2e7d32; }
.badge-custom { background: #fff3e0; color: #e65100; }
.badge-minor_mod { background: #e3f2fd; color: #1565c0; }
.badge-major_mod { background: #fce4ec; color: #c62828; }
.badge-pre_order { background: #f3e5f5; color: #7b1fa2; }
.badge-post_order { background: #e0f2f1; color: #00695c; }
.badge-pending { background: #fff8e1; color: #f57f17; }
.badge-in_progress { background: #e3f2fd; color: #1565c0; }
.badge-completed { background: #e8f5e9; color: #2e7d32; }
.badge-rejected { background: #ffebee; color: #c62828; }

.sla-timer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
}
.sla-normal { background: #e8f5e9; color: #2e7d32; }
.sla-urgent { background: #fff3e0; color: #e65100; animation: pulse 1s infinite; }
.sla-overdue { background: #ffebee; color: #c62828; animation: pulse 0.8s infinite; }

/* Workflow steps */
.workflow-steps {
  display: flex;
  gap: 0;
  margin: 20px 0;
  overflow-x: auto;
}
.step {
  flex: 1;
  text-align: center;
  position: relative;
  min-width: 120px;
}
.step::after {
  content: '';
  position: absolute;
  top: 18px;
  right: -50%;
  width: 100%;
  height: 3px;
  background: var(--border);
  z-index: 0;
}
.step:last-child::after { display: none; }
.step-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  position: relative;
  z-index: 1;
  margin-bottom: 6px;
}
.step.done .step-icon { background: var(--success); color: white; }
.step.active .step-icon { background: var(--accent); color: white; animation: pulse 1.5s infinite; }
.step.rejected .step-icon { background: var(--danger); color: white; }
.step-label { font-size: 12px; color: var(--text-light); }
.step.done .step-label, .step.active .step-label { color: var(--text); font-weight: 600; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 18px; }
.modal-close {
  background: none; border: none; font-size: 24px;
  cursor: pointer; color: var(--text-light); padding: 4px;
}
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row .form-group.full { grid-column: 1 / -1; }

.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.radio-option:has(input:checked) { border-color: var(--primary); background: #e8f5e9; }
.radio-option input { accent-color: var(--primary); }

/* Notifications panel */
.notif-panel {
  position: fixed;
  top: 0; right: -400px;
  width: 400px;
  height: 100vh;
  background: var(--card);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 200;
  transition: right 0.3s;
  display: flex;
  flex-direction: column;
}
.notif-panel.open { right: 0; }
.notif-panel-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary-dark);
  color: white;
}
.notif-list { flex: 1; overflow-y: auto; padding: 12px; }
.notif-item {
  padding: 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  transition: background 0.2s;
}
.notif-item.unread { background: #fff8e1; border-color: var(--accent); }
.notif-item.urgent { background: #ffebee; border-color: var(--danger); }
.notif-item .notif-title { font-weight: 600; margin-bottom: 4px; }
.notif-item .notif-time { font-size: 11px; color: var(--text-light); margin-top: 6px; }

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--card);
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  border-left: 4px solid var(--primary);
  max-width: 380px;
  animation: slideIn 0.3s ease;
  font-size: 14px;
}
.toast.urgent { border-left-color: var(--danger); background: #fff5f5; }
.toast.success { border-left-color: var(--success); }
.toast .toast-title { font-weight: 700; margin-bottom: 4px; }

/* Alert banner */
.alert-banner {
  display: none;
  background: linear-gradient(90deg, var(--danger), #c0392b);
  color: white;
  padding: 12px 24px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  animation: pulse 1.5s infinite;
  position: fixed;
  top: 0; left: 240px; right: 0;
  z-index: 50;
}
.alert-banner.show { display: block; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* Eval result */
.eval-result {
  background: #f8faf8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.eval-result.success { border-color: var(--success); background: #e8f5e9; }
.eval-result.error { border-color: var(--danger); background: #ffebee; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.detail-item { font-size: 13px; }
.detail-item .label { color: var(--text-light); font-size: 12px; }
.detail-item .value { font-weight: 600; margin-top: 2px; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
@keyframes urgentGlow {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 20px rgba(231,76,60,0.3); }
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.voice-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  margin: 8px 12px;
  cursor: pointer;
}
.voice-toggle input { accent-color: var(--accent); }

.field-hint { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.sla-notice { background: #fff8e1; padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-top: 12px; }
.calc-box { background: #f0f7f2; border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-top: 16px; }
.contact-section { border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.contact-section h4 { margin-bottom: 12px; color: var(--primary-dark); }
.contact-row { margin-bottom: 8px; }


/* Mobile top bar (hidden on desktop) */
.mobile-topbar,
.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0);
    background: var(--primary-dark);
    color: #fff;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  .mobile-menu-btn,
  .mobile-notif-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    flex-shrink: 0;
  }

  .mobile-topbar-center {
    flex: 1;
    text-align: center;
    padding: 0 8px;
    min-width: 0;
  }

  .mobile-topbar-title {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 150;
  }

  .app-layout.mobile-menu-open .sidebar-backdrop {
    display: block;
  }

  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 160;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  .app-layout.mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-header h2,
  .sidebar-user,
  .nav-item span:not(.nav-badge) {
    display: block !important;
  }

  .main-content {
    margin-left: 0;
    padding: 72px 16px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
    width: 100%;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 16px;
  }

  .page-header h1 {
    font-size: 20px;
  }

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

  .stat-card {
    padding: 14px;
  }

  .stat-value {
    font-size: 28px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .card-body {
    padding: 14px;
  }

  .card-body table {
    font-size: 13px;
  }

  .card-body th,
  .card-body td {
    padding: 8px 6px !important;
  }

  .order-card {
    padding: 14px;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
  }

  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .alert-banner {
    left: 0;
    right: 0;
    top: 56px;
  }

  .notif-panel {
    width: 100%;
    right: -100%;
    top: 0;
    height: 100vh;
    padding-top: env(safe-area-inset-top, 0);
  }

  .login-card {
    margin: 16px;
    padding: 28px 20px;
    width: calc(100% - 32px);
    max-width: 420px;
  }

  .login-screen {
    padding: 16px;
    align-items: flex-start;
    padding-top: 10vh;
  }

  .btn {
    min-height: 44px;
  }

  .nav-item {
    padding: 14px 16px;
    font-size: 15px;
  }

  .voice-toggle {
    margin: 8px 12px 12px;
  }
}
