/* ระบบดีไซน์สำหรับระบบแจ้งซ่อมและติดตามงานอาคารสถานที่ */
/* วิทยาลัยสารพัดช่างพระนครศรีอยุธยา */

:root {
  /* Color System */
  --primary-color: #1e3a8a; /* Deep Royal Blue (สีน้ำเงินหลัก) */
  --primary-light: #2563eb;
  --primary-hover: #172554;
  --secondary-color: #d97706; /* Gold (สีทองสถาบัน) */
  --secondary-hover: #b45309;
  
  --bg-color: #f8fafc;
  --panel-bg: #ffffff;
  --border-color: #e2e8f0;
  
  /* Text Colors */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #ffffff;
  
  /* Status Colors */
  --status-pending: #3b82f6;      /* รอรับเรื่อง: น้ำเงิน */
  --status-received: #06b6d4;     /* รับเรื่องแล้ว: ฟ้าอมเขียว */
  --status-investigating: #0ea5e9; /* กำลังตรวจสอบ: ฟ้า */
  --status-approval: #eab308;     /* รออนุมัติ: เหลือง */
  --status-materials: #8b5cf6;    /* รอวัสดุ/อะไหล่: ม่วง */
  --status-progress: #f97316;     /* กำลังดำเนินการ: ส้ม */
  --status-completed: #10b981;    /* ซ่อมเสร็จแล้ว: เขียว */
  --status-confirmed: #059669;    /* ผู้แจ้งยืนยันผลแล้ว: เขียวเข้ม */
  --status-cancelled: #ef4444;    /* ยกเลิก: แดง */

  /* Urgency Colors */
  --urgency-normal: #10b981;
  --urgency-high: #f97316;
  --urgency-critical: #ef4444;
  
  /* Box Shadow & Borders */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  
  /* Fonts */
  --font-family: 'Sarabun', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Layout Transitions */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  overflow-x: hidden;
}

/* App Container Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  position: relative;
}

/* Logged out styles (Login screen centered) */
.app-container.logged-out #main-layout {
  display: none;
}
.app-container.logged-in #login-view {
  display: none;
}

.view-panel {
  width: 100%;
}

/* Login Panel Layout */
#login-view {
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  padding: 20px;
}

.login-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  animation: fadeInUp 0.5s ease-out;
}

.login-logo {
  width: 100px;
  height: 100px;
  margin: 0 auto 20px;
  background-color: var(--primary-color);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--secondary-color);
  font-size: 3rem;
  box-shadow: var(--shadow-md);
  border: 3px solid var(--secondary-color);
}

.login-card h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 5px;
}

.login-card h3 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--secondary-color);
  margin-bottom: 25px;
}

/* Form Styles */
.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-control, select, textarea {
  width: 100%;
  padding: 12px 16px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  color: var(--text-main);
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
}

.form-control:focus, select:focus, textarea:focus {
  border-color: var(--primary-light);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

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

.btn-primary:hover {
  background-color: var(--primary-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background-color: var(--secondary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  background-color: #f1f5f9;
  color: var(--text-main);
}

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

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.quick-login-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 25px;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

.btn-quick-login {
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 10px 5px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--primary-color);
}

.btn-quick-login:hover {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Authenticated Layout */
.layout-container {
  display: flex;
  width: 100%;
  height: 100vh;
}

/* Sidebar navigation */
.sidebar {
  width: 280px;
  background-color: var(--primary-color);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  transition: all var(--transition-normal);
  z-index: 100;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  background-color: white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  color: var(--primary-color);
  border: 2px solid var(--secondary-color);
  font-weight: bold;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar-title span {
  display: block;
  font-size: 0.75rem;
  color: var(--secondary-color);
  margin-top: 2px;
}

.sidebar-menu {
  list-style: none;
  padding: 20px 12px;
  flex-grow: 1;
  overflow-y: auto;
}

.sidebar-menu li {
  margin-bottom: 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.sidebar-link i {
  width: 20px;
  height: 20px;
}

.sidebar-link:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: white;
}

.sidebar-link.active {
  background-color: var(--secondary-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
}

/* Content Area */
.content-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* App Header */
.app-header {
  height: 70px;
  background-color: var(--panel-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 30px;
  flex-shrink: 0;
  z-index: 90;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

#toggle-sidebar {
  display: none; /* Only visible on tablet/mobile */
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary-color);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: #f1f5f9;
  padding: 6px 12px 6px 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

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

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background-color: #f1f5f9;
  color: var(--text-main);
}

.btn-icon-danger {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ef4444;
  padding: 8px;
  border-radius: 50%;
  transition: all var(--transition-fast);
  margin-left: 5px;
}

.btn-icon-danger:hover {
  background-color: #fee2e2;
}

/* Page Workspace */
.page-workspace {
  flex-grow: 1;
  padding: 30px;
  overflow-y: auto;
  background-color: var(--bg-color);
}

/* Mobile Nav is hidden on desktop */
.mobile-nav {
  display: none;
}

/* Dashboard Styles */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.kpi-card {
  background-color: var(--panel-bg);
  border-radius: var(--radius-md);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: transform var(--transition-fast);
}

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

.kpi-info h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1;
}

.kpi-icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
}

.kpi-icon.blue { background-color: #dbeafe; color: #1e40af; }
.kpi-icon.orange { background-color: #ffedd5; color: #9a3412; }
.kpi-icon.purple { background-color: #f3e8ff; color: #6b21a8; }
.kpi-icon.red { background-color: #fee2e2; color: #991b1b; }
.kpi-icon.green { background-color: #d1fae5; color: #065f46; }
.kpi-icon.teal { background-color: #ccfbf1; color: #115e59; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

@media (max-width: 1024px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  background-color: var(--panel-bg);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.chart-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 20px;
  border-left: 4px solid var(--secondary-color);
  padding-left: 10px;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Card components */
.card {
  background-color: var(--panel-bg);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.card-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Table styles */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  background-color: var(--panel-bg);
}

th {
  background-color: #f8fafc;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 14px 18px;
  border-bottom: 2px solid var(--border-color);
}

td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
  color: var(--text-main);
}

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

tr:hover td {
  background-color: #f8fafc;
}

/* Search and Filter Panel */
.filter-panel {
  background-color: var(--panel-bg);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
}

.filter-group {
  display: flex;
  flex-direction: column;
}

.filter-group label {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.filter-group .form-control, .filter-group select {
  padding: 8px 12px;
  font-size: 0.85rem;
  background-color: #f8fafc;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 20px;
}

/* Badges - Status */
.badge-pending { background-color: #dbeafe; color: #1e40af; }
.badge-received { background-color: #cffafe; color: #0891b2; }
.badge-investigating { background-color: #e0f2fe; color: #0369a1; }
.badge-approval { background-color: #fef9c3; color: #854d0e; }
.badge-materials { background-color: #f3e8ff; color: #6b21a8; }
.badge-progress { background-color: #ffedd5; color: #c2410c; }
.badge-completed { background-color: #d1fae5; color: #065f46; }
.badge-confirmed { background-color: #a7f3d0; color: #047857; }
.badge-cancelled { background-color: #fee2e2; color: #b91c1c; }

/* Badges - Urgency */
.badge-urgency-normal { background-color: #e6f4ea; color: #137333; }
.badge-urgency-high { background-color: #feefe3; color: #b06000; }
.badge-urgency-critical { background-color: #fce8e6; color: #c5221f; }

/* Form Wizard & File Upload Zone */
.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 30px;
  text-align: center;
  cursor: pointer;
  background-color: #f8fafc;
  transition: all var(--transition-fast);
}

.upload-zone:hover {
  border-color: var(--primary-light);
  background-color: #f0fdf4;
}

.upload-icon {
  font-size: 2rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.upload-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.upload-preview {
  margin-top: 15px;
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-md);
  display: none;
  object-fit: cover;
  box-shadow: var(--shadow-sm);
}

/* Timeline component */
.timeline {
  position: relative;
  padding-left: 30px;
  margin-top: 20px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 5px;
  bottom: 5px;
  width: 2px;
  background-color: var(--border-color);
}

.timeline-item {
  position: relative;
  margin-bottom: 25px;
}

.timeline-item:last-child {
  margin-bottom: 0;
}

.timeline-marker {
  position: absolute;
  left: -30px;
  top: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: var(--border-color);
  border: 4px solid var(--panel-bg);
  box-shadow: 0 0 0 1px var(--border-color);
}

.timeline-marker.completed {
  background-color: var(--status-completed);
}

.timeline-marker.active {
  background-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(30, 58, 138, 0.2);
}

.timeline-marker.cancelled {
  background-color: var(--status-cancelled);
}

.timeline-content {
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 15px 20px;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.timeline-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
}

.timeline-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.timeline-note {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.timeline-user {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Material Expenses Editor */
.cost-table {
  width: 100%;
  margin-top: 15px;
}

.cost-total-row {
  font-weight: 700;
  background-color: #f8fafc;
  border-top: 2px solid var(--border-color);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: white;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  min-width: 300px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 6px solid var(--primary-color);
  animation: slideInRight 0.3s ease-out;
  font-size: 0.9rem;
}

.toast.success { border-left-color: var(--status-completed); }
.toast.error { border-left-color: var(--status-cancelled); }
.toast.info { border-left-color: var(--status-pending); }
.toast.warning { border-left-color: var(--status-approval); }

/* Grid Layout for Detailed View */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

.detail-info-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 20px;
}

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

.info-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.info-value {
  font-size: 0.95rem;
  color: var(--text-main);
  font-weight: 500;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* Responsive Overrides */
@media (max-width: 768px) {
  /* Sidebar behaves as a slide-over panel, initially hidden */
  .sidebar {
    position: absolute;
    left: -280px;
    height: 100vh;
  }
  
  .sidebar.open {
    left: 0;
  }
  
  #toggle-sidebar {
    display: flex;
  }
  
  /* Page workspace spacing */
  .page-workspace {
    padding: 15px;
    padding-bottom: 90px; /* Space for bottom tab bar */
  }
  
  /* Show mobile bottom tab navigation */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background-color: var(--primary-color);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
    justify-content: space-around;
    align-items: center;
  }
  
  .mobile-tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.7rem;
    text-decoration: none;
    cursor: pointer;
  }
  
  .mobile-tab-item i {
    width: 20px;
    height: 20px;
    margin-bottom: 2px;
  }
  
  .mobile-tab-item.active {
    color: var(--secondary-color);
  }
  
  /* Header customizations */
  .app-header {
    padding: 0 15px;
  }
  
  .user-profile-badge {
    padding: 4px;
    background: none;
    border: none;
  }
  
  .user-info {
    display: none; /* Hide name on mobile header */
  }
}

/* Special Dashboard Overrides */
.text-danger { color: var(--status-cancelled) !important; }
.text-success { color: var(--status-completed) !important; }
.text-warning { color: var(--status-approval) !important; }

/* Empty state styling */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 3rem;
  margin-bottom: 15px;
  color: #cbd5e1;
}

/* Image preview thumbnail inside details page */
.damage-img-container {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: #f1f5f9;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.damage-img-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.excel-drop-zone {
  border: 2px dashed var(--primary-light);
  background-color: #eff6ff;
}

.excel-drop-zone:hover {
  background-color: #dbeafe;
}
