/* ── Timetracking Module Styles ── */

@property --tt-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

@keyframes ttBorderSpin {
  to { --tt-angle: 360deg; }
}

#viewTimeTracking {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* ── Sub-Tab Navigation ── */
.ttSubTabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  flex-wrap: wrap;
  background: rgba(255,255,255,.03);
  border-radius: 12px;
}

.ttTab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  color: var(--mut);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all .2s ease;
  white-space: nowrap;
}
.ttTab:hover {
  background: rgba(59,130,246,.1);
  color: var(--txt);
  border-color: rgba(59,130,246,.3);
  box-shadow: 0 0 10px rgba(59,130,246,.2);
}
html[data-theme=light] .ttTab {
  border-color: rgba(0,0,0,.08);
  background: rgba(0,0,0,.03);
}
html[data-theme=light] .ttTab:hover {
  background: rgba(59,130,246,.08);
  border-color: rgba(59,130,246,.25);
  box-shadow: 0 0 8px rgba(59,130,246,.15);
}
.ttTab.active {
  background: rgba(59,130,246,.15);
  color: #3b82f6;
  border-color: transparent;
  box-shadow: 0 0 14px rgba(59,130,246,.3), inset 0 0 10px rgba(59,130,246,.06);
}
.ttTab.active::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 9px;
  padding: 1px;
  background: conic-gradient(
    from var(--tt-angle),
    transparent 0%,
    rgba(59,130,246,.6) 10%,
    rgba(147,197,253,.8) 15%,
    rgba(59,130,246,.6) 20%,
    transparent 30%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  animation: ttBorderSpin 3s linear infinite;
  pointer-events: none;
}
html[data-theme=light] .ttTab.active {
  background: rgba(59,130,246,.1);
  border-color: transparent;
  box-shadow: 0 0 10px rgba(59,130,246,.2);
}
html[data-theme=light] .ttTab.active::before {
  background: conic-gradient(
    from var(--tt-angle),
    transparent 0%,
    rgba(59,130,246,.4) 10%,
    rgba(59,130,246,.6) 15%,
    rgba(59,130,246,.4) 20%,
    transparent 30%
  );
}
@media (prefers-reduced-motion: reduce) {
  .ttTab.active::before { animation: none; }
}

/* ── Panels ── */
.ttPanel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Dashboard Head ── */
.ttDashHead {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.ttMonthPicker {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ttMonthPicker label {
  font-size: 12px;
  color: var(--mut);
  font-weight: 600;
  letter-spacing: .3px;
}
.ttMonthPicker select {
  min-width: 200px;
}

/* ── Dashboard Client Cards ── */
.ttDashCard {
  background:
    radial-gradient(900px 420px at 10% 0%, rgba(59,130,246,.04), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02) 20%, rgba(0,0,0,.02) 100%),
    var(--card);
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 12px 26px -26px rgba(0,0,0,.80);
}
html[data-theme=light] .ttDashCard {
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.ttDashCardHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.ttDashCardTitle {
  font-size: 16px;
  font-weight: 700;
  color: var(--txt);
}
.ttDashCardSub {
  font-size: 12px;
  color: var(--mut);
  margin-top: 2px;
}
.ttPackageBadge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.ttPackageBadge.retainer {
  background: rgba(59,130,246,.15);
  color: #3b82f6;
  border: 1px solid rgba(59,130,246,.25);
}
.ttPackageBadge.tm {
  background: rgba(168,85,247,.15);
  color: #a855f7;
  border: 1px solid rgba(168,85,247,.25);
}

/* ── Progress Bar ── */
.ttProgressWrap {
  margin-bottom: 16px;
}
.ttProgressLabel {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--mut);
  margin-bottom: 6px;
}
.ttProgressBar {
  height: 10px;
  background: rgba(255,255,255,.06);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
html[data-theme=light] .ttProgressBar {
  background: rgba(0,0,0,.06);
}
.ttProgressFill {
  height: 100%;
  border-radius: 6px;
  transition: width .4s ease;
  min-width: 2px;
}
.ttProgressFill.green {
  background: linear-gradient(90deg, #22c55e, #4ade80);
}
.ttProgressFill.yellow {
  background: linear-gradient(90deg, #eab308, #facc15);
}
.ttProgressFill.red {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

/* ── Stats Grid ── */
.ttStatsGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.ttStatTile {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
html[data-theme=light] .ttStatTile {
  background: rgba(0,0,0,.02);
  border-color: rgba(0,0,0,.06);
}
.ttStatVal {
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--txt);
}
.ttStatLabel {
  font-size: 11px;
  color: var(--mut);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

/* ── Category Chips ── */
.ttCatChips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 16px;
}
.ttCatChip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Dashboard Card Footer ── */
.ttDashCardFoot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  border-top: 1px solid var(--bd);
  margin-top: 8px;
}
.ttDashTotal {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--txt);
}
.ttDashTotalLabel {
  font-size: 11px;
  color: var(--mut);
}
.ttDashOvertime {
  font-size: 12px;
  color: #ef4444;
  margin: 4px 0 6px;
  font-variant-numeric: tabular-nums;
}
.ttDashCardActions {
  display: flex;
  gap: 8px;
}

/* ── Journal Filters ── */
.ttJournalFilters {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr 1fr 1fr;
  gap: 12px;
  align-items: end;
}
@media (max-width: 1200px) {
  .ttJournalFilters {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 600px) {
  .ttJournalFilters {
    grid-template-columns: 1fr;
  }
}

/* ── Journal Table ── */
.ttTableWrap {
  overflow-x: auto;
}
.ttTable {
  width: 100%;
  font-variant-numeric: tabular-nums;
}
.ttTable th.sortable {
  cursor: pointer;
  user-select: none;
}
.ttTable th.sortable:hover {
  color: #3b82f6;
}
.ttTable th.num,
.ttTable td.num {
  text-align: right;
}
.ttSumRow td {
  border-top: 2px solid var(--bd);
  font-weight: 700;
  padding-top: 14px;
  padding-bottom: 14px;
}
.ttTable .ttSumRow td:first-child {
  padding-left: 24px;
}

/* Hide rate/amount columns for retainer clients */
.ttHideRates .ttColRate,
.ttHideRates .ttColAmount {
  display: none;
}
.ttOvertimeRow td {
  border-top: none;
  font-weight: 600;
  color: #ef4444;
}

/* ── Reports ── */
.ttReportKpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 12px;
}
@media (max-width: 1200px) {
  .ttReportKpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .ttReportKpis { grid-template-columns: 1fr; }
}
.ttReportKpi {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ttRkLabel {
  font-size: 12px;
  color: var(--mut);
  font-weight: 600;
  letter-spacing: .3px;
}
.ttRkValue {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ttRkDelta {
  font-size: 12px;
  font-weight: 600;
}
.ttRkDelta.up { color: #22c55e; }
.ttRkDelta.down { color: #ef4444; }
.ttRkDelta.neutral { color: var(--mut); }

/* Category bar chart */
.ttCatChart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ttCatBarRow {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ttCatBarLabel {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 600px) {
  .ttCatBarLabel { width: 120px; min-width: 120px; max-width: 120px; font-size: 12px; }
}
.ttCatBarTrack {
  flex: 1;
  height: 28px;
  background: rgba(255,255,255,.06);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.ttCatBarFill {
  height: 100%;
  border-radius: 6px;
  min-width: 2px;
  transition: width .3s ease;
}
.ttCatBarValue {
  font-size: 12px;
  font-weight: 600;
  min-width: 80px;
  font-variant-numeric: tabular-nums;
  color: var(--mut);
}

/* Report client table */
.ttReportTable {
  width: 100%;
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}
.ttReportTable th.num,
.ttReportTable td.num {
  text-align: right;
}
.ttReportTable .ttSumRow td {
  padding: 14px 12px;
}
.ttRptUtilBar {
  display: inline-block;
  height: 8px;
  border-radius: 4px;
  min-width: 2px;
  vertical-align: middle;
  margin-right: 6px;
}
.ttRptUtilText {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ── Client Filters ── */
.ttClientsFilters {
  display: flex;
  gap: 12px;
}
.ttClientsFilters input { flex: 1; }
.ttClientsFilters select { width: 140px; }

/* ── Rich Client Cards ── */
.ttClientCardRich {
  background:
    radial-gradient(600px 300px at 5% 0%, rgba(59,130,246,.03), transparent 60%),
    var(--card);
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 12px;
  transition: border-color .15s;
}
.ttClientCardRich:hover {
  border-color: rgba(59,130,246,.3);
}
.ttClientCardRich.inactive {
  opacity: .5;
}
.ttCCHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.ttCCTitle {
  font-size: 16px;
  font-weight: 700;
  color: var(--txt);
}
.ttCCRow {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--mut);
  margin-bottom: 6px;
}
.ttCCItem {
  white-space: nowrap;
}
.ttStatusBadge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 4px;
  text-transform: uppercase;
}
.ttStatusBadge.active {
  background: rgba(34,197,94,.15);
  color: #22c55e;
}
.ttStatusBadge.inactive {
  background: rgba(239,68,68,.15);
  color: #ef4444;
}
.ttCCProgress {
  margin: 8px 0 4px;
}
.ttCCProgressLabel {
  font-size: 11px;
  color: var(--mut);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.ttCCActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* ── Modals ── */
.ttDlg {
  width: 560px;
  max-width: 96vw;
}
.ttDlgWide {
  width: 640px;
}
.ttDlg .dlgFt {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--bd);
}
.ttDlg .dlgFt .btn {
  box-sizing: border-box;
}
.ttFormGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.ttFormGrid .field.full {
  grid-column: 1 / -1;
}
.ttFormGrid .field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--mut);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.ttHoursInput {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.ttHoursInput input {
  flex: 1;
}
.ttFullDayToggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.ttCharCount {
  font-size: 11px;
  color: var(--mut);
  text-align: right;
  display: block;
  margin-top: 2px;
}
.ttRetainerFields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ── Disabled Save Button ── */
.ttDlg .btn.p:disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Empty State ── */
.ttEmpty {
  text-align: center;
  padding: 40px 20px;
}
.ttEmpty .hint {
  color: var(--mut);
  font-size: 14px;
}

/* ── Journal action buttons right-aligned ── */
.ttTable .act {
  justify-content: flex-end;
}

/* ── Description Cell ── */
.ttDescCell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* ── Half-Month Hint ── */
.ttHalfHint {
  color: #f59e0b;
  font-style: italic;
}

/* ── Inline Edit ── */
.ttTable td[contenteditable=true] {
  outline: 2px solid rgba(59,130,246,.4);
  border-radius: 4px;
  padding: 4px 6px;
  background: rgba(59,130,246,.05);
}

/* ── Touch-Targets (Apple HIG: min 44px) ── */
.ttTab {
  min-height: 44px;
  padding: 10px 16px;
}
.ttFormGrid .ctl {
  min-height: 44px;
}
.ttDashCardActions .btn {
  min-height: 44px;
  min-width: 44px;
}
.ttDlg .dlgFt .btn {
  min-height: 44px;
  padding-left: 20px;
  padding-right: 20px;
}
.ttTable .act .btn {
  min-height: 36px;
  min-width: 36px;
}

/* ── Responsive: iPad Pro / iPad (max-width: 1024px) ── */
@media (max-width: 1024px) {
  .ttJournalFilters {
    grid-template-columns: 1fr 1fr;
  }
  .ttJournalFilters > input[type="search"] {
    grid-column: 1 / -1;
  }
  .ttCatBarLabel {
    width: 180px;
    min-width: 180px;
    max-width: 180px;
  }
  .ttStatsGrid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}

/* ── Responsive: iPad Mini (max-width: 768px) ── */
@media (max-width: 768px) {
  .ttSubTabs {
    gap: 2px;
  }
  .ttTab {
    flex: 1;
    justify-content: center;
    padding: 10px 8px;
    font-size: 12px;
  }
  .ttDashHead {
    flex-direction: column;
    align-items: stretch;
  }
  .ttMonthPicker select {
    min-width: unset;
    width: 100%;
  }
  .ttClientsFilters {
    flex-direction: column;
  }
  .ttClientsFilters select {
    width: 100%;
  }
  .ttFormGrid {
    grid-template-columns: 1fr;
  }
  .ttRetainerFields {
    grid-template-columns: 1fr;
  }
  .ttDashCardHead {
    flex-direction: column;
  }
  .ttDashCardFoot {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .ttDashCardActions {
    width: 100%;
    justify-content: flex-end;
  }
  .ttStatsGrid {
    grid-template-columns: 1fr 1fr;
  }
  .ttCCHead {
    flex-wrap: wrap;
  }
  .ttCatBarLabel {
    width: 140px;
    min-width: 140px;
    max-width: 140px;
    font-size: 12px;
  }
  .ttRkValue {
    font-size: 22px;
  }
}

/* ── Responsive: iPhone (max-width: 480px) ── */
@media (max-width: 480px) {
  .ttSubTabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px;
    padding: 6px 2px;
  }
  .ttSubTabs::-webkit-scrollbar {
    display: none;
  }
  .ttTab {
    flex: 0 0 auto;
    font-size: 12px;
    padding: 8px 12px;
    gap: 4px;
  }
  .ttTab svg {
    width: 14px;
    height: 14px;
  }
  .ttDashCard {
    padding: 14px;
    border-radius: 10px;
  }
  .ttDashCardTitle {
    font-size: 14px;
  }
  .ttDashCardSub {
    font-size: 11px;
  }
  .ttStatTile {
    padding: 8px;
    border-radius: 8px;
  }
  .ttStatVal {
    font-size: 16px;
  }
  .ttStatLabel {
    font-size: 10px;
  }
  .ttRkValue {
    font-size: 20px;
  }
  .ttReportKpi {
    padding: 14px 16px;
  }
  .ttDashTotal {
    font-size: 16px;
  }
  .ttDashTotalLabel {
    font-size: 10px;
  }
  .ttDescCell {
    max-width: 140px;
  }
  /* Hide less-critical table columns on phone */
  .ttTable th:nth-child(3),
  .ttTable td:nth-child(3) {
    display: none;
  }
  .ttTable .ttColRate {
    display: none;
  }
  .ttReportTable th:nth-child(2),
  .ttReportTable td:nth-child(2),
  .ttReportTable th:nth-child(4),
  .ttReportTable td:nth-child(4) {
    display: none;
  }
  .ttCatBarLabel {
    width: 90px;
    min-width: 90px;
    max-width: 90px;
    font-size: 11px;
  }
  .ttCatBarValue {
    min-width: 60px;
    font-size: 11px;
  }
  .ttCatBarTrack {
    height: 22px;
  }
  .ttClientCardRich {
    padding: 14px;
    border-radius: 10px;
  }
  .ttCCTitle {
    font-size: 14px;
  }
  .ttCCRow {
    gap: 8px;
    font-size: 11px;
  }
  .ttEmpty {
    padding: 24px 14px;
  }
  .ttJournalFilters {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  #viewTimeTracking .kpis {
    grid-template-columns: 1fr 1fr;
  }
  .ttDlg {
    max-width: 100vw;
    border-radius: 12px 12px 0 0;
  }
  .ttDlgWide {
    width: 100vw;
  }
}

/* ── Responsive: iPhone SE / Mini (max-width: 374px) ── */
@media (max-width: 374px) {
  .ttStatsGrid {
    grid-template-columns: 1fr;
  }
  .ttFormGrid {
    gap: 10px;
  }
  .ttDlg {
    padding: 12px;
  }
  .ttCatChip {
    font-size: 10px;
    padding: 3px 6px;
  }
  .ttTab {
    padding: 8px 10px;
    font-size: 11px;
  }
  .ttPackageBadge {
    font-size: 10px;
    padding: 2px 6px;
  }
  #viewTimeTracking .kpis {
    grid-template-columns: 1fr;
  }
}

/* ── Touch Devices (iPad/iPhone) ── */
@media (hover: none) and (pointer: coarse) {
  .ttTableWrap {
    -webkit-overflow-scrolling: touch;
  }
  .ttTable thead th {
    position: static;
  }
  .ttTable .act .btn {
    min-height: 44px;
    min-width: 44px;
  }
  .ttCCActions .btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ── Desktop Touch Fix (iPad in desktop mode) ── */
@media (min-width: 981px) and (hover: none) and (pointer: coarse) {
  #viewTimeTracking {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }
}

/* ── Safe Area (iPhone Notch / Dynamic Island) ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .ttDlg .dlgFt {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .ttPanel:last-child {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── Print styles ── */
@media print {
  .ttSubTabs,
  .ttJournalFilters,
  .ttDashCardActions {
    display: none !important;
  }
}
