/* GSSS Routine System - Material Design 3 Modern Palette & Styles */
:root {
  --md-sys-color-primary: #1a73e8;
  --md-sys-color-primary-container: #e8f0fe;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-on-primary-container: #0d47a1;
  --md-sys-color-secondary: #455a64;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-surface-variant: #f8f9fa;
  --md-sys-color-background: #f1f3f4;
  --md-sys-color-outline: #dadce0;
  
  --status-ok: #1e8e3e;
  --status-ok-bg: #e6f4ea;
  --status-nok: #d93025;
  --status-nok-bg: #fce8e6;
  --status-na: #5f6368;
  --status-na-bg: #f1f3f4;

  --font-family: 'Kanit', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
  --shadow-sm: 0 1px 3px rgba(60,64,67,0.12), 0 1px 2px rgba(60,64,67,0.24);
  --shadow-md: 0 4px 8px rgba(60,64,67,0.15), 0 1px 3px rgba(60,64,67,0.3);
  --shadow-lg: 0 8px 16px rgba(60,64,67,0.15), 0 2px 6px rgba(60,64,67,0.2);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--md-sys-color-background);
  color: #202124;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* App Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--md-sys-color-outline);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  height: 60px;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #1a73e8, #0d47a1);
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: var(--shadow-sm);
}

.brand-title h1 {
  font-size: 1.15rem;
  font-weight: 600;
  color: #1a73e8;
}

.brand-title span {
  font-size: 0.78rem;
  color: #5f6368;
}

.user-badge-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.role-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 50px;
  font-size: 0.825rem;
  font-weight: 500;
}

.role-badge.supervisor {
  background-color: #e8f0fe;
  color: #1a73e8;
  border: 1px solid #aecbfa;
}

.role-badge.admin {
  background-color: #e6f4ea;
  color: #137333;
  border: 1px solid #a8dab5;
}

/* Main Layout Grid */
.app-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 60px);
  overflow: hidden;
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: auto;
  }
}

/* Sidebar */
.app-sidebar {
  background-color: #ffffff;
  border-right: 1px solid var(--md-sys-color-outline);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
}

.sidebar-card {
  background: var(--md-sys-color-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.sidebar-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #5f6368;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.fy-selector-box {
  display: flex;
  gap: 8px;
}

.select-custom {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background-color: #ffffff;
  color: #202124;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.select-custom:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.2);
}

.btn-icon-add {
  background: var(--md-sys-color-primary);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon-add:hover {
  background: #1557b0;
}

/* Nav Tabs */
.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: #3c4043;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  font-size: 0.9rem;
}

.nav-item:hover {
  background-color: #f1f3f4;
  color: #1a73e8;
}

.nav-item.active {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 600;
  border-color: #aecbfa;
}

.nav-item .material-symbols-outlined {
  font-size: 18px;
}

/* Content Area */
.app-content {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.tab-pane {
  display: none;
}

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

/* Material Card */
.card {
  background: #ffffff;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f3f4;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #202124;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Quick Fill Banner */
.quick-fill-banner {
  background: linear-gradient(135deg, #e8f0fe, #e6f4ea);
  border: 1px solid #aecbfa;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.quick-fill-text h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1a73e8;
}

.quick-fill-text p {
  font-size: 0.8rem;
  color: #5f6368;
}

.btn-quick-ok {
  background: #1e8e3e;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.btn-quick-ok:hover {
  background: #137333;
}

/* Form Styles */
.form-grid-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 600px) {
  .form-grid-top {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 0.825rem;
  font-weight: 500;
  color: #3c4043;
}

.input-custom {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}

.input-custom:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.2);
}

/* Routine Items Section */
.routine-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.routine-item-card {
  background: #ffffff;
  border: 1px solid var(--md-sys-color-outline);
  border-left: 4px solid #1a73e8;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  transition: var(--transition);
}

.routine-item-card:hover {
  box-shadow: var(--shadow-sm);
}

.routine-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.routine-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #202124;
}

.status-button-group {
  display: flex;
  gap: 6px;
}

.btn-status {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--md-sys-color-outline);
  background: #ffffff;
  color: #5f6368;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}

.btn-status:hover {
  background: #f1f3f4;
}

.btn-status.selected-ok {
  background: var(--status-ok-bg);
  color: var(--status-ok);
  border-color: #a8dab5;
}

.btn-status.selected-nok {
  background: var(--status-nok-bg);
  color: var(--status-nok);
  border-color: #f5c2c0;
}

.btn-status.selected-na {
  background: var(--status-na-bg);
  color: var(--status-na);
  border-color: #dadce0;
}

.comment-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #e0e0e0;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.825rem;
  background: #fafafa;
  outline: none;
  transition: var(--transition);
}

.comment-input:focus {
  background: #ffffff;
  border-color: var(--md-sys-color-primary);
}

/* Action Buttons */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #f1f3f4;
}

.btn-primary {
  background: var(--md-sys-color-primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.btn-primary:hover {
  background: #1557b0;
}

.btn-secondary {
  background: #ffffff;
  color: #3c4043;
  border: 1px solid var(--md-sys-color-outline);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: #f8f9fa;
}

/* SPECIAL: Report View - Viewport Fit (No Scrollbar) */
#pane-report.active {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

#pane-report #pdfPrintArea {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 10px;
  overflow: hidden;
  min-height: 0;
}

.report-filter-bar {
  background: #f8f9fa;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: flex-end;
}

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

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  background: #ffffff;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.total { background: #e8f0fe; color: #1a73e8; }
.stat-icon.ok { background: #e6f4ea; color: #1e8e3e; }
.stat-icon.nok { background: #fce8e6; color: #d93025; }
.stat-icon.rate { background: #feefc3; color: #b06000; }

.stat-info .number {
  font-size: 1.25rem;
  font-weight: 700;
  color: #202124;
  line-height: 1.2;
}

.stat-info .label {
  font-size: 0.75rem;
  color: #5f6368;
}

/* Chart Container Grid */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

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

.chart-box {
  background: #ffffff;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chart-header {
  font-size: 0.9rem;
  font-weight: 600;
  color: #202124;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-canvas {
  width: 100%;
  flex: 1;
  min-height: 0;
}

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

.custom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.custom-table th {
  background: #f8f9fa;
  color: #3c4043;
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--md-sys-color-outline);
}

.custom-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #e0e0e0;
  color: #202124;
}

.custom-table tr:hover {
  background: #f8f9fa;
}

.badge-status {
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.75rem;
  display: inline-block;
}

.badge-status.ok { background: #e6f4ea; color: #137333; }
.badge-status.nok { background: #fce8e6; color: #c5221f; }
.badge-status.na { background: #f1f3f4; color: #5f6368; }

/* 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;
}

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

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 450px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

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

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

.btn-close {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #5f6368;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #323232;
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.3s ease-out forwards;
}

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

/* Print / PDF Styles */
@media print {
  body { overflow: visible !important; }
  .app-header, .app-sidebar, .btn-primary, .btn-secondary, .report-filter-bar {
    display: none !important;
  }
  .app-layout {
    display: block !important;
    height: auto !important;
  }
  .app-content {
    padding: 0 !important;
    height: auto !important;
  }
  .card, .chart-box {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }
}
