/* ======================================
   PHIR — Global Styles
   ====================================== */
:root {
  --phir-primary:   #1a5276;
  --phir-accent:    #2e86c1;
  --phir-light:     #eaf4fb;
  --phir-success:   #1e8449;
  --phir-danger:    #c0392b;
  --phir-warning:   #d4ac0d;
  --phir-muted:     #6c757d;
  --phir-border:    #d6e4f0;
  --phir-bg:        #f0f4f8;
  --phir-card-bg:   #ffffff;
  --phir-radius:    .75rem;
  --phir-shadow:    0 2px 12px rgba(26,82,118,.08);
  --phir-shadow-lg: 0 4px 24px rgba(26,82,118,.14);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', 'Noto Sans Thai', 'Helvetica Neue', sans-serif;
  background: var(--phir-bg);
  color: #1a2a3a;
  font-size: 15px;
  line-height: 1.6;
}

/* ======================================
   NAVBAR
   ====================================== */
.phir-navbar {
  background: linear-gradient(90deg, var(--phir-primary) 0%, #1f618d 100%) !important;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  padding: .5rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1030;
}
.phir-navbar .navbar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .04em;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.phir-navbar .navbar-brand .brand-icon {
  font-size: 1.5rem;
  color: #f4d03f;
}
.phir-navbar .nav-link {
  color: rgba(255,255,255,.85) !important;
  font-weight: 500;
  padding: .4rem .8rem !important;
  border-radius: .5rem;
  transition: background .15s, color .15s;
}
.phir-navbar .nav-link:hover,
.phir-navbar .nav-link.active {
  background: rgba(255,255,255,.15);
  color: #fff !important;
}
.phir-navbar .dropdown-menu {
  border: none;
  border-radius: var(--phir-radius);
  box-shadow: var(--phir-shadow-lg);
  min-width: 200px;
  padding: .4rem;
}
.phir-navbar .dropdown-item {
  border-radius: .4rem;
  padding: .5rem .9rem;
  font-weight: 500;
  transition: background .1s;
}
.phir-navbar .dropdown-item:hover { background: var(--phir-light); color: var(--phir-primary); }
.phir-navbar .user-badge {
  font-size: .7rem;
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 20px;
  padding: .15rem .55rem;
  vertical-align: middle;
}

/* ======================================
   LAYOUT
   ====================================== */
.phir-main {
  padding: 1.5rem 1.25rem;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 576px) {
  .phir-main { padding: 1rem .75rem; }
}

/* ======================================
   CARDS
   ====================================== */
.card {
  border: 1px solid var(--phir-border);
  border-radius: var(--phir-radius);
  box-shadow: var(--phir-shadow);
  background: var(--phir-card-bg);
}
.card-header {
  border-radius: calc(var(--phir-radius) - 1px) calc(var(--phir-radius) - 1px) 0 0 !important;
  font-weight: 600;
  font-size: .95rem;
  padding: .8rem 1.1rem;
  border-bottom: 1px solid var(--phir-border);
}
.card-header.bg-primary { background: linear-gradient(90deg,#1a5276,#2471a3) !important; }
.card-header.bg-info    { background: linear-gradient(90deg,#117a8b,#138496) !important; }
.card-header.bg-secondary{ background: linear-gradient(90deg,#495057,#6c757d) !important; }

/* ======================================
   STAT CARDS (Dashboard)
   ====================================== */
.stat-card {
  border-radius: var(--phir-radius);
  border: none;
  overflow: hidden;
  transition: transform .18s, box-shadow .18s;
  cursor: default;
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--phir-shadow-lg);
}
.stat-card .stat-body {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-card .stat-icon {
  font-size: 2.4rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: .65rem;
  flex-shrink: 0;
}
.stat-card .stat-num  { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label{ font-size: .8rem; color: var(--phir-muted); margin-top: .2rem; font-weight: 500; }
.stat-card.s-blue   { background: linear-gradient(135deg,#d6eaf8,#eaf4fb); }
.stat-card.s-orange { background: linear-gradient(135deg,#fdebd0,#fef9e7); }
.stat-card.s-green  { background: linear-gradient(135deg,#d5f5e3,#eafaf1); }
.stat-card.s-purple { background: linear-gradient(135deg,#e8daef,#f4ecf7); }
.stat-card.s-blue   .stat-icon { background:#d0e8f5; color:#1a5276; }
.stat-card.s-orange .stat-icon { background:#fde8c8; color:#d35400; }
.stat-card.s-green  .stat-icon { background:#c8ebd6; color:#1e8449; }
.stat-card.s-purple .stat-icon { background:#dcc8e8; color:#6c3483; }
.stat-card.s-blue   .stat-num  { color:#1a5276; }
.stat-card.s-orange .stat-num  { color:#d35400; }
.stat-card.s-green  .stat-num  { color:#1e8449; }
.stat-card.s-purple .stat-num  { color:#6c3483; }

/* ======================================
   TABLES
   ====================================== */
.table th {
  background: var(--phir-light);
  font-weight: 600;
  font-size: .83rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--phir-primary);
  border-bottom: 2px solid var(--phir-border) !important;
  white-space: nowrap;
}
.table td { vertical-align: middle; font-size: .9rem; }
.table-hover tbody tr:hover { background: #f5faff; }

/* Responsive table wrapper */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 600px; }

/* Readings table */
.readings-table th, .readings-table td { padding: .35rem .5rem; }
.readings-table input { font-size: .88rem !important; }
.readings-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.readings-wrap table { min-width: 560px; }

/* ======================================
   FORMS
   ====================================== */
.form-label { font-weight: 600; font-size: .88rem; color: #2c3e50; margin-bottom: .35rem; }
.form-control, .form-select {
  border-color: #c8d9ec;
  border-radius: .5rem;
  font-size: .92rem;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--phir-accent);
  box-shadow: 0 0 0 3px rgba(46,134,193,.15);
}
.input-group-text {
  background: var(--phir-light);
  border-color: #c8d9ec;
  color: var(--phir-primary);
  font-weight: 600;
}
.form-section-title {
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--phir-accent);
  margin-bottom: .5rem;
  padding-bottom: .25rem;
  border-bottom: 2px solid var(--phir-light);
}

/* Inline label-value rows (view form) */
.info-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.info-table th {
  background: #f4f9fe;
  font-size: .85rem;
  font-weight: 600;
  color: #2c3e50;
  padding: .55rem .9rem;
  width: 38%;
  border: 1px solid var(--phir-border);
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}
.info-table td {
  padding: .55rem .9rem;
  border: 1px solid var(--phir-border);
  font-size: .92rem;
}

/* ======================================
   BUTTONS
   ====================================== */
.btn { border-radius: .55rem; font-weight: 600; font-size: .9rem; transition: all .15s; }
.btn-phir {
  background: linear-gradient(135deg, var(--phir-primary), var(--phir-accent));
  color: #fff;
  border: none;
}
.btn-phir:hover { background: linear-gradient(135deg,#154360,var(--phir-primary)); color:#fff; transform:translateY(-1px); }
.btn-sm { font-size: .82rem; padding: .3rem .65rem; }
.btn-icon { width: 34px; height: 34px; padding: 0; display:inline-flex; align-items:center; justify-content:center; }

/* ======================================
   BADGES & STATUS
   ====================================== */
.badge { font-weight: 600; font-size: .75rem; border-radius: 20px; padding: .3em .7em; }
.status-pill { display:inline-flex; align-items:center; gap:.4rem; }
.status-dot  { width:8px; height:8px; border-radius:50%; flex-shrink:0; }

/* ======================================
   PAGE TITLE
   ====================================== */
.page-title { color: var(--phir-primary); font-weight: 800; font-size: 1.2rem; letter-spacing: -.01em; }
.page-sub   { color: var(--phir-muted); font-size: .84rem; }

/* ======================================
   LOGIN PAGE
   ====================================== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d3b5e 0%, var(--phir-primary) 40%, var(--phir-accent) 100%);
  padding: 1rem;
}
.login-card { width: 100%; max-width: 420px; }
.login-card .card { border: none; border-radius: 1.25rem; overflow: hidden; }
.login-logo-wrap {
  background: linear-gradient(135deg, var(--phir-primary), var(--phir-accent));
  padding: 2rem;
  text-align: center;
  color: #fff;
}
.login-logo-wrap .login-icon { font-size: 3.5rem; display:block; }
.login-logo-wrap h4 { font-weight: 800; font-size: 1.6rem; margin:.4rem 0 .1rem; }
.login-logo-wrap p  { opacity: .8; font-size: .82rem; margin: 0; }
.login-form-area { padding: 2rem; }

/* ======================================
   TEMP COLORS
   ====================================== */
.temp-ok   { background: #d5f5e3 !important; }
.temp-warn { background: #fef9e7 !important; }
.temp-low  { background: #fde8e8 !important; }

/* ======================================
   FLASH ALERTS
   ====================================== */
.alert { border-radius: var(--phir-radius); border: none; font-weight: 500; }
.alert-success { background:#d5f5e3; color:#145a32; }
.alert-danger  { background:#fde8e8; color:#78281f; }
.alert-warning { background:#fef9e7; color:#7d6608; }
.alert-info    { background:#d6eaf8; color:#1a5276; }

/* ======================================
   INSPECTION VIEW SPECIFIC
   ====================================== */
.form-header-title {
  background: linear-gradient(90deg, var(--phir-primary), var(--phir-accent));
  color: #fff;
  border-radius: var(--phir-radius) var(--phir-radius) 0 0;
  padding: 1rem 1.5rem;
  text-align: center;
}
.checkbox-display {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin-right: 1.5rem;
  font-size: .9rem;
}
.chk-box {
  width: 16px; height: 16px;
  border: 2px solid #555;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 11px; font-weight: 700;
  background: #fff;
}
.chk-box.checked { background: #1a5276; color: #fff; border-color: #1a5276; }

/* ======================================
   EMPTY STATE
   ====================================== */
.empty-state { padding: 3rem 1rem; text-align: center; color: var(--phir-muted); }
.empty-state i { font-size: 3rem; display:block; margin-bottom:.75rem; opacity:.4; }

/* ======================================
   FOOTER
   ====================================== */
.phir-footer {
  text-align: center;
  padding: 1.25rem;
  color: var(--phir-muted);
  font-size: .8rem;
  border-top: 1px solid var(--phir-border);
  margin-top: 2rem;
}

/* ======================================
   MOBILE OVERRIDES
   ====================================== */
@media (max-width: 768px) {
  .page-title { font-size: 1rem; }
  .hide-mobile { display: none !important; }
  .card-header { font-size: .88rem; padding: .65rem .9rem; }
  .btn { font-size: .85rem; }

  /* Stack page title + action button on mobile */
  .page-header { flex-direction: column; align-items: flex-start !important; gap: .6rem; }
  .page-header .btn-phir { width: 100%; justify-content: center; }

  /* Reading table inputs smaller */
  .readings-table input { padding: .2rem .3rem !important; font-size: .82rem !important; }

  /* Signature boxes: stack on mobile */
  .sig-row { flex-direction: column; }
  .sig-row > div { width: 100%; }

  /* Stat cards: 2 column on mobile */
  .stat-card .stat-num { font-size: 1.6rem; }
  .stat-card .stat-icon { width: 44px; height: 44px; font-size: 1.8rem; }
}

@media (max-width: 400px) {
  .phir-main { padding: .75rem .5rem; }
  .stat-card .stat-body { padding: 1rem; gap: .65rem; }
}

/* ======================================
   PRINT
   ====================================== */
@media print {
  .no-print, .phir-navbar, .phir-footer, .alert { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .phir-main { padding: 0; max-width: none; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .card-header { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .temp-ok, .temp-warn { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .info-table th, .info-table td { padding: .3rem .5rem; font-size: 10pt; }
  .readings-wrap { overflow: visible; }
  .readings-wrap table { min-width: unset; }
  table { page-break-inside: avoid; }
  .sig-row { display: flex !important; flex-direction: row !important; }
  .sig-box { break-inside: avoid; }
}
