/* Modern UI Variables */
:root {
  --primary-color: #2563eb;
  /* Modern Blue */
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  /* Slate */
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-color: #1e293b;
  --border-color: #e2e8f0;
  --radius: 8px;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-hover: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* Scoped Container for Modern UI Controls */
.modern-ui-container {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text-color);
  max-width: 1200px;
  margin: 0 auto;
}

.modern-ui-container h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #0f172a;
  margin: 1.5rem 0;
  letter-spacing: -0.025em;
}

.modern-ui-container .header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  gap: 1rem;
  /* Removed border-bottom for more compact design */
}

.modern-ui-container .header-action-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex: 1;
  justify-content: center;
}

.modern-ui-container .header-btn {
  padding: 0.625rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-color);
}

.modern-ui-container .header-btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: var(--primary-color);
}

.modern-ui-container .header-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.modern-ui-container .header-btn.primary-btn {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.modern-ui-container .header-btn.primary-btn:hover:not(:disabled) {
  background: #1e40af;
  border-color: #1e40af;
}

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

.modern-ui-container .logout-link {
  color: var(--secondary-color);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.modern-ui-container .logout-link:hover {
  background-color: #f1f5f9;
  color: var(--text-color);
}

/* Tab Navigation */
.tab-navigation {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 0.75rem;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.5rem 1rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--secondary-color);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  position: relative;
  bottom: -2px;
}

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

.tab-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  font-weight: 600;
}

/* Tab Content */
.tab-content {
  position: relative;
}

.tab-panel {
  display: none;
  padding: 0.75rem 0;
  animation: fadeIn 0.2s ease-in;
}

.tab-panel.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Options inline layout */
.options-inline-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.options-inline-row .show-event-times {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.options-inline-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

/* Feed Sub-tabs */
.feed-sub-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 1rem;
}

.feed-sub-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.4rem 0.75rem;
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--secondary-color);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  position: relative;
  bottom: -2px;
}

.feed-sub-tab-btn:hover {
  color: var(--primary-color);
  background: #f8fafc;
}

.feed-sub-tab-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  font-weight: 600;
}

.feed-sub-tab-btn.has-url {
  font-weight: 700;
}

.feed-sub-tab-btn:not(.has-url) {
  opacity: 0.5;
}

.feed-sub-content {
  position: relative;
}

.feed-sub-panel {
  display: none;
}

.feed-sub-panel.active {
  display: block;
}


/* Form Controls */
.modern-ui-container input[type="text"],
.modern-ui-container input[type="password"],
.modern-ui-container input[type="number"],
.modern-ui-container select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background-color: #fff;
}

.modern-ui-container input:focus,
.modern-ui-container select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.modern-ui-container input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
  vertical-align: middle;
}

.modern-ui-container input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.modern-ui-container input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
  border: 1px solid var(--border-color);
}

/* Buttons */
.modern-ui-container button {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border-color);
  background-color: white;
  color: var(--text-color);
}

.modern-ui-container button:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.modern-ui-container button.primary-btn {
  background-color: var(--primary-color);
  color: white;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.modern-ui-container button.primary-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.modern-ui-container button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Grid Layouts for Sections */

/* Template Controls */
.template-controls-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.template-grid-save {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Feed Grid */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.feed-item {
  background-color: #f8fafc;
  padding: 1rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.feed-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}

.feed-row label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--secondary-color);
  min-width: 80px;
}

/* Main Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
  padding: 1.5rem;
  background: white;
  border-top: 1px solid var(--border-color);
  position: sticky;
  bottom: 0;
  z-index: 10;
  /* Above normal content but below loading overlay */
}

/* View Range Selector */
.view-range-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: white;
  padding: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
  margin-top: 0.5rem;
}

/* Typography fix */
.modern-ui-container label {
  font-weight: 500;
}

/* Widen "Match text" fields */
.modern-ui-container .rule-entry {
  display: flex;
  align-items: flex-end;
  /* Align bottom to match inputs */
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--border-color);
}

.modern-ui-container .rule-entry:last-child {
  border-bottom: none;
}

.modern-ui-container .rule-text-field {
  flex: 2;
  /* Take up twice as much space as others */
  display: flex;
  flex-direction: column;
}

.modern-ui-container .rule-text-field input {
  width: 100%;
}

.modern-ui-container .rule-color-field,
.modern-ui-container .rule-text-color-field {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Hamburger Menu Button Styling */
.modern-ui-container .hamburger-menu-btn {
  display: flex;
  /* Always visible at all screen widths */
  position: relative;
  background: #1e40af !important;
  /* Darker blue for better contrast */
  border: 2px solid #1e3a8a !important;
  /* Dark blue border */
  padding: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  z-index: 1000;
  margin-left: 0.5rem;
  flex-direction: column;
  gap: 5px;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  flex-shrink: 0;
  /* Prevent button from shrinking */
}

.modern-ui-container .hamburger-menu-btn:hover {
  background: #1e3a8a !important;
  /* Even darker on hover */
  border-color: #172554 !important;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
}

.hamburger-icon {
  display: block;
  width: 24px;
  height: 3px;
  background: #ffffff;
  /* Solid white for maximum contrast */
  border-radius: 2px;
  transition: all 0.3s ease;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  /* Subtle shadow on lines */
}

/* Hamburger animation when menu is open */
.hamburger-menu-btn.active .hamburger-icon:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger-menu-btn.active .hamburger-icon:nth-child(2) {
  opacity: 0;
}

.hamburger-menu-btn.active .hamburger-icon:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Form Controls Wrapper - Hidden by default, toggleable at all screen widths */
.form-controls-wrapper {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.3s ease;
}

.form-controls-wrapper.open {
  max-height: 10000px;
  opacity: 1;
  overflow: visible;
}

/* Desktop: Show form controls by default, but still allow toggle */
@media (min-width: 769px) {
  .form-controls-wrapper:not(.manually-closed) {
    max-height: none;
    opacity: 1;
    overflow: visible;
  }
}

/* Responsive Styles for Narrow Screens */
@media (max-width: 768px) {

  /* Adjust header bar for mobile */
  .modern-ui-container .header-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .modern-ui-container h1 {
    font-size: 1.5rem;
  }

  /* Stack action bar buttons on mobile */
  .action-bar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .action-bar button {
    width: 100%;
  }

  /* Stack view range selectors on mobile */
  .view-range-container {
    flex-direction: column;
    align-items: stretch;
  }

  .view-range-container label {
    width: 100%;
  }

  .view-range-container select {
    width: 100%;
  }
}

/* Mobile device-specific styles */
body.mobile-device .modern-ui-container .header-bar {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

body.mobile-device .modern-ui-container h1 {
  font-size: 1.5rem;
}

body.mobile-device .action-bar {
  flex-direction: column;
  gap: 0.5rem;
}

body.mobile-device .action-bar button {
  width: 100%;
}

body.mobile-device .view-range-container {
  flex-direction: column;
  align-items: stretch;
}

body.mobile-device .view-range-container label {
  width: 100%;
}

body.mobile-device .view-range-container select {
  width: 100%;
}

/* Toggle Switch Styling */
.view-toggle-switch {
  position: relative;
  display: inline-flex;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 4px;
  gap: 0;
}

.view-toggle-switch input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.view-toggle-switch label {
  position: relative;
  padding: 8px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  transition: color 0.3s ease;
  z-index: 2;
  user-select: none;
}

.view-toggle-switch input[type="radio"]:checked+label {
  color: #ffffff;
}

.view-toggle-switch .toggle-slider {
  position: absolute;
  background: var(--primary-color);
  border-radius: 6px;
  transition: transform 0.3s ease, width 0.3s ease;
  height: calc(100% - 8px);
  top: 4px;
  left: 4px;
  z-index: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Adjust slider width and position based on which option is selected */
.view-toggle-switch input#viewCalendar:checked~.toggle-slider {
  width: calc(50% - 4px);
  transform: translateX(0);
}

.view-toggle-switch input#viewTodo:checked~.toggle-slider {
  width: calc(50% - 4px);
  transform: translateX(calc(100%));
}

.view-toggle-switch label:hover {
  color: var(--primary-color);
}

.view-toggle-switch input[type="radio"]:checked+label:hover {
  color: #ffffff;
}

/* Unified Todo View in Calendar Grid */
.todo-group-event {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  margin-bottom: 4px !important;
}

.todo-group-event .fc-event-main {
  color: var(--text-color) !important;
  white-space: normal !important;
  overflow: visible !important;
}

.todo-group-header {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 2px;
  color: var(--primary-color);
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 1px;
}

.todo-group-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.todo-group-item {
  display: flex;
  align-items: flex-start;
  font-size: 0.8rem;
  line-height: 1.3;
  margin-bottom: 2px;
  gap: 4px;
}

.todo-icon-checkbox {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid #94a3b8;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 2px;
  background: white;
}

/* Hide event time/dot for todo items if they leak through */
.todo-group-event .fc-daygrid-event-dot,
.todo-group-event .fc-event-time {
  display: none !important;
}

/* Remove 'Today' highlight in Todo View */
.todo-view-mode .fc-day-today {
  background: transparent !important;
}