/* app.css — Musubi component styles (TableKit-flavored) */

/* ---- Links ---- */
a { color: inherit; text-decoration: none; }
a.tk-link, .tk-link { color: var(--link); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
a.tk-link:hover, .tk-link:hover { color: var(--link-hover); }

/* ---- Surfaces ---- */
.tk-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-8);
}

/* ---- Buttons ---- */
.tk-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-sans);
  font-weight: var(--fw-medium);
  font-size: 13px;
  line-height: 1;
  padding: 7px 12px;
  border-radius: var(--radius-4);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out;
  white-space: nowrap;
  text-decoration: none;
}
.tk-btn-primary {
  background: var(--brand-primary);
  color: var(--brand-primary-text);
}
.tk-btn-primary:hover { background: var(--brand-primary-hover); }

.tk-btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.tk-btn-secondary:hover { background: var(--surface-hover); }

.tk-btn-ghost {
  background: transparent;
  color: var(--text-subtle);
}
.tk-btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.tk-btn-sm { font-size: 12px; padding: 5px 9px; }

/* ---- Badges ---- */
.tk-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  font-weight: var(--fw-medium);
  padding: 2px 8px;
  border-radius: var(--radius-4);
  line-height: 1.5;
  white-space: nowrap;
}
.tk-badge-success { background: var(--success-surface); color: var(--success-text, var(--success-500)); }
.tk-badge-warning { background: var(--warning-surface); color: var(--warning-text); }
.tk-badge-error   { background: var(--error-surface);   color: var(--error-text, var(--error-500)); }
.tk-badge-info    { background: var(--info-surface);    color: var(--info-text, var(--info-500)); }
.tk-badge-purple  { background: var(--purple-utility-surface); color: var(--purple-utility-text); }
.tk-badge-neutral { background: var(--neutral-surface); color: var(--neutral-text); }

.tk-badge.tk-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: 0.8;
}

/* ---- Form controls ---- */
.tk-input, .tk-select {
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-4);
  padding: 6px 10px;
  height: 30px;
  line-height: 1;
  width: 100%;
  outline: none;
}
.tk-input::placeholder { color: var(--text-placeholder); }
.tk-input:focus, .tk-select:focus {
  outline: 2px solid var(--brand-primary);
  outline-offset: -1px;
}
.tk-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  padding-right: 26px;
}

.tk-field-label {
  font-size: 11px;
  font-weight: var(--fw-medium);
  color: var(--text-subtle);
  margin-bottom: 4px;
  display: block;
}

/* ---- Chips ---- */
.tk-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
  font-weight: var(--fw-medium);
  background: var(--neutral-surface);
  color: var(--neutral-text);
  padding: 3px 9px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 120ms ease-out;
  border: 1px solid transparent;
}
.tk-chip:hover { background: var(--neutral-surface-hover); }
.tk-chip.active {
  background: var(--purple-utility-surface);
  color: var(--purple-utility-text);
  border-color: var(--purple-utility-border);
}
.tk-chip-count {
  font-size: 11px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

/* ---- Tables ---- */
.tk-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.tk-table thead th {
  font-size: 10px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
  text-align: left;
  padding: 8px 12px;
  background: var(--surface-low);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tk-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
}
.tk-table tbody tr:last-child td { border-bottom: 0; }
.tk-table tbody tr:hover { background: var(--surface-hover); }
.tk-table tbody tr { transition: background 80ms ease-out; }
.tk-table a { color: var(--link); }
.tk-table a:hover { color: var(--link-hover); }

/* ---- Layout ---- */
.viewport-fill {
  width: 100%; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface-low);
  color: var(--text);
  overflow: hidden;
}

/* Shell: top bar */
.tk-topbar {
  height: 48px; flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 18px 0 0;
  z-index: 2;
}
.tk-topbar-brand {
  width: 220px; display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-right: 1px solid var(--border);
  height: 100%;
  text-decoration: none;
  color: var(--text);
}
.tk-topbar-brand:hover { color: var(--text); }
.tk-brand-icon {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--purple-utility-surface);
  display: flex; align-items: center; justify-content: center;
}
.tk-brand-name { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.15; }
.tk-brand-sub { font-size: 9.5px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-subtle); }

.tk-breadcrumbs {
  flex: 1; padding-left: 18px;
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-subtle);
}
.tk-breadcrumbs a { color: var(--text-subtle); text-decoration: none; }
.tk-breadcrumbs a:hover { color: var(--text); }
.tk-breadcrumbs .current { color: var(--text); font-weight: 500; }
.tk-breadcrumbs .sep { font-size: 10px; opacity: 0.5; }

.tk-topbar-actions {
  display: flex; align-items: center; gap: 8px;
}
.tk-search-wrap {
  position: relative;
}
.tk-search-wrap input {
  width: 260px; padding-left: 28px; height: 28px; font-size: 12px;
}
.tk-search-wrap .icon {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--text-subtle);
}
.tk-search-wrap .kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  color: var(--text-subtle); font-size: 10px; padding: 1px 5px;
  border: 1px solid var(--border); border-radius: 3px;
}
.tk-avatar {
  width: 26px; height: 26px; border-radius: 999px;
  background: var(--brand-primary); color: #fff;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

/* Shell: sidebar */
.tk-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.tk-sidebar nav {
  flex: 1; padding: 14px 10px;
  display: flex; flex-direction: column; gap: 1px;
  overflow-y: auto;
}
.tk-nav-section {
  padding: 8px 10px 6px;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-subtle);
}
.tk-nav-section.mt { padding-top: 14px; }

.tk-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px; font-weight: 400;
  color: var(--text-subtle);
  position: relative;
  text-decoration: none;
  transition: background 80ms ease-out;
}
.tk-nav-item:hover { background: var(--surface-hover); color: var(--text); }
.tk-nav-item.active {
  font-weight: 500;
  color: var(--text);
  background: var(--surface-active);
}
.tk-nav-item.active::before {
  content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px;
  width: 3px; border-radius: 2px; background: var(--brand-primary);
}
.tk-nav-item .badge {
  margin-left: auto;
  font-size: 10px; color: var(--text-subtle);
}
.tk-nav-item.disabled {
  opacity: 0.5; pointer-events: none;
}

.tk-nav-icon {
  width: 16px; height: 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.tk-nav-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* Sidebar volume card */
.tk-volume-card {
  background: var(--surface-low);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.tk-volume-card .label { font-size: 10px; color: var(--text-subtle); font-weight: 500; margin-bottom: 2px; }
.tk-volume-card .value { font-family: var(--font-mono); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tk-volume-card .trend { font-size: 10px; color: var(--success-500); margin-top: 4px; }

/* Shell: body */
.tk-body-wrap {
  flex: 1; display: flex; min-height: 0;
}
.tk-main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--surface-low);
  overflow-y: auto;
}
.tk-main-content {
  flex: 1; padding: 24px;
}

/* ---- Page header ---- */
.tk-page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.tk-page-title {
  font-size: var(--text-20); font-weight: var(--fw-semibold);
  color: var(--text);
}
.tk-page-actions {
  display: flex; align-items: center; gap: 8px;
}

/* ---- Stats row ---- */
.tk-stats {
  display: flex; gap: 16px; margin-bottom: 20px;
}
.tk-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-8);
  padding: 12px 16px;
  min-width: 140px;
}
.tk-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-subtle); font-weight: 500; margin-bottom: 4px; }
.tk-stat-value { font-size: 20px; font-weight: 600; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- Flash messages ---- */
.tk-flash {
  padding: 10px 14px;
  border-radius: var(--radius-4);
  font-size: 13px;
  margin-bottom: 16px;
}
.tk-flash-success { background: var(--success-surface); color: var(--success-500); }
.tk-flash-error { background: var(--error-surface); color: var(--error-500); }
.tk-flash-info { background: var(--info-surface); color: var(--info-500); }

/* ---- Detail page ---- */
.tk-detail-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.tk-detail-row {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.tk-detail-row:last-child { border-bottom: none; }
.tk-detail-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-subtle); font-weight: 500; }
.tk-detail-value { font-size: 13px; color: var(--text); }

/* ---- Help button ---- */
.tk-help-btn {
  position: fixed;
  bottom: 16px; right: 16px;
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--brand-primary);
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 30;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}
.tk-help-btn:hover { background: var(--brand-primary-hover); transform: scale(1.05); }
.tk-help-btn svg { width: 16px; height: 16px; stroke: #fff; }

/* ---- Scrollbars ---- */
.tk-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.tk-scroll::-webkit-scrollbar-thumb { background: var(--grey-300); border-radius: 8px; }
.tk-scroll::-webkit-scrollbar-thumb:hover { background: var(--grey-400); }
.tk-scroll::-webkit-scrollbar-track { background: transparent; }

/* ---- HTMX loading ---- */
.htmx-request .tk-main-content { opacity: 0.5; transition: opacity 200ms ease-in; }
.tk-main-content { transition: opacity 200ms ease-out; }

/* ---- Insights rail ---- */
.tk-rail-wrap {
  display: flex;
  margin: -24px;
  min-height: 100%;
}
.tk-rail-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  min-width: 0;
}
.tk-insights-rail {
  width: 320px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tk-insights-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}
.tk-insights-header .hint {
  font-size: 10px;
  color: var(--text-subtle);
  font-weight: 400;
  margin-left: 4px;
}
.tk-insights-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Micro labels ---- */
.tk-micro-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* ---- Hero card ---- */
.tk-hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-8);
  padding: 20px;
  margin-bottom: 14px;
}
.tk-hero-grid-3 {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
}
.tk-hero-grid-bal {
  display: grid;
  grid-template-columns: 1.4fr 1.6fr auto;
  gap: 24px;
  align-items: center;
}
.tk-hero-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ---- Progress bar ---- */
.tk-progress {
  height: 4px;
  background: var(--surface-low);
  border-radius: 2px;
  overflow: hidden;
}
.tk-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 200ms ease-out;
}

/* ---- Link inline ---- */
.tk-link-inline { color: var(--link); }
.tk-link-inline:hover { color: var(--link-hover); text-decoration: underline; }

/* ---- Filter Strip ---- */
.tk-filter-strip {
  padding: 14px 16px;
  margin-bottom: 12px;
}
.tk-filter-strip form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tk-filter-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.tk-filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tk-filter-group + .tk-filter-group {
  margin-left: 10px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

/* Chip enhancements — micro-interactions on top of base tk-chip */
.tk-chip {
  transition: background 120ms ease-out, border-color 120ms ease-out, transform 140ms cubic-bezier(0.22, 1, 0.36, 1);
  transform: translateZ(0);
  user-select: none;
  text-decoration: none;
}
.tk-chip:hover {
  transform: scale(1.03) translateZ(0);
}
.tk-chip:active {
  transform: scale(0.96) translateZ(0);
  transition-duration: 60ms;
}
.tk-chip-active .tk-chip-count {
  color: var(--purple-utility-text);
  opacity: 0.7;
}

/* Active filter chips bar — animated entrance */
.tk-active-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 16px 10px;
}
.tk-active-filters:empty { display: none; }

.tk-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  animation: chipSlideIn 200ms cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: opacity 120ms ease-out, transform 120ms ease-out;
}
.tk-filter-chip:hover {
  opacity: 0.85;
  transform: scale(0.98);
}
.tk-filter-chip:active {
  transform: scale(0.95);
}
.tk-filter-chip .close-x {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 100ms ease-out;
}
.tk-filter-chip:hover .close-x { opacity: 1; }

@keyframes chipSlideIn {
  from { opacity: 0; transform: translateX(-8px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

/* Stagger animation delay for multiple chips */
.tk-filter-chip:nth-child(2) { animation-delay: 30ms; }
.tk-filter-chip:nth-child(3) { animation-delay: 60ms; }
.tk-filter-chip:nth-child(4) { animation-delay: 90ms; }
.tk-filter-chip:nth-child(5) { animation-delay: 120ms; }

.tk-clear-filters {
  font-size: 11px;
  color: var(--text-subtle);
  text-decoration: none;
  padding: 3px 8px;
  border-radius: 999px;
  transition: all 120ms ease-out;
}
.tk-clear-filters:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Date input styling */
.tk-date-input {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-4);
  padding: 4px 8px;
  height: 26px;
  width: 120px;
  outline: none;
  transition: border-color 120ms ease-out;
}
.tk-date-input:focus {
  outline: 2px solid var(--brand-primary);
  outline-offset: -1px;
}

/* ---- Page bezels (create/edit = warning, delete = danger) ---- */
/* Full-page top + bottom bezel bars — inset shadow on the scroll container */
.tk-main:has(.tk-main-content.tk-bezel-warning) {
  box-shadow: inset 0 4px 0 0 var(--warning-500), inset 0 -4px 0 0 var(--warning-500);
}
.tk-main:has(.tk-main-content.tk-bezel-danger) {
  box-shadow: inset 0 4px 0 0 var(--error-500), inset 0 -4px 0 0 var(--error-500);
}

.tk-bezel-warning-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warning-text);
  background: var(--warning-surface);
  padding: 3px 10px;
  border-radius: var(--radius-4);
  border: 1px solid var(--warning-500);
  margin-bottom: 14px;
}

/* ---- Danger confirmation modal ---- */
.tk-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 800;
  display: none;
  animation: modalFadeIn 150ms ease-out;
}
.tk-modal-backdrop.is-visible { display: flex; align-items: center; justify-content: center; }

.tk-modal-danger {
  background: var(--surface);
  border: 2px solid var(--error-500);
  border-radius: 12px;
  box-shadow: 0 0 0 4px rgba(204, 0, 0, 0.10), var(--shadow-dialog, 0 8px 32px rgba(0,0,0,0.18));
  width: 440px;
  max-width: 90vw;
  overflow: hidden;
  animation: modalScaleIn 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.tk-modal-danger-bar {
  height: 4px;
  background: var(--error-500);
}
.tk-modal-danger-body {
  padding: 24px;
}
.tk-modal-danger-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--error-surface);
  color: var(--error-500);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.tk-modal-danger-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.tk-modal-danger-text {
  font-size: 13px;
  color: var(--text-subtle);
  line-height: 1.5;
  margin-bottom: 20px;
}
.tk-modal-danger-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}
.tk-btn-danger {
  background: var(--error-500);
  color: #fff;
  border-color: var(--error-500);
}
.tk-btn-danger:hover {
  background: #b30000;
  border-color: #b30000;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalScaleIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---- Utility ---- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
