/* ===== CSS Variables ===== */
:root {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-column: #d6e0f0;
  --text-primary: #172b4d;
  --text-secondary: #5e6c84;
  --border-color: #dfe1e6;
  --accent: #0079bf;
  --accent-hover: #026aa7;
  --danger: #eb5a46;
  --danger-hover: #cf513d;
  --priority-high: #eb5a46;
  --priority-medium: #f2d600;
  --priority-low: #61bd4f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.15);
  --radius: 8px;
  --radius-sm: 4px;
  --header-height: 56px;
  --footer-height: 32px;
}

:root.dark {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-column: #0f3460;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --border-color: #2a2a4a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}

.btn-share {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

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

.btn-other-apps {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.btn-other-apps:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.other-apps-label,
.help-label {
  white-space: nowrap;
}

.btn-help {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

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

.btn-dark-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.btn-dark-mode:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.header-center {
  flex: 1;
  max-width: 400px;
}

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

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

.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  margin-top: 4px;
}

.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-primary);
}

.search-no-results {
  padding: 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ===== Buttons ===== */
.btn-primary {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

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

.btn-danger {
  padding: 8px 16px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

/* ===== View Toggle ===== */
.view-toggle {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-btn {
  padding: 6px 14px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
}

.view-btn:hover:not(.active) {
  background: var(--border-color);
}

/* ===== Main Content ===== */
.app-main {
  flex: 1;
  overflow: hidden;
}

.view-section {
  display: none;
  height: calc(100vh - var(--header-height) - var(--footer-height));
  overflow: auto;
}

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

/* ===== Kanban Board ===== */
.kanban-board {
  display: flex;
  gap: 16px;
  padding: 16px;
  min-height: 100%;
  overflow-x: auto;
}

.kanban-column {
  flex: 1;
  min-width: 280px;
  max-width: 360px;
  background: var(--bg-column);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 2px solid var(--border-color);
}

.column-header h2 {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.task-count {
  background: var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

.column-tasks {
  flex: 1;
  padding: 8px;
  min-height: 100px;
  transition: background 0.2s;
}

.column-tasks.drag-over {
  background: rgba(0, 121, 191, 0.1);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ===== Task Cards ===== */
.task-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: grab;
  transition: box-shadow 0.2s, transform 0.15s;
  border-left: 4px solid transparent;
}

.task-card:hover {
  box-shadow: var(--shadow-hover);
}

.task-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
  cursor: grabbing;
}

.task-card.priority-high {
  border-left-color: var(--priority-high);
}

.task-card.priority-medium {
  border-left-color: var(--priority-medium);
}

.task-card.priority-low {
  border-left-color: var(--priority-low);
}

.task-card-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.task-card-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.task-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
}

.task-card-due {
  color: var(--text-secondary);
}

.task-card-due.overdue {
  color: var(--priority-high);
  font-weight: 700;
}

.priority-tag {
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
}

.priority-tag.high { background: var(--priority-high); }
.priority-tag.medium { background: var(--priority-medium); color: #333; }
.priority-tag.low { background: var(--priority-low); }

.task-card.highlight {
  animation: highlightPulse 1.5s ease-out;
}

@keyframes highlightPulse {
  0% { box-shadow: 0 0 0 3px var(--accent); }
  100% { box-shadow: var(--shadow); }
}

/* ===== Calendar ===== */
.calendar-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px;
}

.cal-nav-btn {
  padding: 6px 14px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.2s;
}

.cal-nav-btn:hover {
  background: var(--bg-column);
}

.cal-title {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 180px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border-color);
  margin: 0 16px 16px;
  border-radius: var(--radius);
  overflow: hidden;
}

.cal-day-header {
  background: var(--bg-column);
  padding: 8px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.cal-day {
  background: var(--bg-secondary);
  min-height: 100px;
  padding: 6px;
  position: relative;
}

.cal-day.other-month {
  opacity: 0.4;
}

.cal-day.today {
  background: rgba(0, 121, 191, 0.08);
}

.cal-day-number {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.cal-day.today .cal-day-number {
  color: var(--accent);
  font-weight: 700;
}

.cal-task {
  font-size: 0.65rem;
  padding: 2px 4px;
  margin-bottom: 2px;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  transition: opacity 0.2s;
}

.cal-task:hover {
  opacity: 0.8;
}

.cal-task.priority-high { background: var(--priority-high); }
.cal-task.priority-medium { background: var(--priority-medium); color: #333; }
.cal-task.priority-low { background: var(--priority-low); }

.cal-task.overdue {
  text-decoration: line-through;
  opacity: 0.7;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

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

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

/* ===== Forms ===== */
.task-form {
  padding: 20px;
}

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

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

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

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-secondary);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  z-index: 600;
  box-shadow: var(--shadow-hover);
  animation: toastIn 0.3s ease;
}

.toast[hidden] {
  display: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Update Banner ===== */
.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 1000;
}

.update-banner[hidden] {
  display: none;
}

.btn-update {
  padding: 4px 14px;
  background: #fff;
  color: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

/* ===== Footer ===== */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--footer-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.status-online::before,
.status-offline::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.status-online::before {
  background: var(--priority-low);
}

.status-offline::before {
  background: var(--priority-high);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-header {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
  }

  .header-left {
    order: 1;
  }

  .header-right {
    order: 2;
  }

  .header-center {
    order: 3;
    flex-basis: 100%;
    max-width: 100%;
    margin-top: 8px;
  }

  .app-title {
    font-size: 0.95rem;
  }

  .kanban-board {
    flex-direction: column;
    padding: 8px;
  }

  .kanban-column {
    max-width: 100%;
    min-width: 100%;
  }

  .view-section {
    height: auto;
    min-height: calc(100vh - 120px);
  }

  .cal-day {
    min-height: 60px;
    padding: 4px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (max-width: 480px) {
  .calendar-grid {
    margin: 0 8px 8px;
  }

  .cal-day-header {
    font-size: 0.65rem;
    padding: 4px;
  }
}
