/* =============================================
   瑞昌藥局 人時生產力預警系統 - Custom Styles
   ============================================= */

:root {
  --primary: #1a56db;
  --primary-dark: #1240a8;
  --primary-light: #e8f0fe;
  --sidebar-width: 240px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1a56db;
  --header-height: 60px;
  --green: #16a34a;
  --green-light: #dcfce7;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --gray: #6b7280;
  --border: #e5e7eb;
  --bg: #f8fafc;
  --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --card-shadow-hover: 0 4px 12px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', 'Microsoft JhengHei', '微軟正黑體', sans-serif;
  background: var(--bg);
  color: #1e293b;
  margin: 0;
  overflow-x: hidden;
}

/* =============================================
   LAYOUT
   ============================================= */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid #1e293b;
  text-decoration: none;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.sidebar-brand .brand-title {
  color: white;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.3;
  display: block;
}

.sidebar-brand .brand-sub {
  color: #64748b;
  font-size: 0.7rem;
  display: block;
  margin-top: 2px;
}

.sidebar-nav {
  padding: 0.75rem 0;
  flex: 1;
}

.sidebar-section-label {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.15s;
  border-radius: 0;
  margin: 1px 0.5rem;
  border-radius: 6px;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: white;
}

.sidebar-nav a.active {
  background: var(--primary);
  color: white;
  font-weight: 500;
}

.sidebar-nav a .nav-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.9rem;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid #1e293b;
  color: #475569;
  font-size: 0.72rem;
  text-align: center;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.page-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.page-header-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Page Content */
.page-content {
  padding: 1.5rem;
  flex: 1;
}

/* =============================================
   SUMMARY CARDS
   ============================================= */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-card {
  background: white;
  border-radius: 10px;
  padding: 1.25rem 1rem;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-card .card-label {
  font-size: 0.75rem;
  color: var(--gray);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-card .card-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: #1e293b;
}

.summary-card .card-sub {
  font-size: 0.75rem;
  color: var(--gray);
}

.summary-card.green .card-value { color: var(--green); }
.summary-card.yellow .card-value { color: var(--yellow); }
.summary-card.red .card-value { color: var(--red); }
.summary-card.blue .card-value { color: var(--primary); }

.summary-card .card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.summary-card.green .card-icon { background: var(--green-light); color: var(--green); }
.summary-card.yellow .card-icon { background: var(--yellow-light); color: var(--yellow); }
.summary-card.red .card-icon { background: var(--red-light); color: var(--red); }
.summary-card.blue .card-icon { background: var(--primary-light); color: var(--primary); }

/* =============================================
   STORE ALERT CARDS
   ============================================= */
.store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.store-card {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.store-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.store-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.store-card.green::before { background: var(--green); }
.store-card.yellow::before { background: var(--yellow); }
.store-card.red::before { background: var(--red); }
.store-card.no-data::before { background: #94a3b8; }

.store-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.store-name {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.store-code-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: #f1f5f9;
  color: #64748b;
}

.status-indicator {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.status-indicator.green { background: var(--green-light); color: var(--green); }
.status-indicator.yellow { background: var(--yellow-light); color: var(--yellow); }
.status-indicator.red { background: var(--red-light); color: var(--red); }
.status-indicator.no-data { background: #f1f5f9; color: #94a3b8; }

.store-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
}

.metric-value.highlight-green { color: var(--green); }
.metric-value.highlight-yellow { color: var(--yellow); }
.metric-value.highlight-red { color: var(--red); }

.store-card-footer {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.achievement-bar {
  height: 6px;
  border-radius: 3px;
  background: #f1f5f9;
  overflow: hidden;
  margin-top: 0.5rem;
}

.achievement-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.achievement-fill.green { background: var(--green); }
.achievement-fill.yellow { background: var(--yellow); }
.achievement-fill.red { background: var(--red); }

/* =============================================
   SECTION HEADER
   ============================================= */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =============================================
   TABLES
   ============================================= */
.table-container {
  background: white;
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.table-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
}

.table-responsive {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: #f8fafc;
  padding: 0.7rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid #f1f5f9;
  color: #374151;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

/* =============================================
   STATUS BADGES
   ============================================= */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-status.green { background: var(--green-light); color: var(--green); }
.badge-status.yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-status.red { background: var(--red-light); color: var(--red); }
.badge-status.gray { background: #f1f5f9; color: #64748b; }

.badge-position {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
}

.badge-position.manager { background: #fef3c7; color: #92400e; }
.badge-position.pharmacist { background: #e0f2fe; color: #0369a1; }
.badge-position.fulltime { background: #f0fdf4; color: #166534; }
.badge-position.parttime { background: #faf5ff; color: #7c3aed; }

/* =============================================
   FORMS & MODALS
   ============================================= */
.form-section {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.form-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.35rem;
}

.form-group label .required {
  color: var(--red);
  margin-left: 3px;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 0.85rem;
  color: #1e293b;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.form-control.is-invalid {
  border-color: var(--red);
}

select.form-control {
  cursor: pointer;
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-outline {
  background: transparent;
  border: 1px solid #d1d5db;
  color: #374151;
}

.btn-outline:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #9ca3af;
}

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-success {
  background: var(--green);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #15803d;
}

.btn-warning {
  background: var(--yellow);
  color: white;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

.btn-icon {
  padding: 0.4rem;
  width: 32px;
  height: 32px;
  justify-content: center;
}

/* =============================================
   MONTH SELECTOR
   ============================================= */
.month-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
}

.month-selector select {
  border: none;
  outline: none;
  font-size: 0.85rem;
  color: #1e293b;
  cursor: pointer;
  background: transparent;
}

/* =============================================
   ALERTS & NOTICES
   ============================================= */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.alert-success { background: var(--green-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: var(--yellow-light); color: #92400e; border: 1px solid #fde68a; }
.alert-danger  { background: var(--red-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: var(--primary-light); color: #1e3a8a; border: 1px solid #bfdbfe; }

/* =============================================
   PREVIEW BOX (Input page)
   ============================================= */
.preview-box {
  background: #f8fafc;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-top: 1rem;
}

.preview-box.green { border-color: var(--green); background: var(--green-light); }
.preview-box.yellow { border-color: var(--yellow); background: var(--yellow-light); }
.preview-box.red { border-color: var(--red); background: var(--red-light); }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.preview-item {
  text-align: center;
}

.preview-item .preview-label {
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 4px;
}

.preview-item .preview-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #1e293b;
}

/* =============================================
   CHARTS
   ============================================= */
.chart-container {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 1rem;
}

/* =============================================
   LOADING SPINNER
   ============================================= */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: #94a3b8;
  font-size: 0.9rem;
  gap: 0.5rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #94a3b8;
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h4 {
  color: #475569;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

/* =============================================
   TOASTS
   ============================================= */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: white;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  border-left: 4px solid var(--primary);
  font-size: 0.85rem;
  color: #1e293b;
  animation: slideIn 0.3s ease;
  pointer-events: all;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }
.toast.warning { border-color: var(--yellow); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* =============================================
   MODAL OVERRIDES
   ============================================= */
.modal-content {
  border-radius: 12px;
  border: none;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 1rem 1.25rem;
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1e293b;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
}

/* =============================================
   WEIGHT DISPLAY
   ============================================= */
.weight-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
  font-family: monospace;
}

/* =============================================
   SEARCH INPUT
   ============================================= */
.search-input-wrapper {
  position: relative;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.85rem;
}

.search-input-wrapper .form-control {
  padding-left: 2rem;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .store-grid {
    grid-template-columns: 1fr;
  }

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

  .page-content {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .summary-cards {
    grid-template-columns: 1fr 1fr;
  }
}

/* =============================================
   UTILITY CLASSES
   ============================================= */
.text-muted { color: #94a3b8; }
.text-success { color: var(--green); }
.text-warning { color: var(--yellow); }
.text-danger { color: var(--red); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fs-sm { font-size: 0.8rem; }
.fs-xs { font-size: 0.72rem; }
.gap-2 { gap: 0.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-0 { margin-bottom: 0; }
.mt-auto { margin-top: auto; }
