:root {
  --ink: #1c1c1c;
  --header: #1f2430;
  --header-ink: #f4f5f7;
  --canvas: #f3f4f6;
  --sheet: #ffffff;
  --line: #e2e4e8;
  --line-strong: #c8ccd4;
  --muted: #5c6470;
  --blue: #2f5fd0;
  --blue-soft: #e8eefb;
  --accent: #2f5fd0;
  --green: #2a7a52;
  --red: #b42318;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(28, 28, 28, 0.06), 0 6px 16px rgba(28, 28, 28, 0.05);
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --nav-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

button, input, select { font: inherit; }

a { color: inherit; }

.tm-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--nav-h);
  padding: 8px 16px;
  background: var(--header);
  color: var(--header-ink);
  flex-shrink: 0;
}

.tm-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tm-nav-logo,
.tm-nav-section {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--header-ink);
  white-space: nowrap;
}

.tm-nav-logo {
  font-weight: 650;
  font-size: 0.9rem;
  opacity: 0.8;
}

.tm-nav-logo:hover { opacity: 1; }

.tm-nav-section {
  font-weight: 650;
  font-size: 0.95rem;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.16);
}

.tm-nav-section img { filter: brightness(0) invert(1); }

.tm-nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tm-nav-links a {
  color: rgba(244, 245, 247, 0.82);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}

.tm-nav-links a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }

.tm-status {
  font-size: 0.75rem;
  color: rgba(244, 245, 247, 0.62);
  padding: 0 6px;
}

.tm-status[data-tone="ok"] { color: #9ad4b3; }
.tm-status[data-tone="bad"] { color: #f3b4ad; }

.tm-btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 650;
  cursor: pointer;
  background: #3a4150;
  color: #fff;
}

.tm-btn:hover { background: #454d5e; }

.tm-btn-export {
  background: var(--accent);
  color: #fff;
}

.tm-btn-export:hover { background: #274ea8; }

.tm-btn-ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

.tm-btn-ghost:hover { background: #f7f8fa; }

.tm-shell { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.tm-landing,
.tm-app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tm-landing[hidden],
.tm-app[hidden] { display: none !important; }

.tm-hero {
  max-width: 40rem;
  margin: 40px auto 0;
  padding: 0 20px 24px;
}

.tm-hero h1 {
  font-size: 1.55rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0 0 10px;
}

.tm-hero p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.98rem;
}

.tm-hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px 0;
}

.tm-faces,
.tm-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tm-faces {
  padding: 3px;
  background: #e8eaee;
  border-radius: var(--radius);
}

.tm-pill {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
}

.tm-pill.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(28, 28, 28, 0.08);
}

.tm-title {
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-weight: 650;
  font-size: 0.98rem;
  min-width: 10rem;
  max-width: 22rem;
}

.tm-title:hover,
.tm-title:focus {
  border-color: var(--line-strong);
  background: #fff;
  outline: none;
}

.tm-well {
  flex: 1;
  min-height: 0;
  margin: 12px 16px 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

.tm-grid-wrap { min-width: max-content; }

.tm-grid {
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.tm-grid th,
.tm-grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0;
  vertical-align: middle;
}

.tm-grid-corner,
.tm-grid-rowhead,
.tm-grid-colhead {
  background: #f4f5f7;
  color: var(--muted);
  font-weight: 650;
  position: sticky;
}

.tm-grid-corner {
  left: 0;
  top: 0;
  z-index: 3;
  min-width: 36px;
  width: 36px;
}

.tm-grid-rowhead {
  left: 0;
  z-index: 1;
  width: 36px;
  text-align: center;
  font-size: 11px;
}

.tm-grid-colhead {
  top: 0;
  z-index: 2;
  min-width: 140px;
  text-align: left;
}

.tm-grid-colhead.is-grouped { background: #e8eefb; }

.tm-grid-cell.is-grouped { background: #f7f9fd; font-weight: 650; }

.tm-grid-band {
  position: sticky;
  left: 0;
  background: #eef2f8;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.tm-grid-band-label {
  font-weight: 650;
  color: var(--ink);
  margin-right: 10px;
}

.tm-grid-band-count {
  font-size: 11px;
  color: var(--muted);
}

.tm-groupby {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 4px 6px 4px 10px;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--muted);
}

.tm-groupby select {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 8px 4px 0;
  font-weight: 650;
  color: var(--ink);
  cursor: pointer;
  max-width: 12rem;
}

.tm-groupby select:focus { outline: none; }

.tm-grid-letter {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 4px 8px 0;
  text-align: left;
  cursor: pointer;
}

.tm-grid-colname {
  border: 0;
  background: #fff;
  border-radius: var(--radius-sm);
  margin: 2px 6px 0;
  width: calc(100% - 12px);
  padding: 4px 6px;
  font-weight: 650;
  color: var(--ink);
}

.tm-grid-colname:focus {
  outline: 2px solid var(--blue);
  outline-offset: 0;
}

.tm-grid-colhint {
  display: block;
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px 5px;
  color: var(--muted);
}

.tm-grid-colhead.is-sel-col,
.tm-grid-rowhead.is-sel-row { background: var(--blue-soft); color: var(--ink); }

.tm-grid-cell {
  min-width: 140px;
  height: 30px;
  padding: 0 8px;
  cursor: cell;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-grid-cell.is-selected {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  background: #fff;
  z-index: 1;
  position: relative;
}

.tm-grid-edit {
  width: 100%;
  height: 30px;
  border: 0;
  padding: 0 8px;
  outline: none;
  background: #fff;
}

.tm-form-wrap { padding: 16px; }

.tm-group { margin-bottom: 18px; }

.tm-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.tm-group-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.tm-group-count {
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
}

.tm-btn-sm { padding: 5px 10px; font-size: 0.75rem; }

.tm-btn-add {
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
}

.tm-form-footer { padding-top: 4px; }

.tm-icon-btn {
  appearance: none;
  border: 0;
  background: #f3f4f6;
  color: var(--muted);
  border-radius: var(--radius-sm);
  width: 24px;
  height: 24px;
  font-size: 15px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.tm-icon-btn:hover { background: #e8eaee; color: var(--ink); }

.tm-cards-wrap { padding: 16px; }

.tm-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.tm-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px 14px 14px;
}

.tm-card.is-selected { outline: 2px solid var(--blue); }

.tm-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.tm-card-num {
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
}

.tm-card-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-card-fields { display: grid; gap: 8px; }

.tm-field { display: grid; gap: 4px; }

.tm-field-name {
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
}

.tm-field-input {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  background: #fff;
}

.tm-field-input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 0;
}

.tm-cards-empty {
  color: var(--muted);
  display: grid;
  gap: 10px;
  justify-items: start;
}

@media (max-width: 720px) {
  .tm-nav { flex-wrap: wrap; }
  .tm-title { max-width: none; flex: 1; }
  .tm-grid-cell,
  .tm-grid-colhead { min-width: 110px; }
}
