:root {
  --bg-page: #FFFAF5;
  --bg-card: #FFFFFF;
  --bg-subtle: #F5F0EB;
  --bg-hover: #EDE8E2;
  --text-primary: #3D3D3D;
  --text-secondary: #7A7A7A;
  --text-muted: #B0B0B0;
  --border: #EBE5DE;
  --border-light: #F3EFE9;

  --pastel-mint: #B5EAD7;
  --pastel-rose: #F4C2C2;
  --pastel-lavender: #D5B5EB;
  --pastel-sky: #B5D8EB;
  --pastel-peach: #FAD5B5;
  --pastel-yellow: #FDF5B5;

  --covered-light: #D8F0DE;
  --covered: #B5EAD7;
  --today-bg: #FFF8E7;
  --today-border: #F0E6C8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-size: 18px;
}

#app {
  max-width: 100%;
  margin: 0 auto;
  padding: 10px 8px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 16px;
  flex-wrap: wrap;
}

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

.app-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.app-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 640px) {
  .app-subtitle { display: inline; }
}

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

.period-label {
  font-size: 20px;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
  color: var(--text-primary);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: #D5CFC8;
}

.btn:active {
  transform: scale(0.97);
}

.btn-icon {
  padding: 10px 12px;
  font-size: 20px;
  line-height: 1;
  min-width: 42px;
}

.btn-primary {
  background: var(--pastel-sky);
  border-color: #98C8DE;
  color: #2A5A7A;
  font-weight: 600;
}

.btn-primary:hover {
  background: #98C8DE;
  border-color: #7AB5D0;
}

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

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

.btn-toggle {
  border-radius: 0;
  border: 1px solid var(--border);
  font-size: 14px;
  padding: 8px 16px;
}

.btn-toggle:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.btn-toggle:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  border-left: none;
}

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

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--pastel-sky);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Error */
.error-message {
  padding: 12px 16px;
  background: #FDF0F0;
  border: 1px solid #F4D0D0;
  border-radius: var(--radius-sm);
  color: #B05050;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Views */
.view {
  display: none;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* Monthly View */
.monthly-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background-color: var(--border);
  flex: 1;
}

.day-name-header {
  background: var(--bg-subtle);
  padding: 14px 8px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.day-cell {
  background: var(--bg-card);
  min-height: 90px;
  padding: 6px 8px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.day-cell:hover {
  background: #FAF7F3;
}

.day-cell.other-month {
  background: #FCFAF7;
}

.day-cell.other-month .day-number {
  color: var(--text-muted);
}

.day-cell.today {
  background: var(--today-bg);
}

.day-cell.today .day-number {
  font-weight: 700;
  color: var(--text-primary);
}

.day-number {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.day-cell.covered .day-number {
  color: #2D7A4A;
  font-weight: 600;
}

.coverage-indicator {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 2px;
}

.coverage-dot {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  margin-bottom: 2px;
}

.day-event-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Weekly View - Timeline con sticky headers */
.weekly-container {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* Fixed top bar (day headers) */
.ww-top {
  display: flex;
  flex-shrink: 0;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.ww-corner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-right: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-subtle);
}

.ww-top-days {
  display: flex;
  flex: 1;
  min-width: 0;
}

.ww-top-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border-right: 1px solid var(--border-light);
  background: var(--bg-subtle);
}

.ww-top-day:last-child {
  border-right: none;
}

.ww-top-day.ww-today {
  background: var(--today-bg);
}

.ww-top-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ww-top-num {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.ww-top-day.ww-today .ww-top-num {
  color: #2A7A4A;
}

/* Scrollable body */
.ww-body {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Hour sidebar (sticky left) */
.ww-hour-sidebar {
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  align-self: flex-start;
}

.ww-hour-sidebar .ww-hlbl {
  position: absolute;
  right: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  transform: translateY(-50%);
  white-space: nowrap;
}

/* Day columns container */
.ww-daycols {
  display: flex;
  flex: 1;
  min-width: 490px;
}

.ww-col {
  flex: 1;
  position: relative;
  min-width: 0;
  border-right: 1px solid var(--border-light);
  background: var(--bg-card);
}

.ww-col:last-child {
  border-right: none;
}

.ww-today {
  background: #FFFDF5;
}

/* Hour grid lines */
.ww-hline {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border-light);
  pointer-events: none;
  z-index: 1;
}

.ww-hline-major {
  background: var(--border);
}

/* Event bars */
.ww-ev {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  z-index: 4;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  transition: transform 0.1s, box-shadow 0.1s;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 26px;
  border: 1px solid rgba(255,255,255,0.35);
}

.ww-ev:hover {
  transform: scaleX(1.03);
  box-shadow: 0 3px 12px rgba(0,0,0,0.18);
  z-index: 10;
}

.ww-ev:active {
  transform: scaleX(0.97);
}

.ww-ev-manual {
  outline: 2px dashed rgba(0,0,0,0.15);
  outline-offset: -2px;
}

.ww-ev-title {
  font-size: 14px;
  font-weight: 700;
  color: #2D5A3A;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ww-ev-time {
  font-size: 12px;
  font-weight: 500;
  color: rgba(45,90,58,0.65);
  line-height: 1.2;
  margin-top: 1px;
}

.ww-ev-note {
  font-size: 11px;
  font-weight: 400;
  color: rgba(45,90,58,0.5);
  line-height: 1.2;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weekly-wrap {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  height: 100%;
}

.ww-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.ww-sidebar {
  flex: 0 0 64px;
  position: relative;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  z-index: 3;
}

.ww-corner {
  border-bottom: 1px solid var(--border);
}

.ww-hlabel {
  position: absolute;
  right: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  transform: translateY(-50%);
  white-space: nowrap;
}

.ww-days {
  display: flex;
  min-width: 490px;
}

.ww-col {
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
}

.ww-col:last-child {
  border-right: none;
}

.ww-col-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.ww-today .ww-col-header {
  background: var(--today-bg);
}

.ww-day-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ww-day-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.ww-today .ww-day-num {
  color: #2A7A4A;
}

.ww-col-body {
  position: relative;
  background: var(--bg-card);
}

.ww-hline {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border-light);
  pointer-events: none;
}

.ww-hline-major {
  background: var(--border);
}

.ww-event {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 10px;
  padding: 4px 6px;
  cursor: pointer;
  z-index: 4;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  transition: transform 0.1s, box-shadow 0.1s;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 22px;
  border: 1px solid rgba(255,255,255,0.3);
}

.ww-event:hover {
  transform: scaleX(1.02);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 10;
}

.ww-event:active {
  transform: scaleX(0.98);
}

.ww-event-manual {
  outline: 2px dashed rgba(0,0,0,0.15);
  outline-offset: -2px;
}

.ww-event-title {
  font-size: 12px;
  font-weight: 700;
  color: #2D5A3A;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ww-event-time {
  font-size: 10px;
  font-weight: 500;
  color: rgba(45,90,58,0.65);
  line-height: 1.2;
  margin-top: 1px;
}

/* Stats row */
.stats-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 18px;
  font-size: 15px;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border-radius: var(--radius);
  margin-top: 12px;
}

.stats-row strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

.modal-sm {
  max-width: 380px;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

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

.modal-body {
  padding: 16px 24px 24px;
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal .modal-close {
  font-size: 22px;
  color: var(--text-muted);
  padding: 4px 8px;
}

/* Forms */
form {
  padding: 20px 24px 24px;
}

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

.form-group label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

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

input[type="text"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="file"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="url"]:focus,
input[type="date"]:focus,
input[type="time"]:focus {
  outline: none;
  border-color: var(--pastel-sky);
  box-shadow: 0 0 0 3px rgba(181, 216, 235, 0.2);
}

.form-help {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* Time picker */
.time-picker {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tp-select {
  flex: 1;
  padding: 12px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 18px;
  color: var(--text-primary);
  background: var(--bg-card);
  cursor: pointer;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
  text-align-last: center;
}
.tp-select:focus {
  outline: none;
  border-color: var(--pastel-sky);
  box-shadow: 0 0 0 3px rgba(181, 216, 235, 0.2);
}
.tp-sep {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1;
}

/* Color picker */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-option {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c);
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.15s;
  display: block;
}

.color-option:hover {
  transform: scale(1.1);
}

.color-option.selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--c);
}

/* Info banner */
.info-banner {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 20px;
}

.info-banner.hidden {
  display: none;
}

.info-banner-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  max-width: 440px;
  text-align: center;
  animation: slideUp 0.3s ease;
}

.info-banner-content strong {
  font-size: 20px;
  display: block;
  margin-bottom: 12px;
}

.info-banner-content p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.6;
}

.info-banner-content .btn {
  margin-top: 8px;
}

/* Utility */
.hidden {
  display: none !important;
}

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

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  max-width: 300px;
}

/* Responsive */
@media (max-width: 768px) {
  #app {
    padding: 12px;
  }

  .app-header {
    gap: 8px;
  }

  .header-left {
    width: 100%;
    order: -1;
  }

  .header-center {
    order: 0;
    flex: 1;
    justify-content: center;
  }

  .header-right {
    order: 1;
  }

  .period-label {
    font-size: 17px;
    min-width: 140px;
  }

  .day-cell {
    min-height: 70px;
    padding: 4px 6px;
  }

  .day-number {
    font-size: 14px;
  }

  .view-toggle .btn-toggle {
    padding: 6px 10px;
    font-size: 13px;
  }

  .ww-hour-sidebar {
    width: 54px !important;
  }

  .ww-hour-sidebar .ww-hlbl {
    font-size: 12px;
    right: 6px;
  }

  .ww-top-day {
    padding: 4px;
  }

  .ww-top-name {
    font-size: 13px;
  }

  .ww-top-num {
    font-size: 20px;
  }

  .ww-ev {
    left: 1px;
    right: 1px;
    border-radius: 8px;
    padding: 4px 6px;
  }

  .ww-ev-title {
    font-size: 13px;
  }

  .ww-ev-time {
    font-size: 11px;
  }

  .ww-ev-note {
    font-size: 10px;
  }

  .modal {
    max-width: 100%;
    margin: 10px;
  }
}

@media (max-width: 480px) {
  .day-cell {
    min-height: 56px;
    padding: 3px 4px;
  }

  .day-name-header {
    padding: 8px 4px;
    font-size: 12px;
  }

  .coverage-dot {
    height: 4px;
  }

  .app-title {
    font-size: 20px;
  }
}

/* Detail modal swatches */
.dc-swatch {
  transition: transform 0.1s, border-color 0.1s;
}
.dc-swatch:hover {
  transform: scale(1.15);
}
.dc-swatch.dc-active {
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text-primary);
}

/* Scrollbar styling */
.weekly-container::-webkit-scrollbar {
  height: 6px;
}

.weekly-container::-webkit-scrollbar-track {
  background: var(--bg-subtle);
}

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

.weekly-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
