:root {
  --bg: #1a1d23;
  --bg-elevated: #22262e;
  --bg-card: #2a2f38;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #5b7cff;
  --accent-hover: #7a94ff;
  --accent-soft: rgba(91, 124, 255, 0.12);
  --partner: #e85d8a;
  --partner-soft: rgba(232, 93, 138, 0.12);
  --danger: #e57373;
  --success: #66bb6a;
  --border: #3a3f48;
  --now-line: #ffb74d;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.15);
}

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

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh; /* More reliable on mobile */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Login screen */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(160deg, var(--bg) 0%, #242830 50%, var(--bg) 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.25rem;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--accent), var(--partner));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

#login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
}

#login-form input::placeholder {
  color: var(--text-muted);
}

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

#login-form button {
  width: 100%;
  padding: 0.875rem;
  margin-top: 0.5rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

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

.secret-link-hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* Calendar screen */
#calendar-screen {
  min-height: 100vh;
  padding-bottom: 80px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(1rem + env(safe-area-inset-top, 0px)) 1.25rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

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

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

#user-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#logout-btn {
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
}

#logout-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-elevated);
}

main {
  padding: 1rem 1.25rem;
  max-width: 900px;
  margin: 0 auto;
}

/* Social battery */
.social-battery-section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.social-battery-section .section-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.social-batteries-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  max-width: 360px;
}

@media (max-width: 500px) {
  .social-batteries-grid {
    max-width: 100%;
  }
}

.social-battery-card {
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  min-width: 220px;
  max-width: 320px;
}

.social-battery-card.you {
  border-color: var(--accent);
}

.social-battery-card.partner {
  border-color: var(--partner);
}

.social-battery-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.social-battery-slider-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.social-battery-emoji {
  font-size: 1.75rem;
  flex-shrink: 0;
}

.social-battery-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
}

.social-battery-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-card);
  box-shadow: 0 0 0 1px var(--border);
}

.social-battery-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-card);
}

.social-battery-card.readonly .social-battery-slider {
  pointer-events: none;
  opacity: 0.8;
}

.social-battery-card.readonly .social-battery-slider::-webkit-slider-thumb {
  cursor: default;
}

.social-battery-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.social-battery-labels span {
  flex: 1;
  text-align: center;
}

.social-battery-error {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.5rem 0;
}

.view-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}

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

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Upcoming section */
.upcoming-section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.upcoming-section h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upcoming-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.upcoming-item:hover {
  background: var(--bg-elevated);
}

.upcoming-item .date-badge {
  flex-shrink: 0;
  width: 48px;
  text-align: center;
}

.upcoming-item .date-badge .day {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.upcoming-item .date-badge .month {
  font-size: 0.7rem;
  color: var(--text-muted);
}

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

.upcoming-item .event-title {
  font-weight: 500;
}

.upcoming-item .event-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.upcoming-item .event-creator {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* Calendar section */
.calendar-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

.calendar-header button {
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.calendar-header button:hover {
  color: var(--accent);
}

#today-btn {
  padding: 0.5rem 0.75rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
}

#today-btn:hover {
  background: var(--accent);
  color: white;
}

#current-date-label {
  font-size: 1rem;
  font-weight: 600;
}

/* Day view */
#day-view {
  display: flex;
  min-height: 400px;
}

.time-column {
  flex-shrink: 0;
  width: 56px;
  position: relative;
}

.time-slots {
  padding: 0 0 1rem;
}

.time-slot {
  height: 50px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-right: 0.5rem;
  text-align: right;
}

.events-column {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--border);
}

.events-container {
  position: relative;
  min-height: 550px; /* 11h (8AM-6PM) * 50px */
}

/* Current time line */
.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--now-line);
  z-index: 10;
  pointer-events: none;
}

.now-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -4px;
  width: 10px;
  height: 10px;
  background: var(--now-line);
  border-radius: 50%;
}

/* Event blocks */
.event-block {
  position: absolute;
  left: 4px;
  right: 4px;
  padding: 6px 8px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  font-size: 0.85rem;
  border-left: 3px solid;
}

.event-block .event-block-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-block .event-block-time {
  font-size: 0.75rem;
  opacity: 0.9;
}

/* Week view */
#week-view {
  padding: 1rem;
}

.week-day-cell {
  min-width: 0;
}

#week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

@media (max-width: 600px) {
  #week-grid {
    grid-template-columns: 1fr;
  }
}

.week-day-header {
  padding: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.week-day-header.today {
  color: var(--accent);
}

.week-day-column {
  min-height: 300px;
  padding: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

/* FAB */
#add-event-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 1.75rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
  z-index: 50;
}

#add-event-fab:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

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

@media (min-width: 480px) {
  .modal {
    align-items: center;
    padding: 20px;
  }
}

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

.modal-content {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem;
  border: 1px solid var(--border);
}

@media (min-width: 480px) {
  .modal-content {
    border-radius: var(--radius);
  }
}

.modal-content h3 {
  margin-bottom: 1rem;
}
.modal-content h4 {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 1rem 0 0.5rem;
}
.modal-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}
.secret-link-section {
  margin-bottom: 0.5rem;
}
.secret-link-section label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.secret-link-box {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.secret-link-box input {
  flex: 1;
  margin-bottom: 0;
  font-size: 0.85rem;
}
.secret-link-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.import-calendar-section .import-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.import-url-box {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.import-url-box input {
  flex: 1;
  margin-bottom: 0;
  font-size: 0.9rem;
}
.import-result {
  font-size: 0.85rem;
  padding: 0.5rem;
  border-radius: 6px;
}
.import-result.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success, #22c55e);
}
.import-result.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger, #ef4444);
}

.modal-content input,
.modal-content textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
}

/* Date/datetime pickers - improve visibility on dark theme */
input[type="date"],
input[type="datetime-local"],
input[type="time"] {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  padding: 0.6rem 0.75rem !important;
  font-size: 1rem !important;
  min-height: 44px;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  opacity: 0.8;
  cursor: pointer;
}

.modal-content label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  gap: 1rem;
}

.modal-actions-right {
  display: flex;
  gap: 0.5rem;
}

.modal-actions button {
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
}

.modal-actions button[type="submit"] {
  background: var(--accent);
  border: none;
  color: white;
}

.modal-actions button[type="button"]:not(.btn-danger) {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

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

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.ics-url-box {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

.ics-url-box input {
  flex: 1;
  font-size: 0.85rem;
}

.ics-url-box button {
  padding: 0.5rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
}

.ics-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Tasks */
.tasks-section {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

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

.tasks-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#tasks-project-select {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
}

.task-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.task-form input[type="date"],
.task-form input[type="datetime-local"] {
  min-height: 44px;
}

.task-form input[type="date"]::-webkit-calendar-picker-indicator,
.task-form input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  opacity: 0.8;
}

.task-form-row {
  display: flex;
  gap: 0.5rem;
}

.task-form-row input {
  flex: 1;
}

.task-form-extras {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.75rem 0;
}

.task-form-field {
  min-width: 120px;
}

.task-form-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.task-form-field select {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.task-form-labels {
  flex: 1;
  min-width: 160px;
}

.task-labels-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.task-labels-checkboxes label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.task-priority-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--bg-card);
}

.task-priority-badge.p1 { color: #ef4444; }
.task-priority-badge.p2 { color: #f59e0b; }
.task-priority-badge.p3 { color: #eab308; }
.task-priority-badge.p4 { color: var(--text-muted); }

.task-labels-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 2px;
}

.task-label-tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
}

.task-form-actions {
  display: flex;
  justify-content: flex-end;
}

.task-form-actions button,
.tasks-controls button,
.tasks-subheader button {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
}

.task-form-actions button[type="submit"] {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.task-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.task-item.completed {
  opacity: 0.85;
}

.task-main {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-weight: 600;
}

.task-due {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.task-note {
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.task-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.task-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

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

.task-btn[data-action="delete"]:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.task-empty, .task-error {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tasks-subheader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Safe area for mobile */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #add-event-fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: calc(24px + env(safe-area-inset-right));
  }
}
