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

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --bg-card: #1e1e36;
  --bg-hover: #252547;
  --bg-active: #2d2d5a;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-glow: rgba(124, 58, 237, 0.3);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #2d2d5a;
  --border-hover: #4c4c8a;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* Title Bar */
.titlebar {
  height: 36px;
  background: var(--bg-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
}

.titlebar-drag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
}

.titlebar-icon {
  font-size: 16px;
}

.titlebar-title {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.titlebar-controls {
  display: flex;
  -webkit-app-region: no-drag;
}

.titlebar-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.titlebar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.titlebar-btn-close:hover {
  background: var(--danger);
  color: white;
}

/* App Layout */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.app-header {
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-title {
  font-size: 24px;
  font-weight: 600;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.app-subtitle .last-update {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 8px;
  opacity: 0.7;
}

.header-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 0 30px var(--accent-glow);
}

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

.btn-accent {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: white;
  box-shadow: 0 0 15px rgba(34, 197, 94, 0.3);
}

.btn-accent:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 25px rgba(34, 197, 94, 0.4);
}

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

.btn-accent .spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

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

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

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-icon {
  width: 18px;
  height: 18px;
}

.btn-icon-small {
  width: 14px;
  height: 14px;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

/* Panels */
.panel {
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.services-panel {
  flex: 1.2;
}

.plan-panel {
  flex: 0.8;
  border-left: 1px solid var(--border);
}

.panel-header {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Search */
.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  transition: all 0.2s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* Filters */
.filters {
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.filter-btn {
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.filter-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 15px var(--accent-glow);
}

/* Services List */
.services-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.services-list::-webkit-scrollbar {
  width: 6px;
}

.services-list::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.services-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.services-list::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* Service Category */
.service-category {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

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

.category-header {
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-header::before {
  content: '';
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
}

/* Service Item */
.service-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin: 4px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.service-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
  transform: translateX(4px);
}

.service-item.selected {
  background: var(--bg-active);
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.service-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.service-item.selected .service-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.service-checkbox::after {
  content: '✓';
  color: white;
  font-size: 12px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s ease;
}

.service-item.selected .service-checkbox::after {
  opacity: 1;
  transform: scale(1);
}

.service-info {
  flex: 1;
  min-width: 0;
}

.service-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.service-price {
  font-size: 14px;
  font-weight: 600;
  color: var(--success);
  white-space: nowrap;
}

.service-qty {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-btn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s ease;
  opacity: 0;
  pointer-events: none;
}

.service-item.selected .qty-btn {
  opacity: 1;
  pointer-events: auto;
}

.qty-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.qty-value {
  font-size: 13px;
  font-weight: 500;
  min-width: 20px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.service-item.selected .qty-value {
  opacity: 1;
}

/* Empty State */
.empty-state, .empty-plan {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state p, .empty-plan p {
  font-size: 14px;
  margin-bottom: 4px;
}

.empty-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* Patient Info */
.patient-info {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.input-field, .textarea-field {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.input-field:focus, .textarea-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-field::placeholder, .textarea-field::placeholder {
  color: var(--text-muted);
}

.textarea-field {
  min-height: 80px;
  resize: vertical;
  margin-top: 10px;
}

/* Selected Services */
.selected-services {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.selected-services::-webkit-scrollbar {
  width: 6px;
}

.selected-services::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.selected-services::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.selected-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin: 6px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  animation: slideIn 0.3s ease;
}

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

.selected-item-info {
  flex: 1;
  min-width: 0;
}

.selected-item-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-item-category {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.selected-item-price {
  font-size: 14px;
  font-weight: 600;
  color: var(--success);
  white-space: nowrap;
}

.selected-item-remove {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.selected-item-remove:hover {
  background: var(--danger);
  color: white;
}

/* Total Section */
.total-section {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.total-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.total-value {
  font-size: 14px;
  font-weight: 500;
}

.total-final {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.total-final .total-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.total-final .total-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.savings {
  color: var(--warning) !important;
}

/* Plan Actions */
.plan-actions {
  padding: 16px 20px;
  display: flex;
  gap: 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.plan-actions .btn {
  flex: 1;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease;
  z-index: 1000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

/* Animations */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.pulse {
  animation: pulse 0.3s ease;
}

/* Responsive */
@media (max-width: 900px) {
  .main-content {
    flex-direction: column;
  }
  
  .services-panel, .plan-panel {
    flex: none;
    height: 50%;
  }
  
  .plan-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
