:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --success-light: #34d399;
  --warning: #f59e0b;
  --warning-light: #fbbf24;
  --danger: #ef4444;
  --danger-light: #f87171;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-width: 240px;
  --header-height: 0px;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

.app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-700);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
}

.nav-menu {
  list-style: none;
  padding: 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 2px;
  font-size: 14px;
  color: var(--gray-300);
}

.nav-item:hover {
  background: var(--gray-700);
  color: white;
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

/* Main Content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
}

.subtitle {
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-badges {
  padding-left: 113px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.blue { background: #dbeafe; color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--gray-500);
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  margin-bottom: 16px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
}

.card-body {
  padding: 20px;
}

/* Search & Filters */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 10px;
  color: var(--gray-400);
  pointer-events: none;
}

.search-box input {
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  width: 260px;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}

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

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  background: white;
  cursor: pointer;
  color: var(--gray-700);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

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

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #059669; }

.btn-warning {
  background: var(--warning);
  color: white;
}
.btn-warning:hover { background: #d97706; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #dc2626; }

.btn-outline {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); }

.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead {
  background: var(--gray-50);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: var(--gray-50);
}

/* Status Badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-running {
  background: #d1fae5;
  color: #065f46;
}

.badge-setup {
  background: #dbeafe;
  color: #1e40af;
}

.badge-storage {
  background: #fef3c7;
  color: #92400e;
}

.badge-in {
  background: #d1fae5;
  color: #065f46;
}

.badge-out {
  background: #fee2e2;
  color: #991b1b;
}

.badge-ok {
  background: #d1fae5;
  color: #065f46;
}

.badge-low {
  background: #fee2e2;
  color: #991b1b;
}

.badge-normal {
  background: #dbeafe;
  color: #1e40af;
}

.badge-freq-H {
  background: #fee2e2;
  color: #991b1b;
}

.badge-freq-M {
  background: #fef3c7;
  color: #92400e;
}

.badge-freq-L {
  background: #d1fae5;
  color: #065f46;
}

/* Chart Bars */
.chart-bar-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chart-bar-label {
  width: 80px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  text-align: right;
  flex-shrink: 0;
}

.chart-bar-track {
  flex: 1;
  height: 28px;
  background: var(--gray-100);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  padding-left: 10px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  min-width: 30px;
}

.chart-bar-count {
  width: 40px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  text-align: right;
  flex-shrink: 0;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--gray-200);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--gray-600);
  transition: all 0.2s;
}

.pagination button:hover { background: var(--gray-50); border-color: var(--gray-300); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(2px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--gray-400);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover { background: var(--gray-100); color: var(--gray-600); }

.modal-body {
  padding: 24px;
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

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

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
}

/* Action buttons in table */
.action-btns {
  display: flex;
  gap: 6px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* Daily report content cell */
.daily-content-cell {
  max-width: 360px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
  font-size: 12px;
  color: var(--gray-600);
}

.badge-PM { background: #dbeafe; color: #1e40af; }
.badge-TS { background: #fee2e2; color: #991b1b; }
.badge-SU { background: #d1fae5; color: #065f46; }
.badge-DC { background: #fef3c7; color: #92400e; }
.badge-move { background: #e0e7ff; color: #3730a3; }
.badge-other { background: #f3f4f6; color: #374151; }

.workers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.workers-list .worker-tag {
  display: inline-block;
  padding: 1px 8px;
  background: var(--gray-100);
  border-radius: 4px;
  font-size: 12px;
  color: var(--gray-600);
}

/* Modal wide variant */
.modal.modal-wide {
  max-width: 700px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Responsive */
@media (max-width: 768px) {
  body { overflow: auto; }

  .app { flex-direction: column; height: auto; min-height: 100vh; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-bottom: 1px solid var(--gray-700);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .sidebar-header { display: none; }

  .nav-menu {
    display: flex;
    padding: 8px;
    gap: 4px;
    flex-wrap: nowrap;
  }

  .nav-item {
    flex-direction: column;
    padding: 8px 12px;
    font-size: 11px;
    gap: 4px;
    white-space: nowrap;
    margin-bottom: 0;
  }

  .nav-item span { display: block; font-size: 10px; }

  .main-content {
    padding: 12px;
    overflow-y: visible;
  }

  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .page-header h1 { font-size: 20px; }
  .subtitle { font-size: 12px; }

  .page-header > div > div:last-child {
    padding-left: 0 !important;
    gap: 8px !important;
    width: 100%;
  }

  .header-badges {
    padding-left: 0 !important;
    gap: 6px !important;
  }

  .header-actions { width: 100%; justify-content: flex-start; }
  .header-actions .btn { font-size: 13px; padding: 6px 12px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; border-radius: 10px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 11px; }

  .dashboard-grid { grid-template-columns: 1fr; gap: 12px; }

  .card { margin-bottom: 12px; }
  .card-header { padding: 12px 14px; }
  .card-header h3 { font-size: 14px; }
  .card-body { padding: 14px; }

  .search-box { width: 100%; }
  .search-box input { width: 100% !important; font-size: 14px; }
  .filter-select { font-size: 13px; padding: 6px 10px; }

  .data-table { font-size: 12px; }
  .data-table th { padding: 8px 10px; font-size: 11px; }
  .data-table td { padding: 8px 10px; white-space: normal; }

  .btn { font-size: 13px; padding: 6px 12px; }
  .btn-sm { padding: 3px 8px; font-size: 12px; }

  .modal { width: 95%; max-width: none; margin: 10px; }
  .modal-header { padding: 14px 16px; }
  .modal-header h2 { font-size: 16px; }
  .modal-body { padding: 16px; }

  .form-row { grid-template-columns: 1fr; gap: 0; }
  .form-group input, .form-group select, .form-group textarea { font-size: 16px; }

  .pagination button { padding: 5px 10px; font-size: 12px; }

  .chart-bar-label { width: 60px; font-size: 11px; }
  .chart-bar-track { height: 24px; }
  .chart-bar-fill { font-size: 11px; }
  .chart-bar-count { font-size: 11px; width: 30px; }

  .workers-list { gap: 3px; }
  .workers-list .worker-tag { font-size: 11px; padding: 1px 6px; }

  .badge { font-size: 11px; padding: 2px 8px; }

  .daily-content-cell { max-width: 200px; font-size: 11px; }

  .page-header > div > div:first-child > div:last-child {
    font-size: 11px !important;
  }

  .page-header > div > div:first-child > div:last-child > div {
    padding: 4px 10px !important;
    font-size: 11px !important;
  }

  .page-header > div > div:first-child > div:last-child > div span {
    font-size: 11px !important;
  }

  #shift-entry-tbody input {
    font-size: 14px !important;
    padding: 6px 8px !important;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  * {
    -webkit-tap-highlight-color: transparent;
  }

  input, select, textarea, button {
    touch-action: manipulation;
  }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 10px; gap: 8px; }
  .stat-value { font-size: 20px; }
  .stat-icon { width: 36px; height: 36px; }

  .nav-item { padding: 6px 10px; }
  .nav-item svg { width: 18px; height: 18px; }
  .nav-item span { font-size: 9px; }

  .main-content { padding: 10px; }
  .page-header h1 { font-size: 18px; }
}
