/* ═══════════════════════════════════════════════
   KEWEKE — Time Calendar (Toggl-style)
   ═══════════════════════════════════════════════ */

/* Sub-tab switcher */
.tcal-sub-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  min-height: 46px;
}
.tcal-stab-group { display: flex; gap: 4px; }
.tcal-stab {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: none; background: transparent; cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  color: var(--c-text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .12s, border-color .12s;
}
.tcal-stab:hover { color: var(--c-text); }
.tcal-stab.active { color: var(--c-accent); border-bottom-color: var(--c-accent); font-weight: 600; }

/* ── Calendar shell ── */
.tcal {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0; overflow: hidden;
  background: var(--c-bg);
}

/* Toolbar */
.tcal-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0; background: var(--c-surface);
}
.tcal-nav { display: flex; align-items: center; gap: 4px; }
.tcal-nav-btn {
  width: 28px; height: 28px; border: 1px solid var(--c-border);
  background: var(--c-surface); border-radius: var(--radius);
  cursor: pointer; color: var(--c-text2); display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: all var(--tr);
}
.tcal-nav-btn:hover { background: var(--c-surface2); color: var(--c-text); }
.tcal-today-btn {
  padding: 4px 10px; height: 28px; border: 1px solid var(--c-border);
  background: var(--c-surface); border-radius: var(--radius);
  cursor: pointer; font-size: 12px; font-weight: 500; color: var(--c-text2);
  font-family: var(--font); transition: all var(--tr);
}
.tcal-today-btn:hover { background: var(--c-surface2); color: var(--c-text); }
.tcal-range { font-size: 13px; font-weight: 600; color: var(--c-text); white-space: nowrap; }
.tcal-modes { display: flex; background: var(--c-surface2); border-radius: var(--radius); padding: 2px; gap: 1px; }
.tcal-mode-btn {
  padding: 4px 10px; border: none; border-radius: 5px; background: transparent;
  font-size: 12px; font-weight: 500; color: var(--c-text2); cursor: pointer;
  font-family: var(--font); transition: all .12s;
}
.tcal-mode-btn.active { background: var(--c-surface); color: var(--c-text); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.tcal-total { font-size: 12px; color: var(--c-text2); margin-left: auto; white-space: nowrap; }
.tcal-total strong { color: var(--c-text); }
.tcal-user-sel { height: 28px; font-size: 12px; padding: 0 8px; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); color: var(--c-text); }

/* Day header (sticky) */
.tcal-dayhead {
  display: flex; flex-shrink: 0;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  position: sticky; top: 0; z-index: 10;
  /* Reserva el mismo hueco de scrollbar que .tcal-scroll para que las columnas
     queden alineadas bajo sus cabeceras (con scrollbars clásicas). */
  overflow: hidden; scrollbar-gutter: stable;
}
.tcal-axis-gutter { width: 52px; flex-shrink: 0; border-right: 1px solid var(--c-border); }
.tcal-day-headers { display: flex; flex: 1; }
.tcal-day-hd {
  flex: 1; text-align: center; padding: 8px 4px;
  border-right: 1px solid var(--c-border);
  cursor: default;
}
.tcal-day-hd:last-child { border-right: none; }
.tcal-day-hd .dow { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-text3); }
.tcal-day-hd .dom { display: block; font-size: 18px; font-weight: 700; color: var(--c-text); line-height: 1.2; margin-top: 2px; }
.tcal-day-hd.today .dom { background: var(--c-accent); color: white; border-radius: 50%; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; margin: 2px auto 0; font-size: 15px; }

/* Scrollable grid */
.tcal-scroll {
  flex: 1; min-height: 0;        /* REQUIRED: allow flex item to shrink below content */
  overflow-y: auto; overflow-x: hidden;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}
.tcal-grid {
  display: flex;
  position: relative;
}

/* Time axis */
.tcal-axis {
  width: 52px; flex-shrink: 0;
  border-right: 1px solid var(--c-border);
  position: relative;
}
.tcal-axis-label {
  position: absolute; right: 8px;
  font-size: 10px; color: var(--c-text3);
  transform: translateY(-50%);
  pointer-events: none; white-space: nowrap;
}

/* Day columns */
.tcal-cols { display: flex; flex: 1; position: relative; }
.tcal-col {
  flex: 1; position: relative;
  border-right: 1px solid var(--c-border);
  box-sizing: border-box;
  touch-action: none;
  cursor: crosshair;
}
.tcal-col:last-child { border-right: none; }
.tcal-col.today { background: rgba(99,102,241,0.02); }
.tcal-col::after {
  content: '+';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  color: var(--c-border2);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.tcal-col:hover::after { opacity: 1; }

/* Hour gridlines (generated as absolute divs) */
.tcal-gridline {
  position: absolute; left: 0; right: 0;
  border-top: 1px solid var(--c-border);
  pointer-events: none;
}
.tcal-gridline.half {
  border-top-style: dashed;
  border-top-color: var(--c-border);
  opacity: 0.5;
}

/* Now indicator */
.tcal-now-line {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 2px solid #EF4444;
  z-index: 5; pointer-events: none;
}
.tcal-now-line::before {
  content: ''; position: absolute;
  left: -4px; top: -5px;
  width: 8px; height: 8px;
  border-radius: 50%; background: #EF4444;
}

/* Time blocks */
.tcal-block {
  position: absolute;
  left: 3px; right: 3px;
  border-radius: 5px;
  padding: 3px 6px;
  color: white;
  font-size: 11px;
  cursor: grab;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  z-index: 2;
  box-sizing: border-box;
  transition: box-shadow .1s;
}
.tcal-block:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.25); z-index: 3; }
.tcal-block.dragging { cursor: grabbing; opacity: .85; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.tcal-block.ghost {
  opacity: .5; pointer-events: none;
  border: 2px dashed rgba(255,255,255,.6);
  z-index: 15;
}
.tcal-block-title {
  font-weight: 600; font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tcal-block-time {
  font-size: 10px; opacity: .85; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tcal-resize {
  position: absolute; left: 0; right: 0; height: 12px;
  cursor: ns-resize; z-index: 4;
}
.tcal-resize-top { top: 0; }
.tcal-resize-bot { bottom: 0; }
.tcal-resize::after {
  content: ''; display: block;
  width: 20px; height: 2px; border-radius: 1px;
  background: rgba(255,255,255,.6);
  margin: 3px auto 0;
}
.tcal-resize-top::after { margin-top: 2px; }

/* Live timer block */
.tcal-live-block {
  opacity: 0.88;
  border: 2px solid rgba(255,255,255,0.5);
  cursor: default !important;
}
.tcal-live-dot {
  position: absolute;
  top: 5px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: white;
  animation: tcalPulse 1.2s ease-in-out infinite;
}
@keyframes tcalPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* Create ghost (drag on empty) */
.tcal-create-ghost {
  position: absolute; left: 3px; right: 3px;
  background: var(--c-accent);
  opacity: .4; border-radius: 5px;
  pointer-events: none; z-index: 15;
  border: 2px dashed var(--c-accent);
}

/* ── Popup ── */
.tcal-popup {
  position: fixed;
  background: var(--c-surface);
  border: 1px solid var(--c-border2);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 320px;
  z-index: 500;
  padding: 16px;
  animation: tcalPopIn .12s ease;
}
@keyframes tcalPopIn {
  from { opacity:0; transform:scale(.96) translateY(-4px); }
  to   { opacity:1; transform:scale(1) translateY(0); }
}
.tcal-popup-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.tcal-popup-title { font-size: 13px; font-weight: 600; color: var(--c-text); }
.tcal-popup-close {
  width: 24px; height: 24px; border: none; background: transparent;
  cursor: pointer; color: var(--c-text3); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.tcal-popup-close:hover { background: var(--c-surface2); color: var(--c-text); }
.tcal-pop-row { margin-bottom: 10px; }
.tcal-pop-label { font-size: 11px; font-weight: 600; color: var(--c-text3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.tcal-pop-desc {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font); background: var(--c-surface);
  color: var(--c-text); box-sizing: border-box;
}
.tcal-pop-desc:focus { outline: none; border-color: var(--c-accent); }
.tcal-pop-project {
  width: 100%; padding: 7px 26px 7px 10px;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font); background: var(--c-surface);
  color: var(--c-text); box-sizing: border-box;
}
.tcal-pop-times {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.tcal-pop-time-input {
  width: 80px; padding: 6px 8px;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font); background: var(--c-surface); color: var(--c-text);
}
.tcal-pop-time-input:focus { outline: none; border-color: var(--c-accent); }
.tcal-pop-date-input {
  flex: 1; min-width: 110px; padding: 6px 8px;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: 12px; font-family: var(--font); background: var(--c-surface); color: var(--c-text);
}
.tcal-pop-sep { color: var(--c-text3); font-size: 12px; }
.tcal-pop-dur { font-size: 12px; color: var(--c-text3); white-space: nowrap; }
.tcal-pop-actions {
  display: flex; align-items: center; gap: 8px;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--c-border);
}
.tcal-pop-del {
  padding: 6px 12px; border-radius: var(--radius); border: none; cursor: pointer;
  font-size: 12px; font-weight: 500; font-family: var(--font);
  color: var(--c-red); background: transparent;
  transition: background var(--tr);
}
.tcal-pop-del:hover { background: #FEF2F2; }
.tcal-pop-cancel {
  padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--c-border);
  cursor: pointer; font-size: 12px; font-weight: 500; font-family: var(--font);
  color: var(--c-text2); background: var(--c-surface);
  transition: background var(--tr); margin-left: auto;
}
.tcal-pop-cancel:hover { background: var(--c-surface2); }
.tcal-pop-save {
  padding: 6px 16px; border-radius: var(--radius); border: none;
  cursor: pointer; font-size: 12px; font-weight: 600; font-family: var(--font);
  color: white; background: var(--c-accent);
  transition: opacity var(--tr);
}
.tcal-pop-save:hover { opacity: .88; }

/* Mobile: popup becomes bottom sheet */
@media (max-width: 768px) {
  .tcal-popup {
    position: fixed !important;
    left: 0 !important; right: 0 !important; bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .tcal-sub-tabs { padding: 8px 12px 0; }
  .tcal-toolbar { padding: 8px 10px; gap: 8px; }
  .tcal-resize { height: 14px; }
}
