/* ============================================================
   PHP OptiControl — Mobile-First Design System
   Dành cho Capacitor / Native App feel
   ============================================================
   Mục tiêu:
     - Touch targets >= 44px
     - Safe area (notch + home indicator)
     - Hiệu ứng :active (scale 0.98)
     - Chặn text selection, double-tap zoom, pull-to-refresh
     - Animations 0.2s-0.3s ease-in-out
     - Card List thay thế Table
     - Full-width inputs, font-size >= 16px
   ============================================================ */

/* ════════════════════════════════════════════════════════════
   1. CSS VARIABLES (Design Tokens)
   ════════════════════════════════════════════════════════════ */
:root {
  /* ---- Colors (Primary palette) ---- */
  --primary: #4a69bd;
  --primary-dark: #3c56a3;
  --primary-light: #e8edf7;
  --secondary: #f4f7fa;
  --accent: #0891b2;

  /* ---- Surfaces ---- */
  --surface: #ffffff;
  --background: #f5f7fa;
  --background-alt: #eef1f5;

  /* ---- Text ---- */
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-hint: #9ca3af;
  --text-inverse: #ffffff;

  /* ---- Borders & Shadows ---- */
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  /* ---- Semantic ---- */
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --info: #3b82f6;
  --info-bg: #dbeafe;

  /* ---- Safe Areas (Capacitor) ---- */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* ---- Layout Sizing ---- */
  --app-bar-height: 56px;
  --bottom-nav-height: 64px;
  --page-padding-x: 16px;
  --page-padding-y: 12px;

  /* ---- Touch / Typography ---- */
  --touch-min: 44px;
  --font-base: 16px;
  --font-sm: 13px;
  --font-xs: 11px;
  --font-heading: 18px;
  --line-height: 1.5;

  /* ---- Radius ---- */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* ---- Animation ---- */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 0.2s;
  --duration-normal: 0.3s;

  /* ---- Legacy variables (backward compat) ---- */
  --primary-color: var(--primary);
  --primary-color-dark: var(--primary-dark);
  --secondary-color: var(--secondary);
  --text-color: var(--text-primary);
  --text-color-light: var(--text-secondary);
  --border-color: var(--border);
  --background-color: var(--surface);
  --shadow-color: rgba(0, 0, 0, 0.08);
  --danger-color: var(--error);
  --danger-color-dark: #dc2626;
}

/* ════════════════════════════════════════════════════════════
   2. RESET & GLOBAL
   ════════════════════════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
}

html,
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  font-size: var(--font-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* ⭐ Chặn bôi đen văn bản không cần thiết
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  */

  /* ⭐ Chặn pull-to-refresh */
  overscroll-behavior: none;
  -webkit-overscroll-behavior: none;
}

/* Cho phép copy trên input/textarea */
input,
textarea,
[contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
}

/* ⭐ Tắt double-tap zoom */
a,
button,
input,
select,
textarea,
[role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Loại bỏ outline mặc định, dùng focus-visible */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

img,
svg,
video {
  max-width: 100%;
  display: block;
  height: auto;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
}

/* ════════════════════════════════════════════════════════════
   3. APP SHELL — TOP APP BAR + BOTTOM NAV
   ════════════════════════════════════════════════════════════ */

/* ---- App Shell Container ---- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height (mobile Safari) */
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  background: var(--background);
}

/* ---- Top App Bar (Fixed) ---- */
.app-bar {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  height: var(--app-bar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.app-bar__left,
.app-bar__right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.app-bar__btn {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.app-bar__btn:active {
  transform: scale(0.92);
  background: var(--primary-light);
}
.app-bar__btn svg {
  width: 24px;
  height: 24px;
}

.app-bar__back-btn {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.app-bar__back-btn:active {
  transform: scale(0.92);
  background: var(--primary-light);
}
.app-bar__back-btn svg {
  width: 24px;
  height: 24px;
}

.app-bar__title {
  font-size: var(--font-heading);
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.app-bar__logout-btn {
  color: var(--text-hint);
  transition: color var(--duration-fast) var(--ease-out);
}
.app-bar__logout-btn:active {
  color: var(--error);
  background: var(--error-bg);
}

/* ---- Notification Badge (dot) ---- */
.badge-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
  border: 2px solid var(--surface);
  display: none;
}
.badge-dot.active {
  display: block;
}

/* ---- Notification Panel (Overlay) ---- */
.panel-overlay {
  position: fixed;
  top: calc(var(--safe-top) + var(--app-bar-height));
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
  display: none;
  animation: fadeIn var(--duration-fast) var(--ease-out);
}
.panel-overlay.active {
  display: block;
}

.panel-sheet {
  background: var(--surface);
  max-height: 60vh;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideDown var(--duration-normal) var(--ease-out);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 600;
}

.panel-header button {
  background: none;
  border: none;
  color: var(--primary);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  min-height: var(--touch-min);
  border-radius: var(--radius-xs);
  transition: background var(--duration-fast) var(--ease-out);
}
.panel-header button:active {
  background: var(--primary-light);
}

.panel-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.notification-item {
  display: flex;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
  text-decoration: none;
  color: var(--text-primary);
}
.notification-item:active {
  background: var(--primary-light);
  transform: scale(0.99);
}
.notification-item:last-child {
  border-bottom: none;
}
.notification-item.unread {
  background: var(--info-bg);
}
.notification-item .message {
  font-size: 14px;
  margin-bottom: 4px;
  line-height: 1.4;
}
.notification-item .timestamp {
  font-size: var(--font-xs);
  color: var(--text-hint);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-hint);
  font-size: 14px;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 1000;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  padding-bottom: 0;
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-hint);
  font-size: var(--font-xs);
  font-weight: 500;
  min-height: var(--touch-min);
  transition: color var(--duration-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 4px 0;
}
.bottom-nav__item:active {
  transform: scale(0.95);
}
.bottom-nav__item.active {
  color: var(--primary);
}
.bottom-nav__item.active::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}
.bottom-nav__item svg {
  width: 24px;
  height: 24px;
}

/* ════════════════════════════════════════════════════════════
   4. MAIN CONTENT — Scrollable Area
   ════════════════════════════════════════════════════════════ */
.main-content {
  flex: 1;
  padding: calc(var(--app-bar-height) + var(--page-padding-y)) var(--page-padding-x)
    calc(var(--page-padding-y) + var(--bottom-nav-height));
  width: 100%;
  max-width: 100%;
}

/* ════════════════════════════════════════════════════════════
   5. DASHBOARD — Hub Cards (Legacy compat)
   ════════════════════════════════════════════════════════════ */

/* Wrapper (legacy) */
.dashboard-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Dashboard Grid (hub pages) */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0;
}

/* Dashboard Card */
.dashboard-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--text-primary);
  min-height: 72px;
  transition: all var(--duration-fast) var(--ease-out);
  border: 1px solid var(--border-light);
}
.dashboard-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
  background: var(--primary-light);
}

.card-icon {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary);
}
.card-icon svg {
  width: 24px;
  height: 24px;
}

/* ════════════════════════════════════════════════════════════
   6. PAGE HEADER
   ════════════════════════════════════════════════════════════ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0 16px;
  gap: 12px;
}
.page-header h1,
.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.page-header h1 {
  font-size: 22px;
}

.welcome-banner {
  padding: 16px 0;
}
.welcome-banner h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ════════════════════════════════════════════════════════════
   7. FORM COMPONENTS (Full-width, font >= 16px)
   ════════════════════════════════════════════════════════════ */

.form-container {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  border: 1px solid var(--border-light);
}

.form-container h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

/* Form Grid — mặc định 1 cột trên mobile */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* Input Group — Label trên, Input dưới, full-width */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

.input-group label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.input-group .required,
.required-mark {
  color: var(--error);
  margin-left: 2px;
}

.input-group input,
.input-group select,
.input-group textarea {
  width: 100%;
  min-height: var(--touch-min);
  padding: 10px 14px;
  font-size: var(--font-base); /* ⭐ >= 16px: iOS không zoom */
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input-group input::placeholder,
.input-group textarea::placeholder {
  color: var(--text-hint);
  font-size: 15px;
}

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

.input-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

/* Form Actions */
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.form-actions .btn {
  flex: 1;
  min-width: 120px;
}

/* Settings Grid (Dashboard project info) */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* Filter Grid (report page) */
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ════════════════════════════════════════════════════════════
   8. BUTTON SYSTEM (Touch-optimized)
   ════════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-min);
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.97);
}

/* Primary */
.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}
.btn-primary:active {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

/* Secondary */
.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:active {
  background: var(--background-alt);
  border-color: var(--text-hint);
}

/* Danger */
.btn-danger {
  background: var(--error);
  color: var(--text-inverse);
  border-color: var(--error);
}
.btn-danger:active {
  background: #dc2626;
  border-color: #dc2626;
}

/* Outline */
.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:active {
  background: var(--primary-light);
}

/* Success */
.btn-success {
  background: var(--success);
  color: var(--text-inverse);
  border-color: var(--success);
}
.btn-success:active {
  background: #059669;
}

/* Ghost (no border) */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:active {
  background: var(--background-alt);
}

/* Sizes */
.btn-sm {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 13px;
}
.btn-lg {
  min-height: 52px;
  padding: 14px 28px;
  font-size: 17px;
}

/* Full-width */
.btn-block {
  width: 100%;
}

/* Icon only */
.btn-icon {
  width: var(--touch-min);
  height: var(--touch-min);
  padding: 0;
  border-radius: 50%;
}

/* ════════════════════════════════════════════════════════════
   9. CARD LIST (Thay thế Table)
   ════════════════════════════════════════════════════════════ */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-list__item {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: all var(--duration-fast) var(--ease-out);
  border: 1px solid var(--border-light);
}
.card-list__item:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
}

.card-list__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 6px;
  gap: 8px;
}

.card-list__ref {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}

.card-list__body {
  padding: 2px 16px 10px;
}

.card-list__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  font-size: 14px;
  gap: 12px;
}

.card-list__label {
  color: var(--text-hint);
  font-size: 13px;
  flex-shrink: 0;
  min-width: 70px;
}

.card-list__value {
  color: var(--text-primary);
  text-align: right;
  font-weight: 500;
  word-break: break-word;
}

.card-list__actions {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--border-light);
  flex-wrap: wrap;
}

/* ════════════════════════════════════════════════════════════
   10. TABLE (Legacy support — scrollable)
   ════════════════════════════════════════════════════════════ */

.table-container {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-light);
  margin-bottom: 16px;
}

.table-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  gap: 8px;
}

.table-container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 600px; /* Force horizontal scroll on mobile */
}

.table-container th {
  background: var(--background-alt);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.table-container td {
  padding: 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.table-container tr:active {
  background: var(--primary-light);
}

/* ════════════════════════════════════════════════════════════
   11. BADGES / STATUS
   ════════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
  min-height: 24px;
}

.badge--pending,
.badge--open {
  background: var(--warning-bg);
  color: #92400e;
}

.badge--approved,
.badge--completed,
.badge--closed {
  background: var(--success-bg);
  color: #065f46;
}

.badge--rejected,
.badge--failed {
  background: var(--error-bg);
  color: #991b1b;
}

.badge--in-progress,
.badge--resolved {
  background: var(--info-bg);
  color: #1e40af;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ════════════════════════════════════════════════════════════
   12. MODAL / BOTTOM SHEET
   ════════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end; /* Bottom sheet trên mobile */
  justify-content: center;
  z-index: 2000;
  padding: var(--safe-top) var(--page-padding-x) var(--safe-bottom);
  animation: fadeIn var(--duration-fast) var(--ease-out);
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px calc(16px + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--duration-normal) var(--ease-out);
}

/* Handle indicator (drag bar) */
.modal-content::before {
  content: "";
  display: block;
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: -8px auto 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 18px;
  font-weight: 600;
}

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

.modal-body {
  padding: 16px 0;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}
.modal-actions .btn {
  flex: 1;
}

/* ════════════════════════════════════════════════════════════
   13. LIST (Project list, etc.)
   ════════════════════════════════════════════════════════════ */

.list-container {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  gap: 8px;
}
.list-header h2 {
  font-size: 18px;
  font-weight: 600;
}

/* ════════════════════════════════════════════════════════════
   14. A4 PAGE (Inspection Detail print layout)
   ════════════════════════════════════════════════════════════ */

.a4-page-wrapper {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border-light);
}

.document-header {
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.document-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ════════════════════════════════════════════════════════════
   15. DETAIL CARDS (Inspection detail, submittal details)
   ════════════════════════════════════════════════════════════ */

.details-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border-light);
}

/* ════════════════════════════════════════════════════════════
   16. PROFILE
   ════════════════════════════════════════════════════════════ */

.profile-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px 16px;
  border: 1px solid var(--border-light);
}

/* ════════════════════════════════════════════════════════════
   17. CONTENT GRID (Project page)
   ════════════════════════════════════════════════════════════ */

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* ════════════════════════════════════════════════════════════
   18. ANALYTICS / CHART CARDS
   ════════════════════════════════════════════════════════════ */

.analytics-section {
  margin-bottom: 16px;
}

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

.chart-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  border: 1px solid var(--border-light);
  transition: all var(--duration-fast) var(--ease-out);
}
.chart-card:active {
  transform: scale(0.98);
}

.chart-card h4 {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 8px;
}

.chart-container {
  position: relative;
  width: 100%;
  max-width: 160px;
  margin: 0 auto;
}

.chart-total {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.chart-total span {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.chart-total small {
  font-size: 10px;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---- Project info column + modules ---- */
.project-hub-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.project-info-column .form-container {
  margin-bottom: 0;
}

.project-modules-column .dashboard-grid {
  gap: 12px;
}

/* ---- Project Parties ---- */
.party-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  min-height: 48px;
}
.party-item:last-child {
  border-bottom: none;
}
.party-item:active {
  background: var(--primary-light);
  margin: 0 -16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

.party-logo {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--surface);
  border: 1px solid var(--border-light);
  padding: 4px;
}

.party-info {
  flex: 1;
}
.party-info .party-name {
  font-weight: 600;
  font-size: 14px;
}
.party-info .party-role {
  font-size: 13px;
  color: var(--text-hint);
}

/* ════════════════════════════════════════════════════════════
   19. INSPECTION DETAIL — Form Actions Container
   ════════════════════════════════════════════════════════════ */

.form-actions-container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.form-actions-container .btn {
  flex: 1;
  min-width: 100px;
}

/* ════════════════════════════════════════════════════════════
   20. QAQC — Layout Viewer / PDF
   ════════════════════════════════════════════════════════════ */

.layout-viewer {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
  margin-bottom: 16px;
}

#canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: var(--background-alt);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
#canvas-toolbar button {
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
#canvas-toolbar button:active {
  background: var(--primary-light);
  transform: scale(0.95);
}

#pdf-canvas-container {
  position: relative;
  width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
#pdf-canvas-container canvas {
  display: block;
  margin: 0 auto;
}

/* Report Info Card (quality-detail) */
.report-info-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border-light);
}

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

.report-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 14px;
}

/* Issue Sidebar (quality-detail) */
.issue-sidebar {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  overflow: hidden;
}

/* ════════════════════════════════════════════════════════════
   21. CHECKLIST ACCORDION (inspection-detail)
   ════════════════════════════════════════════════════════════ */

/* Photo Gallery */
.photo-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.photo-gallery img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

/* Response form */
.response-form {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 12px;
  border: 1px solid var(--border-light);
}

.response-section {
  padding: 12px 0;
}

/* ════════════════════════════════════════════════════════════
   22. ADMIN SECTION (Profile page)
   ════════════════════════════════════════════════════════════ */

.admin-links-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-light);
}

.admin-links-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.admin-link-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--primary);
  font-weight: 500;
  font-size: 15px;
  min-height: var(--touch-min);
  transition: all var(--duration-fast) var(--ease-out);
}
.admin-link-item:active {
  transform: scale(0.98);
  background: var(--primary);
  color: var(--text-inverse);
}
.admin-link-item svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════
   23. MISC / UTILITY
   ════════════════════════════════════════════════════════════ */

.note {
  font-size: 13px;
  color: var(--text-hint);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  gap: 8px;
}

.space-y-4 > * + * {
  margin-top: 16px;
}

.required-mark {
  color: var(--error);
}

/* Tab content */
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ════════════════════════════════════════════════════════════
   23. ANIMATIONS
   ════════════════════════════════════════════════════════════ */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

@keyframes slideDown {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ════════════════════════════════════════════════════════════
   24. MOBILE — Override inline grid styles (inspection, QAQC forms)
   ════════════════════════════════════════════════════════════ */

/* Collapse multi-column sub-grids to 1 column on mobile */
@media (max-width: 600px) {
  /* Target inline grids with 2, 3, or 4 columns inside form-grid */
  .form-grid [style*="grid-template-columns: 1fr 1fr"],
  .form-grid [style*="grid-template-columns: 1fr 1fr 1fr"],
  .form-grid [style*="grid-template-columns: 1fr 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Also target distribution sub-grids in formal-report-create */
  .form-grid .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* Quality report: the send-to/cc sub-grid */
  .form-grid [style*="grid-template-columns: 1fr 1fr; gap: 20px;"] {
    grid-template-columns: 1fr !important;
  }
}

/* ════════════════════════════════════════════════════════════
   25. RESPONSIVE — Tablet trở lên
   ════════════════════════════════════════════════════════════ */

@media (min-width: 768px) {
  .main-content {
    max-width: 768px;
    margin: 0 auto;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .analytics-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .project-hub-grid {
    grid-template-columns: 1fr 1fr;
  }

  .content-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filter-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal-content {
    border-radius: var(--radius-lg);
    max-height: 80vh;
    padding: 24px;
  }
  .modal-content::before {
    display: none;
  }
  .modal-overlay {
    align-items: center;
  }

  /* Trên tablet, hiển thị lại table dạng bình thường */
  .table-container table {
    min-width: auto;
  }
}

@media (min-width: 1024px) {
  .main-content {
    max-width: 960px;
  }

  .dashboard-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .form-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
