/* =========================
   Apple Premium Dark Theme
   Full CSS (drop-in replacement)
   ========================= */

/* --- Theme Tokens --- */
:root {
  /* Apple Dark Surfaces */
  --background: #1c1c1e;  /* systemBackground */
  --card-bg: #2c2c2e;     /* secondarySystemBackground */
  --surface: #3a3a3c;     /* tertiarySystemBackground */

  /* Text */
  --text: #f2f2f7;        /* label */
  --text-light: #8e8e93;  /* secondaryLabel */

  /* Borders / Dividers */
  --border: #3a3a3c;

  /* Accent (Apple blue) */
  --primary: #0a84ff;
  --primary-hover: #409cff;
  --primary-light: rgba(10, 132, 255, 0.18);

  /* Status */
  --success: #30d158;
  --error: #ff453a;
}

/* --- Base Reset --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background-color: var(--background);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */
.container {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 30px;
}

h1 {
  font-size: 2.2rem;
  color: var(--text);
  font-weight: 700;
}

/* --- Cards / Panels --- */
.login-container,
.diary-entry {
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  padding: 30px;
  margin: auto;
  max-width: 450px;
  width: 100%;
}

.form-title {
  font-size: 1.5rem;
  margin-bottom: 20px;
  text-align: center;
  color: var(--text);
}

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

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text);
}

/* --- Inputs (Apple-like) --- */
input,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-light);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

textarea {
  min-height: 200px;
  resize: vertical;
}

/* --- Buttons (never invisible) --- */
button {
  background: var(--primary);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px;
  font-weight: 600;
  transition: background-color 0.2s ease, transform 0.05s ease, border-color 0.2s ease;
  cursor: pointer;
}

button:hover {
  background: var(--primary-hover);
}

button:active {
  transform: scale(0.99);
}

/* Logout button (text-style) */
#logout-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  width: auto;
  padding: 5px 10px;
}

#logout-btn:hover {
  text-decoration: underline;
}

/* --- Messages --- */
.message {
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 20px;
  display: none;
}

.error {
  background-color: rgba(255, 69, 58, 0.12);
  color: var(--error);
  border: 1px solid rgba(255, 69, 58, 0.25);
}

.success {
  background-color: rgba(48, 209, 88, 0.12);
  color: var(--success);
  border: 1px solid rgba(48, 209, 88, 0.25);
}

/* --- Controls --- */
.diary-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

/* Search should look like Apple input */
.search-box {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  width: 250px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
}

.search-box::placeholder {
  color: var(--text-light);
}

.search-box:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Primary action button (Apple blue) */
.new-entry-btn {
  background-color: var(--primary);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  min-width: 120px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.10);
  transition: background-color 0.2s ease, transform 0.05s ease;
}

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

.new-entry-btn:active {
  transform: scale(0.99);
}

/* --- Entries Grid --- */
.entries-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.entry-card {
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.entry-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}

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

.entry-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.entry-date {
  color: var(--text-light);
  font-size: 0.9rem;
}

.entry-preview {
  color: var(--text-light);
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  flex-grow: 1;
}

/* --- Modal --- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.modal-content {
  background-color: var(--card-bg);
  padding: 30px;
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  position: relative;
}

.close-modal {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-light);
  width: auto;
  cursor: pointer;
}

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

/* --- Button Groups --- */
.button-group {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.button-group button {
  flex: 1;
}

/* Delete button (Apple red) */
.delete-btn {
  background-color: rgba(255, 69, 58, 0.18);
  color: var(--error);
  border: 1px solid rgba(255, 69, 58, 0.35);
}

.delete-btn:hover {
  background-color: rgba(255, 69, 58, 0.28);
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  margin: 50px auto;
  color: var(--text-light);
}

.empty-state p {
  margin-bottom: 20px;
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: center;
  margin-top: 30px;
  gap: 8px;
}

.pagination-button {
  background-color: var(--card-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  width: auto;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.pagination-button:hover:not(.active, .disabled) {
  background-color: #3a3a3c;
}

.pagination-button.active {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.pagination-button.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.pagination-info {
  text-align: center;
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 10px;
}

/* --- Calendar Navigation --- */
.calendar-navigation {
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  padding: 15px;
  margin-bottom: 20px;
}

.calendar-nav-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 15px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.calendar-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

/* Calendar previous/next */
.calendar-button {
  background-color: rgba(10, 132, 255, 0.18);
  color: var(--primary);
  border: 1px solid rgba(10, 132, 255, 0.25);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  width: auto;
}

.calendar-button:hover {
  background-color: rgba(10, 132, 255, 0.28);
}

/* Calendar grid */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.calendar-day-header {
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-light);
  padding: 5px;
}

.calendar-day {
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.2s;
  color: var(--text);
}

.calendar-day:hover:not(.empty, .selected) {
  background-color: rgba(255, 255, 255, 0.06);
}

.calendar-day.today {
  border: 1px solid var(--primary);
  font-weight: 800;
}

.calendar-day.has-entries {
  color: var(--primary);
  font-weight: 800;
}

.calendar-day.selected {
  background-color: var(--primary);
  color: #ffffff;
}

.calendar-day.empty {
  color: rgba(255, 255, 255, 0.18);
  cursor: default;
}

/* --- Filters --- */
.filter-section {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
}

.filter-dropdown {
  min-width: 120px;
  flex: 1;
  max-width: 200px;
}

.filter-label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 4px;
  color: var(--text-light);
}

/* --- View Toggle Buttons --- */
.view-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 15px;
  gap: 10px;
}

.view-toggle-btn {
  background-color: var(--card-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px 15px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
  width: auto;
}

.view-toggle-btn:hover {
  background-color: #3a3a3c;
}

.view-toggle-btn.active {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* --- Active Filters Tags --- */
.active-filter-tag {
  display: inline-block;
  background-color: rgba(10, 132, 255, 0.18);
  color: var(--primary);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  margin-right: 5px;
  margin-bottom: 5px;
  border: 1px solid rgba(10, 132, 255, 0.18);
}

.active-filter-tag button {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0 5px;
  font-size: 0.9rem;
  width: auto;
}

.active-filters {
  margin-bottom: 15px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.clear-filters {
  color: var(--primary);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  width: auto;
  margin-left: 10px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  .diary-controls {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .search-box {
    width: 100%;
  }

  .filter-section {
    flex-direction: column;
  }

  .filter-dropdown {
    max-width: none;
  }

  .button-group {
    flex-direction: column;
  }

  .entries-list {
    grid-template-columns: 1fr;
  }

  .pagination {
    flex-wrap: wrap;
  }

  .calendar-grid {
    gap: 2px;
  }

  .calendar-day {
    padding: 5px;
    font-size: 0.8rem;
  }
}

/* Keep actions in one row */
.calendar-actions{
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Small Apple-like chevron button */
.collapse-toggle{
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.collapse-toggle:hover{
  background: rgba(255,255,255,0.10);
}

.collapse-toggle .chev{
  display: inline-block;
  transition: transform 0.18s ease;
  font-size: 14px;
  line-height: 1;
}

/* Collapsible body animation */
.collapse-body{
  overflow: hidden;
  max-height: 2000px;         /* big enough to fit content */
  opacity: 1;
  transform: translateY(0);
  transition: max-height 0.28s ease, opacity 0.18s ease, transform 0.18s ease;
}

.collapse-body.closed{
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
}

/* Rotate chevron when closed */
#calendar-panel.collapsed .collapse-toggle .chev{
  transform: rotate(-90deg);
}

/* ===== Fix calendar header button misplacement (mobile) ===== */

/* Make the calendar header layout stable */
.calendar-nav-title{
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

/* Keep title readable and prevent weird wrapping */
#calendar-title{
  line-height: 1.1;
  word-break: keep-all;
}

/* Right side buttons container */
.calendar-actions{
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap; /* allow wrap but keep it neat */
}

/* Make each button keep its shape */
.calendar-actions button,
.calendar-actions .view-toggle-btn,
.calendar-actions .calendar-button,
.calendar-actions .collapse-toggle{
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Segmented control should never stretch full width */
.segmented-control{
  flex: 0 0 auto;
}

/* Mobile-specific tighter layout */
@media (max-width: 480px){
  .calendar-nav-title{
    grid-template-columns: 1fr; /* stack: title then actions */
    gap: 10px;
  }

  .calendar-actions{
    justify-content: flex-start;
  }

  /* Make controls consistent height */
  .calendar-button,
  .view-toggle-btn,
  .filters-toggle,
  .collapse-toggle{
    height: 38px;
    padding: 0 12px;
  }

  .collapse-toggle{
    width: 38px;
    padding: 0;
  }
}

/* ===== Fix collapse toggle (chevron) on mobile ===== */

.collapse-toggle{
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
  padding: 0 !important;

  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;

  border-radius: 12px !important;
}

.collapse-toggle .chev{
  font-size: 16px !important;
  line-height: 1 !important;
  transform-origin: center !important;
}

/* Make sure it never gets squeezed */
.calendar-actions{
  flex-wrap: nowrap !important;
  overflow-x: auto;            /* if too many buttons, scroll horizontally */
  -webkit-overflow-scrolling: touch;
  gap: 10px;
}

/* Hide scrollbar on mobile (optional) */
.calendar-actions::-webkit-scrollbar{
  display: none;
}