/* styles.css */
/* ระบบดีไซน์ระดับ Premium & Official Corporate SaaS (Dark & Light Theme) */

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

:root {
  --font-display: 'Outfit', 'Sarabun', sans-serif;
  --font-body: 'Sarabun', sans-serif;

  /* สีพื้นฐานของระบบ (Theme-aware Text Colors) */
  --text-title: #ffffff;
  --text-primary: #e2e8f0; /* Slate 200 */
  --text-secondary: #94a3b8; /* Slate 400 */
  --text-muted: #64748b; /* Slate 500 */
  
  /* สีพื้นหลังระดับต่างๆ */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  
  /* สีสถานะและสีหลักขององค์กร (Corporate Tones) */
  --color-primary: #4f46e5; /* Royal Indigo */
  --color-primary-hover: #4338ca;
  --color-success: #10b981; /* Emerald Green */
  --color-success-hover: #059669;
  --color-warning: #f59e0b; /* Amber Gold */
  --color-info: #0ea5e9; /* Professional Sky Blue */
  --color-danger: #f43f5e; /* Rose Red */
  --color-purple: #8b5cf6; /* Violet */
  --color-slate: #64748b; /* Slate */

  /* เอฟเฟกต์ Glassmorphism และเงา */
  --glass-bg: rgba(17, 24, 39, 0.7);
  --glass-bg-hover: rgba(31, 41, 55, 0.8);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.15);
  --glass-border-focus: rgba(99, 102, 241, 0.4);
  --glass-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.3);
  --card-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.1);

  --border-radius-sm: 6px;
  --border-radius-md: 10px;
  --border-radius-lg: 14px;
  --border-radius-xl: 20px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --logo-height: 85px;
}

/* --- LIGHT THEME OVERRIDES --- */
body.light-theme {
  --text-title: #0f172a; /* Slate 900 */
  --text-primary: #334155; /* Slate 700 */
  --text-secondary: #64748b; /* Slate 500 */
  --text-muted: #94a3b8; /* Slate 400 */

  --bg-primary: #f8fafc; /* Slate 50 */
  --bg-secondary: #ffffff; /* pure white */
  --bg-tertiary: #f1f5f9; /* Slate 100 */

  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-bg-hover: rgba(248, 250, 252, 0.9);
  --glass-border: rgba(15, 23, 42, 0.08);
  --glass-border-hover: rgba(15, 23, 42, 0.15);
  --glass-border-focus: rgba(79, 70, 229, 0.4);
  --glass-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.04);
  --card-shadow: 0 4px 15px -5px rgba(15, 23, 42, 0.02);
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Ambient Background Glows */
.bg-glow-1 {
  position: fixed;
  top: -10vw;
  left: -10vw;
  width: 45vw;
  height: 45vw;
  background: radial-gradient(circle, rgba(79, 70, 229, 0.08) 0%, rgba(79, 70, 229, 0) 70%);
  pointer-events: none;
  z-index: -1;
  filter: blur(80px);
  animation: float-blob 20s infinite alternate ease-in-out;
}

.bg-glow-2 {
  position: fixed;
  bottom: -10vw;
  right: -10vw;
  width: 50vw;
  height: 50vw;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.05) 0%, rgba(16, 185, 129, 0) 70%);
  pointer-events: none;
  z-index: -1;
  filter: blur(100px);
  animation: float-blob 25s infinite alternate-reverse ease-in-out;
}

@keyframes float-blob {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(4vw, 3vw) scale(1.05); }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Typography Helpers */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-title);
  letter-spacing: -0.02em;
}

/* App Header */
.app-header {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur-radius, 16px));
  -webkit-backdrop-filter: blur(var(--glass-blur-radius, 16px));
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.85rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--glass-shadow);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo-img {
  height: var(--logo-height, 85px);
  width: auto;
  object-fit: contain;
  background: #ffffff;
  padding: 8px 20px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(79,70,229,0.10);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.brand-logo-img:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 30px rgba(0,0,0,0.25), 0 3px 12px rgba(79,70,229,0.18);
}

.brand-divider {
  width: 1px;
  height: 32px;
  background: var(--glass-border);
}

.brand-name-sub {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-title), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

/* Button & Controls */
.btn {
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--border-radius-md);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  outline: none;
  font-size: 0.88rem;
  user-select: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1.5px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
  background: var(--glass-bg-hover);
  border-color: var(--text-muted);
}

.btn-success {
  background: var(--color-success);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.btn-success:hover {
  background: var(--color-success-hover);
  transform: translateY(-1.5px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.3);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.1);
  color: var(--color-danger);
  border: 1px solid rgba(244, 63, 94, 0.2);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(244, 63, 94, 0.25);
  transform: translateY(-1.5px);
}

.btn-icon-only {
  padding: 0.5rem;
  border-radius: 50%;
  aspect-ratio: 1;
}

/* Switch View Selectors */
.view-selector-container {
  display: flex;
  background: rgba(0, 0, 0, 0.12);
  padding: 3px;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--glass-border);
}

body.light-theme .view-selector-container {
  background: rgba(15, 23, 42, 0.04);
}

.view-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.45rem 1rem;
  border-radius: var(--border-radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.view-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.view-btn:hover {
  color: var(--text-primary);
}

.view-btn.active {
  background: var(--color-primary);
  color: #ffffff !important;
  box-shadow: var(--card-shadow);
}

.branch-select-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

select.select-custom {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  padding: 0.5rem 2.2rem 0.5rem 0.85rem;
  border-radius: var(--border-radius-md);
  outline: none;
  font-family: var(--font-body);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 0.95rem;
  cursor: pointer;
  font-size: 0.88rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

body.light-theme select.select-custom {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23475569'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
}

select.select-custom:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--glass-border-focus);
}

/* Main Layout Wrapper */
.app-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem 2rem;
  animation: fadeIn var(--transition-normal);
}

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

/* Info Bar */
.info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 0.75rem 1.25rem;
  border-radius: var(--border-radius-md);
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  box-shadow: var(--glass-shadow);
}

.info-bar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.info-bar-item span {
  font-weight: 600;
  color: var(--text-title);
}

/* --- MANAGER DASHBOARD --- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  padding: 1.25rem;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--glass-border-hover);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--color-primary);
}

.stat-card.success::before { background: var(--color-success); }
.stat-card.warning::before { background: var(--color-warning); }
.stat-card.info::before { background: var(--color-info); }
.stat-card.purple::before { background: var(--color-purple); }
.stat-card.slate::before { background: var(--color-slate); }

.stat-title {
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-title svg {
  width: 16px;
  height: 16px;
  fill: var(--text-muted);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-title);
  line-height: 1.25;
}

.stat-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* Charts Section */
.charts-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

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

.chart-container {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.5rem;
}

.chart-title {
  font-size: 0.98rem;
  color: var(--text-title);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chart-title svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Mini Bar Chart */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  flex-grow: 1;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 0.4rem;
}

.chart-bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 75px;
  align-items: center;
  gap: 0.85rem;
}

.bar-label {
  font-size: 0.82rem;
  color: var(--text-primary);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.bar-wrapper {
  background: rgba(148, 163, 184, 0.1);
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(to right, var(--color-primary), var(--color-info));
  width: 0%;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.bar-value {
  font-family: var(--font-display);
  font-size: 0.82rem;
  text-align: right;
  color: var(--text-title);
  font-weight: 600;
}

/* Ring Chart */
.status-chart-body {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 1.5rem;
  flex-grow: 1;
}

@media (max-width: 576px) {
  .status-chart-body {
    flex-direction: column;
    gap: 1.25rem;
  }
}

.ring-visual {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-svg {
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(148, 163, 184, 0.1);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--color-success);
  stroke-dasharray: 377;
  stroke-dashoffset: 377;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease-in-out;
  filter: drop-shadow(0 2px 4px rgba(16, 185, 129, 0.15));
}

.ring-text-container {
  position: absolute;
  text-align: center;
}

.ring-percent {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-title);
}

.ring-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

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

.legend-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-value {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--text-title);
  font-weight: 600;
}

/* Table Section */
.table-section {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--glass-shadow);
}

.controls-row-filters {
  margin-bottom: 1.25rem;
}

.input-search-wrapper {
  position: relative;
  flex-grow: 1;
  max-width: 380px;
  min-width: 240px;
}

.input-search-wrapper input {
  width: 100%;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  padding: 0.5rem 1rem 0.5rem 2.2rem;
  border-radius: var(--border-radius-md);
  outline: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-search-wrapper input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--glass-border-focus);
}

.input-search-wrapper svg {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  fill: var(--text-muted);
}

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

.table-custom th {
  background: rgba(0, 0, 0, 0.15);
  padding: 0.85rem 1rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--glass-border);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}

body.light-theme .table-custom th {
  background: rgba(15, 23, 42, 0.03);
}

.table-custom th.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 1.5rem;
}

.table-custom th.sortable:hover {
  color: var(--text-primary);
}

.table-custom th.sortable::after {
  content: '↕';
  position: absolute;
  right: 0.6rem;
  opacity: 0.4;
  font-size: 0.75rem;
}

.table-custom th.sort-asc::after {
  content: '↑';
  opacity: 1;
  color: var(--color-primary);
}

.table-custom th.sort-desc::after {
  content: '↓';
  opacity: 1;
  color: var(--color-primary);
}

.table-custom td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--glass-border);
  color: var(--text-primary);
  font-size: 0.88rem;
}

.table-custom tr:hover td {
  background: rgba(255, 255, 255, 0.012);
}

body.light-theme .table-custom tr:hover td {
  background: rgba(15, 23, 42, 0.008);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge svg {
  width: 11px;
  height: 11px;
  margin-right: 0.25rem;
  fill: currentColor;
}

.badge-pending {
  background: rgba(245, 158, 11, 0.12);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.22);
}

.badge-done {
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.22);
}

.badge-status {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

.badge-status.quotation {
  background: rgba(14, 165, 233, 0.12);
  color: var(--color-info);
  border: 1px solid rgba(14, 165, 233, 0.22);
}

.badge-status.approval {
  background: rgba(245, 158, 11, 0.12);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.22);
}

.badge-status.billing {
  background: rgba(139, 92, 246, 0.12);
  color: var(--color-purple);
  border: 1px solid rgba(139, 92, 246, 0.22);
}

.badge-status.delivered {
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.22);
}

.badge-status.special {
  background: rgba(100, 116, 139, 0.1);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

/* --- KANBAN BOARD VIEW --- */
.kanban-view-header {
  margin-bottom: 1.25rem;
}

.kanban-title-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.kanban-board-container {
  display: grid;
  grid-template-columns: repeat(5, minmax(260px, 1fr));
  gap: 0.85rem;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 1rem;
}

.kanban-column {
  background: rgba(17, 24, 39, 0.3);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  min-height: 68vh;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

body.light-theme .kanban-column {
  background: rgba(15, 23, 42, 0.02);
}

.kanban-column.drag-over {
  background: rgba(79, 70, 229, 0.04);
  border-color: var(--color-primary);
}

.column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
}

.column-title-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.column-color-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.column-title {
  font-size: 0.88rem;
  color: var(--text-title);
  font-weight: 600;
}

.column-count {
  background: var(--bg-tertiary);
  font-family: var(--font-display);
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 10px;
  color: var(--text-secondary);
  font-weight: 600;
}

.column-cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex-grow: 1;
  min-height: 58vh;
}

/* Kanban Card */
.kanban-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-sm);
  padding: 0.85rem;
  box-shadow: var(--card-shadow);
  cursor: grab;
  user-select: none;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.kanban-card:hover {
  transform: translateY(-1.5px);
  border-color: var(--glass-border-hover);
  box-shadow: var(--glass-shadow);
}

.kanban-card:active {
  cursor: grabbing;
}

.kanban-card.dragging {
  opacity: 0.4;
  transform: scale(0.97);
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 0.4rem;
}

.card-title {
  font-size: 0.88rem;
  color: var(--text-title);
  font-weight: 600;
  line-height: 1.3;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.6rem;
}

.card-details {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.6rem;
  line-height: 1.4;
}

.card-info-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.card-info-item span:first-child {
  color: var(--text-secondary);
}

.card-info-item span.highlight {
  font-family: var(--font-display);
  color: var(--text-title);
  font-weight: 600;
}

.card-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--glass-border);
}

.card-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.card-date svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.card-actions-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  transition: all var(--transition-fast);
}

.card-actions-btn svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.card-actions-btn:hover {
  color: var(--color-primary);
  background: rgba(79, 70, 229, 0.08);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 8, 15, 0.6);
  backdrop-filter: blur(var(--glass-blur-radius, 8px));
  -webkit-backdrop-filter: blur(var(--glass-blur-radius, 8px));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  width: 92%;
  max-width: 760px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--transition-normal);
}

body.light-theme .modal-content {
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.15rem;
  color: var(--text-title);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.modal-title svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

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

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

.modal-body {
  padding: 1.5rem;
}

/* Forms styling */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.col-span-2 {
  grid-column: span 2;
}

@media (max-width: 768px) {
  .form-group.col-span-2 {
    grid-column: span 1;
  }
}

.form-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.form-control {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  padding: 0.55rem 0.75rem;
  border-radius: var(--border-radius-md);
  outline: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--glass-border-focus);
}

textarea.form-control {
  resize: vertical;
  min-height: 70px;
}

.form-divider {
  grid-column: span 2;
  border-bottom: 2px solid var(--color-primary);
  margin: 0.85rem 0 0.5rem 0;
  padding-bottom: 0.3rem;
  color: var(--text-title);
  font-weight: 700;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .form-divider {
    grid-column: span 1;
  }
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Empty placeholder */
.empty-placeholder {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

.empty-icon svg {
  width: 45px;
  height: 45px;
  fill: currentColor;
}

/* Attachments Gallery Styles */
.file-upload-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.file-status-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}

#details-attachments-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.4rem;
}

#details-attachments-container .badge {
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  padding: 0.4rem;
  border-radius: var(--border-radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.3rem;
  width: 85px;
  min-height: 90px;
  justify-content: space-between;
  overflow: hidden;
}

#details-attachments-container .badge img {
  border-radius: 4px;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.2);
}

#details-attachments-container .badge span {
  font-size: 0.68rem;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
}

.optgroup {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-primary);
}

/* --- SETTINGS & MANAGEMENT LAYOUT STYLES --- */
.settings-tab-btn {
  border-bottom: 2px solid transparent !important;
}

.settings-tab-btn:hover {
  color: var(--text-primary) !important;
}

.settings-tab-btn.active {
  color: var(--color-success) !important;
  border-bottom: 2px solid var(--color-success) !important;
}

.card-glass-panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--glass-shadow);
  margin-bottom: 1.25rem;
}

.db-action-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--glass-border);
}

.db-action-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.db-action-info h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
  color: var(--text-title);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.db-action-info h4 svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.db-action-info p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* Form controls read-only state */
.form-control:disabled,
select.form-control:disabled,
textarea.form-control:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  background-color: rgba(0, 0, 0, 0.12) !important;
  border-color: var(--glass-border) !important;
  color: var(--text-secondary) !important;
}

body.light-theme .form-control:disabled {
  background-color: rgba(0, 0, 0, 0.04) !important;
  color: var(--text-secondary) !important;
}

/* Toggle Switch Slider */
.slider-toggle::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 50%;
  transition: 0.4s;
}
input:checked + .slider-toggle {
  background-color: var(--color-primary) !important;
}
input:checked + .slider-toggle::before {
  transform: translateX(24px);
}

/* Hidden elements for layout builder */
.hidden-layout {
  display: none !important;
}

/* Small Toggle Switch */
.slider-toggle-small {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  border-radius: 20px;
  transition: 0.3s;
  display: block;
}
.slider-toggle-small::before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
}
input:checked + .slider-toggle-small {
  background-color: var(--color-primary) !important;
}
input:checked + .slider-toggle-small::before {
  transform: translateX(16px);
}

/* Password visibility toggle container and button */
.password-wrapper {
  position: relative;
  display: flex;
  width: 100%;
}

.password-wrapper .form-control {
  width: 100%;
  padding-right: 2.5rem;
}

.btn-toggle-password {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  transition: color var(--transition-fast);
}

.btn-toggle-password:hover {
  color: var(--text-primary);
}

.btn-toggle-password svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* --- MOBILE RESPONSIVE ENHANCEMENTS --- */
@media (max-width: 768px) {
  /* App Container Padding */
  .app-container {
    padding: 1rem 0.75rem 2.5rem 0.75rem;
  }

  /* Header Optimization */
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    padding: 0.75rem 1rem;
  }

  .brand {
    justify-content: space-between;
    width: 100%;
  }

  .brand-logo-img {
    height: 55px;
    padding: 4px 12px;
  }

  .brand-divider,
  .brand-name-sub {
    display: none !important;
  }

  .nav-controls {
    flex-wrap: wrap;
    justify-content: space-between;
    width: 100%;
    gap: 0.6rem;
  }

  /* View Selector Container Full Width */
  .view-selector-container {
    width: 100%;
    justify-content: space-around;
  }

  .view-btn {
    flex: 1;
    justify-content: center;
    padding: 0.5rem 0.25rem;
    font-size: 0.78rem;
  }

  /* Language & Theme & Auth Row Wrap */
  #select-lang {
    flex: 1;
    min-width: 80px;
    height: 38px;
    margin-right: 0;
  }

  #btn-theme-toggle {
    width: 38px !important;
    height: 38px !important;
    margin-right: 0 !important;
  }

  #btn-login-toggle,
  #btn-add-job {
    flex: 1.5;
    height: 38px;
    font-size: 0.82rem;
    padding: 0.5rem 0.75rem;
  }

  #branch-selector-wrapper {
    width: 100%;
  }

  #select-branch-nav {
    width: 100%;
    height: 38px;
  }

  /* Info Bar */
  .info-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    text-align: center;
    padding: 0.75rem;
  }

  .info-bar-left {
    justify-content: center;
    gap: 0.85rem;
  }

  /* Dashboard Stats Grid Override */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  /* Filter Dashboard Month row */
  #dashboard-filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.75rem;
  }

  #dashboard-filter-row span.form-label {
    justify-content: center;
  }

  #filter-dashboard-month {
    width: 100%;
  }

  /* Table Search & Filters Row */
  #search-input,
  #filter-branch,
  #filter-status,
  #filter-case-status {
    flex: 1 1 100% !important;
    width: 100% !important;
  }

  /* Table to Cards Conversion */
  .table-custom,
  .table-custom tbody,
  .table-custom tr,
  .table-custom td {
    display: block !important;
    width: 100% !important;
  }

  .table-custom thead {
    display: none !important;
  }

  .table-custom tr {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    padding: 1rem;
    margin-bottom: 0.85rem;
    box-shadow: var(--glass-shadow);
  }

  .table-custom td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0.65rem 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
    text-align: right !important;
    font-size: 0.85rem !important;
  }

  body.light-theme .table-custom td {
    border-bottom: 1px solid rgba(15, 23, 42, 0.05) !important;
  }

  .table-custom td:last-child {
    border-bottom: none !important;
    padding-bottom: 0 !important;
  }

  /* Labeled headings for cells on Mobile */
  .table-custom td::before {
    font-weight: 600;
    color: var(--text-secondary);
    text-align: left;
    margin-right: 0.5rem;
    font-size: 0.82rem;
  }

  .table-custom td[data-col="branch"]::before { content: "สาขา (Branch):"; }
  .table-custom td[data-col="customer"]::before { content: "ลูกค้า (Customer):"; }
  .table-custom td[data-col="details"]::before { content: "รายละเอียด (Details):"; }
  .table-custom td[data-col="model"]::before { content: "รุ่น/ซีเรียล (Model/SN):"; }
  .table-custom td[data-col="date"]::before { content: "วันที่แจ้ง (Date):"; }
  .table-custom td[data-col="proposed"]::before { content: "ยอดเสนอประกัน (Proposed):"; }
  .table-custom td[data-col="approved"]::before { content: "ยอดอนุมัติจริง (Approved):"; }
  .table-custom td[data-col="sales"]::before { content: "ราคาขายจริง (Sales):"; }
  .table-custom td[data-col="finance"]::before { content: "การเงินลูกค้า (Finance):"; }
  .table-custom td[data-col="substatus"]::before { content: "ขั้นตอนบอร์ด (Stage):"; }
  .table-custom td[data-col="status"]::before { content: "สถานะเคส (Status):"; }
  .table-custom td[data-col="actions"]::before { content: "จัดการ (Actions):"; }

  .table-custom td > * {
    text-align: right !important;
  }

  /* Kanban Mobile - Horizontal Snapping Columns */
  .kanban-board-container {
    scroll-snap-type: x mandatory;
    display: flex !important;
    overflow-x: auto !important;
    gap: 1rem !important;
    padding: 0 0.5rem 1rem 0.5rem !important;
    margin: 0 -0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-column {
    flex: 0 0 295px !important;
    scroll-snap-align: center !important;
    min-height: auto !important;
    max-height: 72vh !important;
  }

  /* Modals to Native-feel Bottom Sheet */
  .modal-overlay {
    align-items: flex-end !important;
  }

  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    height: 85vh !important;
    max-height: 85vh !important;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0 !important;
    margin: 0 !important;
    transform: translateY(100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  .modal-overlay.active .modal-content {
    transform: translateY(0) !important;
  }

  .modal-body {
    padding: 1.25rem 1rem !important;
  }

  .modal-footer {
    padding: 1rem !important;
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
    z-index: 10;
  }
}

/* User Online Pulse Glow Styles */
@keyframes pulse-glow {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.pulse-online {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
  animation: pulse-glow 2s infinite ease-in-out;
}

.pulse-offline {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

