/* ═══════════════════════════════════════════════
   CSS VARIABLES — Dark theme
   ═══════════════════════════════════════════════ */
:root {
  --bg-primary:    #0d1117;
  --bg-secondary:  #161b22;
  --bg-tertiary:   #1c2128;
  --bg-hover:      #21262d;
  --border:        #30363d;
  --border-light:  #21262d;

  --text-primary:  #e6edf3;
  --text-secondary:#8b949e;
  --text-muted:    #484f58;

  --accent:        #1f6feb;
  --accent-hover:  #388bfd;

  --c-mine:        #1f6feb;
  --c-assigned:    #f0883e;
  --c-delegated:   #3fb950;
  --c-other:       #6e7681;

  --danger:        #f85149;
  --danger-hover:  #da3633;

  --today-border:  #388bfd;
  --today-bg:      rgba(31,111,235,.08);

  --hour-height:   64px;

  --radius:        8px;
  --radius-sm:     4px;
  --shadow:        0 4px 24px rgba(0,0,0,.5);
}

/* ═══════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

button { cursor: pointer; border: none; outline: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

.hidden { display: none !important; }
.page  { min-height: 100vh; }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 6px;
}
.empty-msg {
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 16px 0;
  text-align: center;
}

/* ═══════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-icon {
  background: transparent; color: var(--text-secondary);
  padding: 6px 10px; font-size: 1.2rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); line-height: 1;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* ═══════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

label { font-size: 0.82rem; color: var(--text-secondary); font-weight: 500; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="datetime-local"],
select, textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }
select option { background: var(--bg-tertiary); }

/* ═══════════════════════════════════════════════
   LOGIN PAGE — Butterfly full-page layout
   ═══════════════════════════════════════════════ */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  min-height: 100vh;
  padding: 32px 24px;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(156,39,176,.22) 0%, transparent 50%),
    radial-gradient(ellipse at 78% 70%, rgba(0,188,212,.16) 0%, transparent 48%),
    radial-gradient(ellipse at 75% 10%, rgba(224,64,251,.10) 0%, transparent 35%),
    linear-gradient(160deg, #080312 0%, #0d1117 55%, #060d1c 100%);
}

/* ── Left decorative panel ── */
.login-left {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Butterfly scene ── */
.butterfly-scene {
  position: relative;
  width: 300px;
  height: 265px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.butterfly-main {
  width: 280px;
  height: auto;
  filter:
    drop-shadow(0 0 28px rgba(156,39,176,.45))
    drop-shadow(0 0 55px rgba(0,188,212,.22));
  animation: bf-float 5.5s ease-in-out infinite;
  position: relative;
  z-index: 2;
}

@keyframes bf-float {
  0%,100% { transform: translateY(0)    rotate(-1deg);  }
  30%      { transform: translateY(-16px) rotate(1.2deg); }
  65%      { transform: translateY(-6px)  rotate(-.6deg); }
}

/* Mini butterflies */
.mini-bf {
  position: absolute;
  opacity: 0;
  animation: mini-drift 8s ease-in-out infinite;
}
.mini-bf:nth-child(1) { top:  8%; left:  4%; animation-delay: 0s;   animation-duration: 7.2s; }
.mini-bf:nth-child(2) { top: 72%; left:  3%; animation-delay: 2.8s; animation-duration: 9.0s; }
.mini-bf:nth-child(3) { top: 10%; right: 4%; animation-delay: 1.4s; animation-duration: 8.3s; }
.mini-bf:nth-child(4) { top: 78%; right: 3%; animation-delay: 4.1s; animation-duration: 6.8s; }

@keyframes mini-drift {
  0%   { opacity: 0;    transform: translateY(0)    rotate(0deg)  scale(1);    }
  18%  { opacity: .26; }
  50%  { opacity: .18;  transform: translateY(-22px) rotate(9deg)  scale(1.06); }
  82%  { opacity: .22; }
  100% { opacity: 0;    transform: translateY(-6px)  rotate(-5deg) scale(1);    }
}

/* ── Brand text ── */
.login-brand {
  text-align: center;
  margin-top: 20px;
}
.login-brand-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -.03em;
  background: linear-gradient(135deg, #c77dff 0%, #48cae4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}
.login-brand-sub {
  color: var(--text-secondary);
  font-size: .9rem;
  letter-spacing: .03em;
}

/* ── Right form panel ── */
.login-right {
  flex: 0 0 auto;
  width: 100%;
  max-width: 360px;
}

.login-card {
  background: rgba(22, 27, 34, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  width: 100%;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--text-primary);
}
.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: 26px;
  font-size: .88rem;
}

/* ── Responsive ── */
@media (max-width: 720px) {
  #login-page          { flex-direction: column; gap: 12px; padding: 28px 16px 36px; }
  .butterfly-scene     { width: 210px; height: 185px; }
  .butterfly-main      { width: 190px; }
  .login-brand-title   { font-size: 1.75rem; }
  .login-brand         { margin-top: 14px; }
  .mini-bf             { display: none; }
  .login-right         { max-width: 420px; }
  .login-card          { padding: 28px 22px; }
}

@media (max-width: 420px) {
  #login-page          { gap: 8px; padding: 20px 12px 28px; }
  .butterfly-scene     { width: 170px; height: 150px; }
  .butterfly-main      { width: 155px; }
  .login-brand-title   { font-size: 1.5rem; }
  .login-brand-sub     { font-size: .82rem; }
  .login-card          { padding: 22px 18px; }
}

/* ═══════════════════════════════════════════════
   APP HEADER
   ═══════════════════════════════════════════════ */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px;
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1rem; }
.app-logo { font-size: 1.3rem; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { color: var(--text-secondary); font-size: 0.85rem; }

.google-connected {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; color: var(--c-delegated);
  border: 1px solid rgba(63,185,80,.3); border-radius: var(--radius-sm);
  padding: 4px 8px; cursor: default;
}
.google-connected:hover { background: rgba(63,185,80,.08); }

.ms-connected {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; color: #60a5fa;
  border: 1px solid rgba(96,165,250,.3); border-radius: var(--radius-sm);
  padding: 4px 8px; cursor: default;
}
.ms-connected:hover { background: rgba(96,165,250,.08); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 20px;
  font-size: 0.9rem; color: var(--text-primary);
  box-shadow: var(--shadow); z-index: 400;
  animation: toast-in .25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ═══════════════════════════════════════════════
   LEGEND (shared)
   ═══════════════════════════════════════════════ */
.legend, .day-legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 8px 20px;
}
.day-legend {
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 0.78rem; color: var(--text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-dot.mine       { background: var(--c-mine); }
.legend-dot.assigned   { background: var(--c-assigned); }
.legend-dot.delegated  { background: var(--c-delegated); }
.legend-dot.other-user { background: var(--c-other); }

/* ═══════════════════════════════════════════════
   MONTH VIEW LAYOUT
   ═══════════════════════════════════════════════ */
.app-layout {
  display: grid; grid-template-columns: 1fr 280px;
  height: 100%; overflow: hidden;
}
@media (max-width: 860px) {
  .app-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: auto; overflow: visible; }
}

.calendar-section {
  display: flex; flex-direction: column;
  padding: 16px 20px; overflow-y: auto; border-right: 1px solid var(--border);
}

/* Month navigation */
.cal-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cal-title { font-size: 1.15rem; font-weight: 600; min-width: 180px; text-align: center; }

/* Month grid */
.cal-grid { flex: 1; display: flex; flex-direction: column; }
.cal-header-row { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; margin-bottom: 4px; }
.cal-dow {
  text-align: center; font-size: 0.75rem; font-weight: 600;
  color: var(--text-secondary); padding: 4px 0; text-transform: uppercase; letter-spacing: .04em;
}
.cal-body { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; flex: 1; }

.cal-day {
  background: var(--bg-secondary); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 4px; min-height: 90px;
  cursor: pointer; transition: background .12s, border-color .12s;
  overflow: hidden; display: flex; flex-direction: column;
}
.cal-day:hover { background: var(--bg-hover); border-color: var(--border); }
.cal-day.other-month { opacity: 0.35; }
.cal-day.today { background: var(--today-bg); border-color: var(--today-border); }

.day-number {
  font-size: 0.78rem; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 3px; padding: 1px 3px; align-self: flex-start;
  border-radius: 50%; min-width: 22px; text-align: center; line-height: 20px;
}
.today .day-number { background: var(--accent); color: #fff; }

.cal-event {
  font-size: 0.7rem; padding: 2px 5px; border-radius: 3px; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; font-weight: 500; transition: filter .1s; line-height: 1.4;
}
.cal-event:hover { filter: brightness(1.2); }
.cal-event.mine       { background: rgba(31,111,235,.25);  color: #79b8ff; border-left: 2px solid var(--c-mine); }
.cal-event.assigned   { background: rgba(240,136,62,.2);   color: #f0b072; border-left: 2px solid var(--c-assigned); }
.cal-event.delegated  { background: rgba(63,185,80,.2);    color: #7ee787; border-left: 2px solid var(--c-delegated); }
.cal-event.other-user { background: rgba(110,118,129,.12); color: var(--c-other); border-left: 2px solid var(--c-other); opacity: .75; }
.more-events { font-size: 0.65rem; color: var(--text-muted); padding: 1px 3px; }

/* ═══════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════ */
.sidebar { display: flex; flex-direction: column; background: var(--bg-secondary); overflow-y: auto; }
.sidebar-header {
  padding: 16px 16px 10px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-secondary); z-index: 1;
}
.sidebar-header h3 { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .06em; }
.upcoming-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.upcoming-item {
  background: var(--bg-tertiary); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 10px 12px;
  cursor: pointer; transition: background .12s; border-left: 3px solid transparent;
}
.upcoming-item:hover { background: var(--bg-hover); }
.upcoming-item.mine       { border-left-color: var(--c-mine); }
.upcoming-item.assigned   { border-left-color: var(--c-assigned); }
.upcoming-item.delegated  { border-left-color: var(--c-delegated); }
.upcoming-item.other-user { border-left-color: var(--c-other); opacity: .8; }
.upcoming-date  { font-size: 0.72rem; color: var(--text-secondary); margin-bottom: 3px; }
.upcoming-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming-meta  { font-size: 0.72rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ═══════════════════════════════════════════════
   DAY VIEW
   ═══════════════════════════════════════════════ */
#day-view {
  display: flex; flex-direction: column;
  height: 100%;
}

.day-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary); flex-shrink: 0;
}
.day-nav-center { display: flex; align-items: center; gap: 10px; }
.day-title { font-size: 1.1rem; font-weight: 600; min-width: 220px; text-align: center; }

.day-scroll-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
}

.day-grid-wrapper {
  display: grid;
  grid-template-columns: 52px 1fr;
  position: relative;
}

/* Time gutter — left column with hour labels */
.time-gutter { background: var(--bg-secondary); border-right: 1px solid var(--border); }

.gutter-slot {
  height: var(--hour-height);
  display: flex; align-items: flex-start;
  padding-top: 4px;
  border-bottom: 1px solid var(--border-light);
  justify-content: flex-end; padding-right: 8px;
}
.gutter-label {
  font-size: 0.7rem; color: var(--text-muted); font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Events column — right side */
.events-column {
  position: relative;
  background: var(--bg-primary);
}

.hour-row {
  height: var(--hour-height);
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background .1s;
}
.hour-row:hover { background: var(--bg-hover); }

/* Half-hour divider */
.hour-row::after {
  content: '';
  display: block;
  height: 1px;
  background: var(--border-light);
  opacity: 0.5;
  margin-top: calc(var(--hour-height) / 2 - 1px);
}

/* Current time indicator */
.now-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: var(--danger);
  z-index: 5;
  pointer-events: none;
}
.now-line::before {
  content: '';
  position: absolute;
  left: -4px; top: -4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

/* Day event blocks */
.day-event {
  position: absolute;
  border-radius: 4px;
  padding: 3px 6px;
  overflow: hidden;
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1.3;
  border-left: 3px solid transparent;
  transition: filter .1s, box-shadow .1s;
  z-index: 2;
  box-sizing: border-box;
}
.day-event:hover { filter: brightness(1.15); box-shadow: 0 2px 8px rgba(0,0,0,.4); z-index: 3; }

.day-event.mine {
  background: rgba(31,111,235,.3); border-left-color: var(--c-mine); color: #a8c8ff;
}
.day-event.assigned {
  background: rgba(240,136,62,.25); border-left-color: var(--c-assigned); color: #f0c080;
}
.day-event.delegated {
  background: rgba(63,185,80,.2); border-left-color: var(--c-delegated); color: #90e090;
}
.day-event.other-user {
  background: rgba(110,118,129,.13); border-left-color: var(--c-other); color: var(--c-other); opacity: .8;
}

.day-event-time {
  display: block; font-size: 0.68rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.day-event-title {
  display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.day-event-desc {
  display: block; font-size: 0.68rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px; backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close-btn { font-size: 1.4rem; border: none; padding: 4px 8px; }
#event-form { padding: 20px; }
.modal-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 4px; padding-top: 14px; border-top: 1px solid var(--border-light);
}
.modal-actions-right { display: flex; gap: 8px; }

.readonly-info {
  background: rgba(240,136,62,.1); border: 1px solid rgba(240,136,62,.3);
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: 0.82rem; color: var(--c-assigned); margin-bottom: 12px;
}

.delete-confirm-box {
  background: rgba(248,81,73,.08); border: 1px solid rgba(248,81,73,.35);
  border-radius: var(--radius-sm); padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; font-size: 0.875rem;
  color: var(--text-primary);
}
.delete-confirm-btns { display: flex; gap: 8px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════
   LOADING OVERLAY
   ═══════════════════════════════════════════════ */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(13,17,23,.6);
  display: flex; align-items: center; justify-content: center; z-index: 300;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ═══════════════════════════════════════════════
   APP PAGE LAYOUT — flex column for tab bar
   ═══════════════════════════════════════════════ */
#app-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#calendar-section {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Update month/day heights to fill remaining space */
.app-layout {
  height: 100%;
  overflow: hidden;
}

#day-view {
  height: 100%;
}

/* ═══════════════════════════════════════════════
   TAB BAR
   ═══════════════════════════════════════════════ */
.tab-bar {
  display: flex;
  gap: 2px;
  padding: 6px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.tab-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tab-btn.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}
.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 9px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--danger);
  color: #fff;
  line-height: 1;
}

/* ═══════════════════════════════════════════════
   TASK LIST VIEWS (deadline / undated)
   ═══════════════════════════════════════════════ */
.task-list-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  overflow: hidden;
}

.task-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-shrink: 0;
}
.task-list-header h2 { font-size: 1.1rem; font-weight: 600; }
.task-list-header-actions { display: flex; align-items: center; gap: 10px; }

.task-filter-select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
}
.task-filter-select:focus { border-color: var(--accent); }

.task-list {
  flex: 1;
  min-height: 0;
}

/* ── Kanban columns ──────────────────────────── */
.task-columns {
  display: grid;
  gap: 14px;
  height: 100%;
}
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }

.task-column {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.task-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.col-title { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.col-count {
  font-size: 0.75rem; font-weight: 600;
  background: var(--bg-tertiary); border-radius: 10px;
  padding: 1px 8px; color: var(--text-secondary);
}

.col-overdue .task-column-header { border-top: 3px solid var(--danger); }
.col-overdue .col-title          { color: var(--danger); }
.col-intime  .task-column-header { border-top: 3px solid var(--accent); }
.col-intime  .col-title          { color: var(--accent-hover); }
.col-done    .task-column-header { border-top: 3px solid var(--c-delegated); }
.col-done    .col-title          { color: var(--c-delegated); }

.task-column-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: background .12s;
}
.task-item:hover { background: var(--bg-hover); }
.task-item.mine       { border-left-color: var(--c-mine); }
.task-item.assigned   { border-left-color: var(--c-assigned); }
.task-item.delegated  { border-left-color: var(--c-delegated); }
.task-item.other-user { border-left-color: var(--c-other); opacity: .85; }

.task-item.status-done    { opacity: .65; }
.task-item.status-rejected { opacity: .65; }

.task-item-body {
  flex: 1;
  min-width: 0;
}
.task-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.task-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.task-att-badge {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════
   STATUS BADGES
   ═══════════════════════════════════════════════ */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.status-badge.status-pending  { background: rgba(139,148,158,.15); color: var(--text-secondary); }
.status-badge.status-done     { background: rgba(63,185,80,.15);   color: var(--c-delegated); }
.status-badge.status-rejected { background: rgba(248,81,73,.15);   color: var(--danger); }

/* ═══════════════════════════════════════════════
   MODAL — STATUS SECTION
   ═══════════════════════════════════════════════ */
#event-status-section {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
}
.event-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.status-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-status-done {
  background: rgba(63,185,80,.15);
  color: var(--c-delegated);
  border: 1px solid rgba(63,185,80,.3);
}
.btn-status-done:hover { background: rgba(63,185,80,.25); }
.btn-status-reject {
  background: rgba(248,81,73,.12);
  color: var(--danger);
  border: 1px solid rgba(248,81,73,.3);
}
.btn-status-reject:hover { background: rgba(248,81,73,.22); }

.rejection-comment-display {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--danger);
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
}
.rejection-label {
  font-weight: 600;
  margin-right: 6px;
}

/* ═══════════════════════════════════════════════
   MODAL — REJECTION INPUT
   ═══════════════════════════════════════════════ */
.rejection-input-area {
  background: rgba(248,81,73,.05);
  border: 1px solid rgba(248,81,73,.3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.rejection-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ═══════════════════════════════════════════════
   MODAL — TASK TYPE SELECTOR
   ═══════════════════════════════════════════════ */
.task-type-selector {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.task-type-option {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.task-type-option input[type="radio"] {
  display: none;
}
.task-type-option span {
  display: inline-block;
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  user-select: none;
}
.task-type-option input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.task-type-option input:disabled + span {
  opacity: .6;
  cursor: default;
}

/* ═══════════════════════════════════════════════
   MODAL — ATTACHMENTS
   ═══════════════════════════════════════════════ */
#event-attachments-section {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  overflow: hidden;
}
.attachments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-light);
}
.attachments-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.attachments-list {
  padding: 4px 0;
}
.attachment-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-light);
}
.attachment-row:last-child { border-bottom: none; }
.attachment-icon { font-size: 0.9rem; flex-shrink: 0; }
.attachment-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.attachment-name {
  font-size: 0.82rem;
  color: var(--accent-hover);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.attachment-name:hover { text-decoration: underline; }
.attachment-size {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.attachment-actions { flex-shrink: 0; }
.attachment-del-btn {
  padding: 2px 7px;
  font-size: 1rem;
  line-height: 1;
  border-color: transparent;
  color: var(--text-secondary);
}
.attachment-del-btn:hover { color: var(--danger); border-color: rgba(248,81,73,.3); }

/* ═══════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════ */
/* ═══════════════════════════════════════════════
   DONE CONFIRMATION DIALOG
   ═══════════════════════════════════════════════ */
.confirm-dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 350;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.confirm-dialog {
  background: var(--bg-secondary);
  border: 1px solid rgba(63,185,80,.35);
  border-radius: var(--radius);
  padding: 32px 28px 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
  text-align: center;
}
.confirm-dialog-icon {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(63,185,80,.15);
  border: 2px solid rgba(63,185,80,.4);
  color: var(--c-delegated);
  font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.confirm-dialog-msg {
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: 24px;
}
.confirm-dialog-btns {
  display: flex; gap: 10px; justify-content: center;
}
.confirm-dialog-btns .btn { min-width: 110px; }

/* ═══════════════════════════════════════════════
   ATTACHMENT LIGHTBOX
   ═══════════════════════════════════════════════ */
.attachment-lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 400;
}
.lightbox-close {
  position: absolute; top: 14px; right: 18px;
  background: none; border: none;
  color: #fff; font-size: 2.2rem; line-height: 1;
  cursor: pointer; opacity: .7;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-content {
  max-width: 92vw; max-height: 92vh;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-content img {
  max-width: 92vw; max-height: 92vh;
  object-fit: contain; border-radius: 4px;
}
.lightbox-content iframe {
  width: 82vw; height: 88vh;
  border: none; border-radius: 4px; background: #fff;
}
.attachment-preview-btn {
  background: none; border: none;
  font-size: 0.95rem; cursor: pointer;
  padding: 2px 5px; border-radius: var(--radius-sm);
  color: var(--text-secondary); line-height: 1;
}
.attachment-preview-btn:hover { color: var(--accent-hover); }

/* ═══════════════════════════════════════════════
   RESPONSIVE — TABLET (≤860px)
   ═══════════════════════════════════════════════ */
@media (max-width: 860px) {
  .app-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: auto; overflow: visible; }
  .sidebar { border-top: 1px solid var(--border); max-height: 240px; }
  .cal-day { min-height: 60px; }
  .day-title { min-width: 160px; font-size: 0.95rem; }
  .task-list-view { padding: 10px 12px; }
  .tab-bar { padding: 6px 8px; }
  .tab-btn { padding: 5px 10px; font-size: 0.78rem; }
  /* Kanban: collapse to single column, cap column body height */
  .cols-3 { grid-template-columns: 1fr; height: auto; }
  .cols-2 { grid-template-columns: 1fr; height: auto; }
  .task-columns { height: auto; }
  .task-column-body { max-height: 360px; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — LARGE PHONE (≤600px)
   ═══════════════════════════════════════════════ */
@media (max-width: 600px) {
  /* Task list header: stack title above actions */
  .task-list-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .task-list-header-actions { width: 100%; justify-content: space-between; }
  .task-filter-select { flex: 1; min-width: 0; }

  /* Calendar section */
  .calendar-section { padding: 10px 10px; }
  .cal-day { min-height: 54px; padding: 3px; }
  .cal-event { font-size: 0.65rem; padding: 1px 3px; }

  /* Day view nav */
  .day-title { min-width: 0; font-size: 0.9rem; }
  .day-nav { padding: 8px 10px; gap: 4px; flex-wrap: wrap; }
  .day-nav-center { gap: 6px; }

  /* Legend */
  .legend, .day-legend { gap: 8px; padding: 5px 10px; }
  .legend-item { font-size: 0.71rem; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — SMALL PHONE (≤480px)
   ═══════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Dynamic viewport height — avoids browser chrome overlap on iOS/Android */
  #app-page { height: 100dvh; }

  /* App header: compact */
  .app-header { padding: 0 10px; height: 46px; }
  .app-name { display: none; }
  .header-right { gap: 5px; }
  .header-user { max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; }
  /* Google/MS badges: show only icon */
  .google-connected .conn-label,
  .ms-connected .conn-label { display: none; }
  .google-connected, .ms-connected { padding: 4px 6px; }

  /* Tab bar */
  .tab-bar { padding: 4px 6px; gap: 2px; }
  .tab-btn { padding: 5px 8px; font-size: 0.73rem; }
  .tab-badge { min-width: 16px; height: 16px; font-size: 0.65rem; margin-left: 4px; }

  /* Calendar */
  .calendar-section { padding: 6px 8px; }
  .cal-nav { gap: 5px; margin-bottom: 6px; }
  .cal-title { font-size: 0.9rem; min-width: 110px; }
  .cal-day { min-height: 44px; padding: 2px; }
  .day-number { font-size: 0.68rem; min-width: 18px; line-height: 18px; }
  .cal-event { font-size: 0.6rem; padding: 1px 2px; }
  .more-events { font-size: 0.58rem; }
  .cal-dow { font-size: 0.65rem; }

  /* Day view */
  .day-nav { padding: 7px 8px; }
  .day-title { font-size: 0.85rem; }
  /* "← Miesiąc": hide the word, keep arrow */
  #back-to-month .btn-full-label { display: none; }
  /* "+ Wydarzenie" buttons: shorten */
  .btn-add-event-label { display: none; }

  /* Modal: full-width bottom sheet */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 94dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
  }

  /* Larger touch targets for small buttons */
  .attachment-del-btn,
  .attachment-preview-btn {
    min-width: 36px; min-height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 6px;
  }
  .btn-icon { min-width: 36px; min-height: 36px; }
  .lightbox-close { min-width: 44px; min-height: 44px; font-size: 2rem; top: 8px; right: 8px; }

  /* Sidebar */
  .sidebar { max-height: 200px; }

  /* Kanban */
  .task-column-body { max-height: 280px; }

  /* Legend: 2-column grid on tiny screens */
  .legend { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; padding: 5px 8px; }
  .day-legend { gap: 6px; padding: 5px 8px; }
}
