:root {
  --primary: #1e3a8a; /* Deep Navy Blue (Corporate/Professional) */
  --primary-hover: #1e40af;
  --primary-light: #eff6ff;
  --success: #059669; /* Deep Emerald Green */
  --success-hover: #047857;
  --success-light: #ecfdf5;
  --bg-app: #f8fafc; /* Professional light slate background */
  --text-main: #0f172a; /* Near Black (Slate 900) for highest readability */
  --text-muted: #475569; /* Slate 600 for subtext */
  --text-light: #64748b; /* Slate 500 for captions */
  --border-light: #e2e8f0; /* Slate 200 divider */
  --card-bg: #ffffff;
  --font-sans: 'Inter', 'Sarabun', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', 'Sarabun', system-ui, -apple-system, sans-serif;
  
  /* Fine-tuned Shadow System */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.04), 0 4px 6px -2px rgba(15, 23, 42, 0.02);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding: 3rem 2rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle corporate color bar at the top edge */
.bg-gradient-mesh {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  z-index: 100;
  background: linear-gradient(90deg, var(--primary) 0%, #3b82f6 50%, var(--success) 100%);
}

.hide {
  display: none !important;
}

/* Typography & Content Layout */
h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h2 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.5;
  margin-bottom: 2rem;
}

/* Button styles - Sharp, Clean, High Credibility */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: 5px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  letter-spacing: -0.01em;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-0.5px);
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background-color: var(--bg-app);
  color: var(--text-main);
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-success:hover {
  background-color: var(--success-hover);
  transform: translateY(-0.5px);
}

/* Corporate Cards */
.glass-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
}

/* Auth Layout (Login Screen) */
.auth-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 70vh;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 3rem 2.5rem;
  box-shadow: var(--shadow-lg);
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: #ffffff;
  border-radius: 8px;
  color: var(--primary);
  margin-bottom: 1.5rem;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.input-group {
  text-align: left;
  margin-bottom: 1.25rem;
}

.input-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.input-group input, .input-group textarea, .filter-group input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 5px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.15s ease;
}

.input-group textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

.input-group input:focus, .input-group textarea:focus, .filter-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.08);
}

.error-msg {
  color: #dc2626;
  font-size: 0.8rem;
  margin-bottom: 1rem;
  font-weight: 500;
}

/* Dashboard Layout */
.dashboard-wrapper {
  max-width: 1200px;
  margin: 0 auto;
}

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

.header-logo-section {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: #ffffff;
  border-radius: 6px;
  color: var(--primary);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.logo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-header p {
  color: var(--text-light);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.view-tabs {
  display: inline-flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  padding: 0.25rem;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.view-tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  padding: 0.5rem 0.85rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.view-tab:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.view-tab.active {
  color: #ffffff;
  background: var(--primary);
}

.setup-panel {
  margin-bottom: 1.5rem;
  padding: 1.5rem 1.75rem;
}

.setup-form {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.2fr) auto;
  gap: 1rem;
  align-items: end;
}

.setup-form .input-group {
  margin-bottom: 0;
}

.setup-table-section {
  margin-bottom: 1.5rem;
}

/* Control Panel (Filter Panel) */
.control-panel {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  padding: 1.25rem 1.75rem;
  background-color: var(--card-bg);
}

.filters {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.filter-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.filter-group input {
  width: 180px;
  padding: 0.55rem 0.75rem;
}

/* Stats Dashboard widgets */
.stats-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(520px, 1.35fr);
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-width: 0;
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow-sm);
}

.stat-box > div:last-child {
  min-width: 0;
}

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

.stat-icon.case-count {
  background: var(--primary-light);
  color: var(--primary);
}

.stat-icon.active-teams {
  background: var(--success-light);
  color: var(--success);
}

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-box h3 {
  font-size: 0.75rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Corporate Data Table - High legibility styling */
.table-section {
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-filter-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.clear-filter-btn {
  border: 1px solid var(--border-light);
  background: #ffffff;
  color: var(--text-main);
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.clear-filter-btn:hover {
  background: var(--primary-light);
  border-color: #bfdbfe;
  color: var(--primary);
}

.table-wrapper {
  overflow-x: auto;
}

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

th, td {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
}

th {
  background-color: #f8fafc;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.filterable-header {
  cursor: pointer;
  user-select: none;
}

.filterable-header::after {
  content: "⌕";
  margin-left: 0.45rem;
  color: #94a3b8;
  font-size: 0.78rem;
}

.filterable-header:hover,
.filterable-header.active-filter {
  color: var(--primary);
  background-color: var(--primary-light);
}

.filterable-header.active-filter::after {
  color: var(--primary);
}

td {
  font-size: 0.9rem;
  vertical-align: middle;
  line-height: 1.6;
}

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

tr:hover td {
  background-color: #fafafa;
}

.table-placeholder {
  text-align: center;
  color: var(--text-muted);
  padding: 5rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 400;
}

/* Badges and Technical details */
.code-badge {
  background-color: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: var(--text-main);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: Consolas, Monaco, 'Courier New', monospace;
  font-size: 0.825rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.team-badge {
  display: inline-block;
  background-color: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.775rem;
  font-weight: 600;
  border: 1px solid rgba(30, 58, 138, 0.08);
}

.alias-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.alias-list span {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-light);
  background: #ffffff;
  color: var(--text-muted);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.text-reason {
  color: var(--text-main);
  font-size: 0.875rem;
  white-space: pre-line;
  font-weight: 400;
  line-height: 1.6;
}

.action-cell {
  text-align: center;
  white-space: nowrap;
}

.editing-row td {
  vertical-align: top;
  background: #f8fafc;
}

.inline-edit-input,
.inline-edit-textarea {
  width: 100%;
  min-width: 120px;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: #ffffff;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  padding: 0.45rem 0.55rem;
  outline: none;
}

.inline-edit-textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.5;
}

.inline-edit-input:focus,
.inline-edit-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.08);
}

.edit-record-btn {
  border: 1px solid #bfdbfe;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  margin-right: 0.35rem;
}

.edit-record-btn:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.edit-record-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.delete-record-btn {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #be123c;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.save-record-btn,
.cancel-record-btn {
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.save-record-btn {
  border: 1px solid #bbf7d0;
  background: var(--success-light);
  color: var(--success);
  margin-right: 0.35rem;
}

.save-record-btn:hover {
  background: #dcfce7;
  border-color: #86efac;
}

.cancel-record-btn {
  border: 1px solid var(--border-light);
  background: #ffffff;
  color: var(--text-muted);
}

.cancel-record-btn:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

.save-record-btn:disabled,
.cancel-record-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.delete-record-btn:hover {
  background: #ffe4e6;
  border-color: #fda4af;
}

.delete-record-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

/* Custom Elegant Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Responsive Grid Adjustments */
@media (max-width: 960px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding: 2rem 1rem;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 1rem;
  }
  
  #logout-btn {
    align-self: flex-end;
  }
  
  .control-panel {
    flex-direction: column;
    align-items: stretch;
    padding: 1.25rem;
  }
  
  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  
  .filter-group input {
    width: 100%;
  }
  
  .actions button {
    width: 100%;
  }

  .view-tabs {
    display: flex;
    width: 100%;
  }

  .view-tab {
    flex: 1;
  }

  .setup-form {
    grid-template-columns: 1fr;
  }
  
  th, td {
    padding: 0.9rem 1rem;
  }
}
