@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --primary-color: #2E5A36;
  --primary-dark: #1E3F24;
  --primary-light: #E8F4EA;
  --accent-1: #E0F0E3;
  --accent-2: #D2E7D6;
  --accent-3: #C8E1CC;
  --accent-4: #B8D8BE;
  
  --bg-color: #F8F9FA;
  --card-bg: #FFFFFF;
  --text-main: #2C3E50;
  --text-muted: #7F8C8D;
  --border-color: #E2E8F0;
  
  --success: #2ECC71;
  --info: #3498DB;
  --warning: #F1C40F;
  --danger: #E74C3C;
  
  --font-family: 'Sarabun', sans-serif;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --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);
  --radius: 12px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Login Screen --- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary-light) 0%, #FFFFFF 100%);
}

.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 450px;
  text-align: center;
  border: 1px solid var(--accent-3);
  animation: fadeInUp 0.5s ease;
}

.login-logo {
  width: 130px;
  height: 130px;
  margin-bottom: 20px;
  object-fit: contain;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 5px;
}

.login-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--primary-dark);
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 1rem;
  transition: all 0.3s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(46, 90, 54, 0.15);
}

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

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

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

.btn-secondary {
  background-color: var(--accent-1);
  color: var(--primary-dark);
  border: 1px solid var(--accent-3);
}

.btn-secondary:hover {
  background-color: var(--accent-2);
}

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

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

.error-message {
  background-color: #FDF2F2;
  color: var(--danger);
  border: 1px solid #FDE8E8;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* --- Main Layout --- */
.app-header {
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

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

.header-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.header-title-container {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-dark);
}

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

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

.user-profile {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.user-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary-dark);
}

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

.logout-btn {
  background: transparent;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.3s ease;
}

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

.app-container {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 75px);
}

/* --- Sidebar --- */
.app-sidebar {
  width: 260px;
  background-color: var(--card-bg);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.sidebar-menu-item:hover {
  background-color: var(--primary-light);
  color: var(--primary-dark);
}

.sidebar-menu-item.active {
  background-color: var(--primary-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

.sidebar-menu-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  transition: stroke 0.3s ease;
}

/* --- Content Area --- */
.app-content {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.4s ease;
}

.tab-pane.active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--accent-1);
  padding-bottom: 12px;
}

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

.section-title svg {
  width: 28px;
  height: 28px;
  stroke: var(--primary-color);
}

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

.stat-card {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 15px;
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-4);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon.primary { background-color: var(--primary-light); color: var(--primary-color); }
.stat-icon.success { background-color: #E8F8F5; color: var(--success); }
.stat-icon.info { background-color: #EBF5FB; color: var(--info); }
.stat-icon.warning { background-color: #FEF9E7; color: var(--warning); }
.stat-icon.danger { background-color: #FDEDEC; color: var(--danger); }

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

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.grid-charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 25px;
  margin-bottom: 30px;
}

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

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

.chart-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* --- Tables --- */
.table-card {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
  margin-bottom: 30px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.custom-table th {
  background-color: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
  padding: 14px 18px;
  font-size: 0.9rem;
  border-bottom: 2px solid var(--accent-3);
  white-space: nowrap;
}

.custom-table td {
  padding: 14px 18px;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  white-space: nowrap;
}

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

.custom-table tbody tr:hover {
  background-color: rgba(46, 90, 54, 0.02);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.badge-success { background-color: #D4EFDF; color: var(--success); }
.badge-info { background-color: #D6EAF8; color: var(--info); }
.badge-warning { background-color: #FCF3CF; color: #D68910; }
.badge-danger { background-color: #FADBD8; color: var(--danger); }

/* --- Modals / Dialogs --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(3px);
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--accent-4);
  animation: scaleUp 0.3s ease;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--primary-light);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* --- Calendar (ยุทธการ) --- */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 15px;
}

.calendar-day-header {
  text-align: center;
  font-weight: 600;
  padding: 10px;
  background-color: var(--accent-1);
  color: var(--primary-dark);
  border-radius: 4px;
  font-size: 0.9rem;
}

.calendar-day {
  min-height: 100px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 5px;
  background-color: var(--card-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.2s ease;
}

.calendar-day:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--accent-4);
}

.calendar-day.empty {
  background-color: #F8F9FA;
  border-color: transparent;
}

.calendar-day.today {
  border: 2px solid var(--primary-color);
  background-color: var(--primary-light);
}

.calendar-date-num {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 5px;
}

.calendar-event {
  background-color: var(--accent-2);
  color: var(--primary-dark);
  font-size: 0.75rem;
  padding: 4px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
  border-left: 3px solid var(--primary-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.calendar-event:hover {
  background-color: var(--accent-4);
  transform: scale(1.02);
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.calendar-month-year {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-dark);
}

/* --- Fuel Gauges (ส่งกำลังบำรุง) --- */
.fuel-gauge-container {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 30px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

.fuel-gauge-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.gauge-svg {
  width: 200px;
  height: 120px;
}

.gauge-needle {
  transform-origin: 100px 100px;
  transition: transform 1s ease-out;
}

.fuel-value-display {
  margin-top: 15px;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.fuel-label-display {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

/* --- Utility Classes --- */
.text-center { text-align: center; }
.mt-4 { margin-top: 20px; }
.mb-4 { margin-bottom: 20px; }
.d-flex { display: flex; }
.gap-2 { gap: 10px; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.flex-1 { flex: 1; }

.btn-icon {
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background-color: var(--primary-light);
  border-color: var(--accent-4);
  color: var(--primary-color);
}

/* Sub-forms */
.sub-form-section {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  background-color: #FAFDFB;
}

.sub-form-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 12px;
  border-bottom: 1px dashed var(--accent-3);
  padding-bottom: 5px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
}

/* Responsive fixes */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }
  .app-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 10px;
    flex-direction: row;
    overflow-x: auto;
  }
  .sidebar-menu-item {
    padding: 8px 12px;
    font-size: 0.85rem;
    white-space: nowrap;
  }
  .sidebar-menu-item span {
    display: none;
  }
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* User Permission Info banner */
.permission-info-banner {
  background-color: var(--primary-light);
  border: 1px solid var(--accent-4);
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary-dark);
}

.permission-info-banner svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
