:root {
  --color-bg: #ffffff;
  --color-bg-secondary: #f7f6f3;
  --color-bg-tertiary: #f1f0ed;
  --color-border: #e6e4e0;
  --color-text: #37352f;
  --color-text-secondary: #787774;
  --color-primary: #2383e2;
  --color-primary-hover: #1a6dbd;
  --color-success: #0f7b6c;
  --color-warning: #d9730d;
  --color-danger: #e03e3e;
  --color-sidebar: #fbfbfa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.12);
  --radius: 6px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-bg-secondary);
  color: var(--color-text);
  line-height: 1.5;
}

/* Screens */
.screen {
  display: none;
}

.screen.active {
  display: flex;
}

/* Login Screen */
#login-screen {
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  background: var(--color-bg);
}

.login-container {
  width: 100%;
  max-width: 360px;
  padding: 48px 40px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.logo {
  font-size: 48px;
  text-align: center;
  margin-bottom: 16px;
}

.login-container h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 4px;
}

.subtitle {
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

#login-form input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--color-bg);
  transition: border 0.2s;
}

#login-form input:focus {
  outline: none;
  border-color: var(--color-primary);
}

#login-form button {
  width: 100%;
  padding: 10px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

#login-form button:hover {
  background: var(--color-primary-hover);
}

.error {
  margin-top: 12px;
  padding: 8px 12px;
  background: #fee;
  color: var(--color-danger);
  border-radius: var(--radius);
  font-size: 13px;
  display: none;
}

.error.show {
  display: block;
}

/* App Layout */
#app-screen {
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
}

.logo-small {
  font-size: 24px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--color-bg-tertiary);
}

.nav-item.active {
  background: var(--color-bg-tertiary);
  font-weight: 500;
}

.nav-item .icon {
  font-size: 18px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.user-details {
  flex: 1;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
}

.user-role {
  font-size: 11px;
  color: var(--color-text-secondary);
}

.logout-btn {
  width: 100%;
  padding: 6px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.logout-btn:hover {
  background: var(--color-bg-tertiary);
}

/* Main Content */
.main-content {
  margin-left: 240px;
  padding: 40px;
  min-height: 100vh;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.view-header h1 {
  font-size: 32px;
  font-weight: 600;
}

/* Buttons */
.btn-primary, .btn-secondary {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

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

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

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

/* Filters */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.filter-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover {
  background: var(--color-bg-tertiary);
}

.filter-btn.active {
  background: var(--color-text);
  color: white;
  border-color: var(--color-text);
}

/* Tasks List */
.tasks-list, .wiki-list, .team-list {
  display: grid;
  gap: 12px;
}

.task-card, .wiki-card, .team-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.task-card:hover, .wiki-card:hover {
  border-color: var(--color-text-secondary);
  box-shadow: var(--shadow-sm);
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.task-title {
  font-weight: 500;
  font-size: 15px;
}

.task-meta {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}

.badge.priority-high { background: #ffe2dd; color: var(--color-danger); }
.badge.priority-medium { background: #fff3cd; color: var(--color-warning); }
.badge.priority-low { background: #e3f2fd; color: var(--color-primary); }

.badge.status-todo { background: #f1f0ed; color: var(--color-text-secondary); }
.badge.status-in_progress { background: #e3f2fd; color: var(--color-primary); }
.badge.status-done { background: #d3f8df; color: var(--color-success); }
.badge.status-blocked { background: #ffe2dd; color: var(--color-danger); }

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--color-bg);
  border-radius: var(--radius);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-large {
  max-width: 800px;
}

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

.modal-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--color-text-secondary);
  line-height: 1;
  padding: 0;
}

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

form {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--color-bg);
}

.form-group textarea {
  resize: vertical;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 13px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}

/* Comments */
#task-comments-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

#task-comments-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.comment {
  padding: 12px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 13px;
}

.comment-author {
  font-weight: 600;
  margin-bottom: 4px;
}

.comment-time {
  color: var(--color-text-secondary);
  font-size: 11px;
  margin-left: 8px;
}

#comment-form {
  margin-top: 12px;
  padding: 0;
  display: flex;
  gap: 8px;
}

#comment-form textarea {
  flex: 1;
}

/* Team List */
.team-card {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: default;
}

.team-card:hover {
  border-color: var(--color-border);
  box-shadow: none;
}

.team-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.team-info {
  flex: 1;
}

.team-name {
  font-weight: 500;
  font-size: 15px;
}

.team-email {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.team-role {
  font-size: 12px;
  color: var(--color-text-secondary);
  text-transform: capitalize;
}

/* Projects */
.projects-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

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

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.project-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text);
}

.project-description {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.project-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  transition: width 0.3s;
}

/* Filter Selects */
.filter-selects {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
}

.filter-select:hover {
  border-color: var(--color-primary);
}

/* CRM */
.crm-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  flex: 1;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--color-primary);
}

.stat-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

.crm-pipeline {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
}

.pipeline-column {
  flex: 0 0 280px;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius);
  padding: 12px;
}

.pipeline-column h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pipeline-column .count {
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.pipeline-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 400px;
}

.lead-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.lead-card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.lead-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.lead-type {
  font-size: 12px;
  color: var(--color-text-secondary);
  text-transform: capitalize;
  margin-bottom: 4px;
}

.lead-company {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.lead-value {
  font-size: 13px;
  color: var(--color-success);
  font-weight: 600;
  margin-bottom: 4px;
}

.lead-assignee {
  font-size: 11px;
  color: var(--color-text-secondary);
}

.interaction {
  background: var(--color-bg-tertiary);
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.interaction-header {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}

.interaction-type {
  background: var(--color-primary);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
}

.interaction-user {
  color: var(--color-text-secondary);
}

.interaction-time {
  color: var(--color-text-secondary);
  margin-left: auto;
}

.interaction-notes {
  font-size: 13px;
  color: var(--color-text);
}

/* Calendar */
.calendar-simple {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calendar-event-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

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

.event-date {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.event-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.event-time {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.event-type {
  display: inline-block;
  font-size: 11px;
  background: var(--color-bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
  margin-bottom: 4px;
}

.event-location {
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* Card Actions (Delete buttons) */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.btn-action {
  flex: 1;
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-sans);
}

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

.btn-action.btn-danger {
  color: var(--color-danger);
  border-color: #fecaca;
}

.btn-action.btn-danger:hover {
  background: #fef2f2;
  border-color: var(--color-danger);
}

/* Prevent card click when clicking buttons */
.task-card .card-actions,
.project-card .card-actions,
.lead-card .card-actions,
.calendar-event-card .card-actions,
.wiki-card .card-actions {
  pointer-events: auto;
}

/* Fix modal overflow */
.modal-content {
  max-height: 90vh;
  overflow-y: auto;
}

.modal-large .modal-content {
  max-width: 800px;
}

/* Better status badges */
.badge.status-active {
  background: #d1fae5;
  color: #065f46;
}

.badge.status-on-hold {
  background: #fef3c7;
  color: #92400e;
}

.badge.status-completed {
  background: #dbeafe;
  color: #1e40af;
}

.badge.status-archived {
  background: #e5e7eb;
  color: #374151;
}

/* Smooth hover effects */
.task-card, .project-card, .lead-card, .calendar-event-card, .wiki-card {
  transition: all 0.2s ease;
}

.task-card:hover, .project-card:hover, .calendar-event-card:hover, .wiki-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.lead-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Better scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg-tertiary);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}

/* Loading state */
.loading {
  opacity: 0.5;
  pointer-events: none;
}

/* Empty states */
.view p {
  margin: 0;
}

/* Fix form spacing */
.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-row .form-group {
  margin-bottom: 0;
}

/* Better modal backdrop */
.modal {
  backdrop-filter: blur(2px);
}

/* Responsive improvements */
@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .filter-selects {
    flex-direction: column;
  }
  
  .crm-stats {
    flex-direction: column;
  }
  
  .projects-list {
    grid-template-columns: 1fr;
  }
}
