/* ═══════════════════════════════════════════════════════
   calendar.css — Calendar tab (P9.3)
   Category-aware event colors: work, personal, urgent, meeting, deadline
   ═══════════════════════════════════════════════════════ */

#tab-calendar { padding: 0; flex-direction: column; width: 100%; overflow-y: auto; }
#cal-wrap { flex: 1; width: 100%; min-width: 0; display: flex; flex-direction: column; }

/* Header — sticky inside #tab-calendar scroll container */
.cal-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px; position: sticky; top: 0; z-index: 10; background: var(--bg-card); }
.cal-nav, .cal-view-btns { display: flex; align-items: center; gap: 6px; }
.cal-label { font-size: 15px; font-weight: 600; color: var(--text); margin-left: 8px; }
.cal-btn { background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-muted); border-radius: 5px; padding: 4px 10px; font-size: 13px; cursor: pointer; transition: background .15s, color .15s; }
.cal-btn:hover { background: var(--bg-tertiary, #333); color: var(--text); }
.cal-btn-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.cal-subscribe-btn { border-color: #3B82F6; color: #3B82F6; }
.cal-today-btn { font-weight: 600; }

/* Week grid */
.cal-week-grid { overflow-x: auto; width: 100%; }
.cal-week-header, .cal-week-body { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); }
.cal-day-head { padding: 8px 10px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: center; }
.cal-day-name { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.cal-day-num { font-size: 18px; font-weight: 600; color: var(--text); margin-top: 2px; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; transition: background .2s, color .2s; }
.cal-today-col { background: var(--accent, #3B82F6)08; }
.cal-today-num { color: #fff !important; background: var(--accent, #3B82F6) !important; border-color: var(--accent, #3B82F6) !important; border-radius: 50%; }
.cal-day-col { min-height: 160px; padding: 6px 4px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }

/* Event cards */
.cal-event-card { border-radius: 4px; padding: 4px 7px; cursor: pointer; transition: opacity .15s; }
.cal-event-card:hover { opacity: .8; }
.cal-ev-title { font-size: 12px; font-weight: 500; color: var(--text); line-height: 1.3; }
.cal-ev-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; display: flex; gap: 6px; }
.cal-ev-proj { opacity: .7; }
.cal-ev-recurring { opacity: .65; }

/* ── Category colors for event cards ── */
.cal-event-card[data-cat="work"]     { background: rgba(59,130,246,0.18); border-left: 3px solid #3B82F6; }
.cal-event-card[data-cat="personal"] { background: rgba(16,185,129,0.18); border-left: 3px solid #10B981; }
.cal-event-card[data-cat="urgent"]   { background: rgba(239,68,68,0.18);  border-left: 3px solid #EF4444; }
.cal-event-card[data-cat="meeting"]  { background: rgba(245,158,11,0.18); border-left: 3px solid #F59E0B; }
.cal-event-card[data-cat="deadline"] { background: rgba(139,92,246,0.18); border-left: 3px solid #8B5CF6; }

/* Month grid */
.cal-month-grid { overflow-x: auto; width: 100%; }
.cal-month-heads, .cal-month-cells { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); min-width: 0; }
.cal-month-head { padding: 6px; text-align: center; font-size: 11px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); text-transform: uppercase; }
.cal-month-cell { min-height: 96px; padding: 4px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.cal-month-cell:hover { background: var(--bg-secondary); }
.cal-month-empty { background: var(--bg-secondary); opacity: .4; cursor: default; }
.cal-month-other { background: var(--bg-secondary); opacity: .55; }
.cal-today-cell { background: var(--accent, #3B82F6)0d; }
.cal-month-daynum { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 3px; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 6px; transition: background .2s, color .2s; }
.cal-today-cell .cal-month-daynum { color: #fff !important; background: var(--accent, #3B82F6) !important; border-color: var(--accent, #3B82F6) !important; border-radius: 50%; }
.cal-month-dots { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 3px; }
.cal-month-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.cal-month-dot[data-cat="work"]     { background: #3B82F6; }
.cal-month-dot[data-cat="personal"] { background: #10B981; }
.cal-month-dot[data-cat="urgent"]   { background: #EF4444; }
.cal-month-dot[data-cat="meeting"]  { background: #F59E0B; }
.cal-month-dot[data-cat="deadline"] { background: #8B5CF6; }
.cal-month-more { font-size: 10px; color: var(--text-muted); }
.cal-month-ev { font-size: 11px; padding: 1px 4px; border-radius: 3px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }

/* Weekend columns — Sat (col 6) & Sun (col 7) */
.cal-month-heads > .cal-month-head:nth-child(n+6) { color: var(--accent); font-weight: 700; background: rgba(59,130,246,0.06); }
.cal-month-cells > .cal-month-cell:nth-child(7n+6),
.cal-month-cells > .cal-month-cell:nth-child(7n) { background: rgba(59,130,246,0.06) !important; }
.cal-month-cells > .cal-month-cell.cal-month-other:nth-child(7n+6),
.cal-month-cells > .cal-month-cell.cal-month-other:nth-child(7n) { background: rgba(59,130,246,0.04) !important; }

/* Week view weekend columns */
.cal-weekend-head { background: rgba(59,130,246,0.08) !important; }
.cal-weekend-head .cal-day-name { color: var(--accent) !important; font-weight: 700; }
.cal-weekend-col { background: rgba(59,130,246,0.06) !important; }

/* Quick add slot */
.cal-quick-add { padding: 12px 16px; border-top: 1px solid var(--border); }
.cal-add-slot { margin-top: 6px; text-align: center; font-size: 18px; color: var(--text-muted); cursor: pointer; border-radius: 6px; padding: 2px 0; opacity: 0; transition: opacity 0.15s; }
.cal-day-col:hover .cal-add-slot { opacity: 1; }
.cal-add-slot:hover { background: var(--bg-hover, rgba(255,255,255,0.05)); color: var(--accent); }

/* Quick Add Modal */
.qa-container { position: fixed; inset: 0; z-index: 9000; display: flex; align-items: center; justify-content: center; }
.qa-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.qa-modal { position: relative; z-index: 1; background: var(--bg-card); border-radius: 12px; padding: 0; width: min(420px, 95vw); box-shadow: 0 20px 60px rgba(0,0,0,0.4); overflow: hidden; }
.qa-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.9rem; }
.qa-close { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.qa-close:hover { background: var(--bg-hover, rgba(255,255,255,0.05)); }
.qa-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.qa-row { display: flex; gap: 8px; }
.qa-input { width: 100%; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.9rem; box-sizing: border-box; }
.qa-input:focus { outline: none; border-color: var(--accent); }
.qa-time { width: 120px; flex-shrink: 0; }
.qa-select { flex: 1; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.85rem; }
.qa-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }
.qa-desc { resize: vertical; min-height: 56px; font-family: inherit; }

/* Event detail modal */
.det-title-input { flex: 1; background: none; border: none; color: var(--text); font-size: 1rem; font-weight: 600; padding: 0 4px; min-width: 0; }
.det-title-input:focus { outline: none; border-bottom: 1px solid var(--accent); }
.det-meta { display: flex; gap: 16px; font-size: 0.82rem; color: var(--text-muted); flex-wrap: wrap; padding-bottom: 4px; }
.det-label { font-size: 0.78rem; color: var(--text-muted); min-width: 80px; align-self: center; }
.det-desc { font-size: 0.82rem; color: var(--text-muted); padding: 8px; background: var(--bg); border-radius: 6px; }
.det-footer { justify-content: space-between !important; }

/* Day View */
.cal-day-view { display: flex; flex-direction: column; width: 100%; flex: 1; }
.cal-day-grid { width: 100%; border-bottom: 1px solid var(--border); }
.cal-day-row { display: flex; align-items: stretch; width: 100%; border-bottom: 1px solid var(--border); min-height: 52px; }
.cal-day-row-now { background: var(--accent, #3B82F6)0a; }
.cal-day-hour { width: 56px; flex-shrink: 0; padding: 6px 8px; font-size: 11px; color: var(--text-muted); border-right: 1px solid var(--border); line-height: 1.2; }
.cal-day-slot { flex: 1; min-width: 0; padding: 4px 8px; display: flex; flex-direction: column; gap: 3px; }
.cal-day-slot .cal-event-card { width: 100%; box-sizing: border-box; }
.cal-day-slot .cal-add-slot { opacity: 0; }
.cal-day-row:hover .cal-add-slot { opacity: 1; }
.cal-day-allday { display: flex; align-items: flex-start; border-bottom: 2px solid var(--border); background: var(--bg-secondary, var(--bg-card)); }

/* Subscribe panel */
.cal-subscribe-panel { margin: 0 16px 12px; padding: 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; border-top: none; border-top-left-radius: 0; border-top-right-radius: 0; }
.cal-sub-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.cal-sub-row { display: flex; gap: 6px; margin-bottom: 8px; }
.cal-sub-input { flex: 1; padding: 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; font-family: monospace; }
.cal-sub-copy { padding: 6px 12px; background: var(--accent); color: #fff; border-color: var(--accent); border-radius: 6px; font-size: 12px; cursor: pointer; }
.cal-sub-links { display: flex; gap: 12px; font-size: 12px; }
.cal-sub-links a { color: var(--accent); text-decoration: none; }
.cal-sub-links a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 700px) {
  .cal-header { flex-direction: column; align-items: flex-start; gap: 8px; padding: 8px 12px; }
  .cal-nav, .cal-view-btns { flex-wrap: wrap; }
  .cal-label { font-size: 13px; }
  .cal-week-header, .cal-week-body { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal-week-grid { overflow-x: hidden; }
  .cal-day-num { font-size: 12px; width: 24px; height: 24px; border-radius: 6px; }
  .cal-day-name { font-size: 8px; letter-spacing: 0; }
  .cal-day-head { padding: 4px 1px 3px; min-width: 0; overflow: hidden; }
  .cal-day-col { min-height: 80px; padding: 2px 1px; gap: 2px; }
  .cal-event-card { padding: 2px 3px; border-left-width: 2px; }
  .cal-ev-title { font-size: 9px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cal-ev-meta { display: none; }
  .cal-month-cell { min-height: 52px; padding: 2px 3px; }
  .cal-month-ev { display: none; }
  .cal-month-daynum { font-size: 12px; width: 22px; height: 22px; }
  .cal-month-head { font-size: 10px; padding: 4px 2px; }
  .cal-day-hour { width: 44px; font-size: 10px; padding: 4px 4px; }
  .qa-modal { width: 100vw; border-radius: 16px 16px 0 0; margin-top: auto; }
  .qa-container { align-items: flex-end; }
  .qa-row { flex-direction: column; gap: 6px; }
  .qa-time { width: 100%; }
  .cal-sub-links { flex-direction: column; gap: 6px; }
}