/* ==========================================================================
   Design System & Minimal Clean Theme
   Event Venue Expense & Income System (ระบบบันทึกรายรับรายจ่าย สถานที่จัดงานแต่งงาน)
   ========================================================================== */

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

:root {
  /* Color Palette - Minimal Clean & Modern Slate */
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-focus: #6366f1;
  
  /* Primary & Accent Tones */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  
  /* Financial Metrics Tones */
  --income-color: #059669;
  --income-bg: #ecfdf5;
  --income-border: #a7f3d0;
  
  --expense-color: #e11d48;
  --expense-bg: #fff1f2;
  --expense-border: #fecdd3;
  
  --profit-color: #0284c7;
  --profit-bg: #f0f9ff;
  --profit-border: #bae6fd;
  
  --warning-color: #d97706;
  --warning-bg: #fffbeb;
  
  /* UI Radii & Shadows */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  
  --font-family: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Theme */
[data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #1f2937;
  --bg-subtle: #111827;
  
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-light: #6b7280;
  
  --border-color: #374151;
  --border-focus: #818cf8;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  
  --income-color: #10b981;
  --income-bg: rgba(16, 185, 129, 0.12);
  --income-border: rgba(16, 185, 129, 0.3);
  
  --expense-color: #f43f5e;
  --expense-bg: rgba(244, 63, 94, 0.12);
  --expense-border: rgba(244, 63, 94, 0.3);
  
  --profit-color: #38bdf8;
  --profit-bg: rgba(56, 189, 248, 0.12);
  --profit-border: rgba(56, 189, 248, 0.3);
  
  --warning-color: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.12);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* App Header & Navbar */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.brand-logo-img {
  height: 48px;
  width: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  background-color: #ffffff;
  padding: 3px 6px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.brand-logo:hover .brand-logo-img {
  transform: scale(1.03);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-main);
  font-family: 'Prompt', 'Inter', sans-serif;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-subtle);
  padding: 0.25rem;
  border-radius: var(--radius-md);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.nav-btn:hover {
  color: var(--text-main);
}

.nav-btn.active {
  background-color: var(--bg-surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

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

/* Icon Buttons */
.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--text-light);
}

/* Main Container */
.main-wrapper {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem 1.5rem;
  width: 100%;
  flex: 1;
}

/* Page Views */
.view-section {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}

.view-section.active {
  display: block;
}

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

/* Typography & Headers */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
}

.page-title p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

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

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

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

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

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
  background-color: var(--bg-subtle);
}

.btn-danger {
  background-color: #ef4444;
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.825rem;
  border-radius: var(--radius-sm);
}

/* Metric Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.metric-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.metric-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.metric-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.metric-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.metric-icon.income {
  background-color: var(--income-bg);
  color: var(--income-color);
}

.metric-icon.expense {
  background-color: var(--expense-bg);
  color: var(--expense-color);
}

.metric-icon.profit {
  background-color: var(--profit-bg);
  color: var(--profit-color);
}

.metric-icon.events {
  background-color: var(--primary-light);
  color: var(--primary);
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.metric-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Profit Badge % Indicator */
.profit-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.60rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.profit-badge.high {
  background-color: var(--income-bg);
  color: var(--income-color);
  border: 1px solid var(--income-border);
}

.profit-badge.medium {
  background-color: var(--profit-bg);
  color: var(--profit-color);
  border: 1px solid var(--profit-border);
}

.profit-badge.low {
  background-color: var(--warning-bg);
  color: var(--warning-color);
  border: 1px solid rgba(217, 119, 6, 0.3);
}

.profit-badge.negative {
  background-color: var(--expense-bg);
  color: var(--expense-color);
  border: 1px solid var(--expense-border);
}

/* Charts Section */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

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

.chart-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.chart-title h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.chart-title p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chart-container {
  position: relative;
  width: 100%;
  min-height: 260px;
  height: auto;
}

/* Custom Bar Chart Engine */
.custom-bar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 100%;
  padding-top: 0.5rem;
}

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

.bar-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  flex-wrap: wrap;
}

.bar-track {
  height: 22px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
}

.bar-fill.income { background: linear-gradient(90deg, #059669, #10b981); }
.bar-fill.expense { background: linear-gradient(90deg, #e11d48, #f43f5e); }
.bar-fill.profit { background: linear-gradient(90deg, #0284c7, #38bdf8); }

/* Table & Filters Card */
.content-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 2rem;
}

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

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-input {
  position: relative;
  min-width: 240px;
}

.search-input input {
  width: 100%;
  padding: 0.55rem 0.85rem 0.55rem 2.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  outline: none;
}

.search-input input:focus {
  border-color: var(--border-focus);
}

.search-input i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.select-control {
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.select-control:focus {
  border-color: var(--border-focus);
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background-color: rgba(99, 102, 241, 0.02);
}

/* Status Badges */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 500;
}

.status-pill.upcoming {
  background-color: #eff6ff;
  color: #2563eb;
  border: 1px solid #bfdbfe;
}

.status-pill.active {
  background-color: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

.status-pill.completed {
  background-color: #f8fafc;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.status-pill.cancelled {
  background-color: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

/* Modal Dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

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

.modal-card {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  transform: translateY(12px) scale(0.98);
  transition: transform 0.2s ease;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-backdrop.active .modal-card {
  transform: translateY(0) scale(1);
}

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

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background-color: var(--bg-subtle);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* Form Controls */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.form-group label .required {
  color: var(--expense-color);
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

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

/* Event Detail Header & Tabs */
.detail-banner {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.detail-banner-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.detail-title h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.detail-title p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.detail-sub-tabs {
  display: flex;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.sub-tab-btn {
  padding: 0.75rem 1.25rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.sub-tab-btn:hover {
  color: var(--text-main);
}

.sub-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Progress bar inside summary */
.progress-bar-container {
  background-color: var(--bg-subtle);
  height: 10px;
  border-radius: 9999px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--income-color));
  border-radius: 9999px;
  transition: width 0.5s ease;
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: var(--text-light);
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 280px;
}

.toast.success { border-left: 4px solid var(--income-color); }
.toast.error { border-left: 4px solid var(--expense-color); }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Printable PDF View Overlay */
@media print {
  body {
    background-color: #ffffff !important;
    color: #000000 !important;
  }
  .app-header, .header-actions, .filter-bar, .btn, .nav-tabs {
    display: none !important;
  }
  .main-wrapper {
    padding: 0 !important;
    max-width: 100% !important;
  }
  .chart-card, .metric-card, .content-card {
    border: 1px solid #cccccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
}
