:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-alt: #f7f8fb;
  --ink: #161a24;
  --muted: #626b7a;
  --line: #d9dee8;
  --line-strong: #c6cddb;
  --mint: #16836f;
  --mint-soft: #dff3ee;
  --blue: #315f9f;
  --blue-soft: #e2ebf7;
  --coral: #b94f45;
  --coral-soft: #fae8e5;
  --gold: #8d651d;
  --gold-soft: #f4e8d0;
  --violet: #694c96;
  --violet-soft: #ece4f6;
  --shadow-lg: 0 24px 72px rgba(20, 27, 43, 0.2);
  --shadow-md: 0 12px 32px rgba(20, 27, 43, 0.12);
  --shadow-sm: 0 1px 3px rgba(20, 27, 43, 0.08);
  --radius: 8px;
  --radius-sm: 7px;
  --t: 0.14s ease;
}

* { box-sizing: border-box; }
html { height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.86), rgba(255,255,255,0) 34%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  transition: background-color var(--t), border-color var(--t), color var(--t), box-shadow var(--t), transform var(--t), filter var(--t);
}
button:active:not(:disabled) { transform: scale(0.96); }
h1, h2, p { margin: 0; }
h1, h2 { letter-spacing: 0; }
p { color: var(--muted); font-size: 0.82rem; line-height: 1.35; }
svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sprite { display: none; }

[data-tone="mint"]   { --accent: var(--mint);   --soft: var(--mint-soft); }
[data-tone="blue"]   { --accent: var(--blue);   --soft: var(--blue-soft); }
[data-tone="coral"]  { --accent: var(--coral);  --soft: var(--coral-soft); }
[data-tone="gold"]   { --accent: var(--gold);   --soft: var(--gold-soft); }
[data-tone="violet"] { --accent: var(--violet); --soft: var(--violet-soft); }

.app-shell {
  width: min(1180px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
}

.topbar,
.capture-panel,
.timeline-section {
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--mint);
  background: var(--mint-soft);
  border: 1px solid #bdded7;
  border-radius: 50%;
}
.brand-mark svg { width: 24px; height: 24px; }

h1 {
  font-size: clamp(1.08rem, 2vw, 1.34rem);
  font-weight: 820;
  line-height: 1.08;
}

h2 {
  color: #252b38;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, calc(100dvh - 102px)) auto;
  gap: 12px;
}

.capture-panel,
.timeline-section {
  min-height: 0;
  overflow: hidden;
}

.capture-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.time-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(48px, auto)) minmax(195px, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 7px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.strip-mode {
  min-width: 44px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 750;
  text-align: center;
}

.chip,
.segmented button,
.ghost-button,
.secondary-button,
.primary-button,
.icon-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
}

.chip {
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 720;
}
.chip:hover { background: #eef2f8; }
.chip.active,
.segmented button.active {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.time-input {
  min-width: 0;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 9px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color var(--t), box-shadow var(--t);
}
.time-input:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(49, 95, 159, 0.13);
}
.time-input input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 0.86rem;
}

.event-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 9px;
}

.event-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}
.event-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-top {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.event-icon {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--accent);
  background: var(--soft);
  border-radius: 50%;
}

.card-label {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  font-weight: 820;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.running-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--coral);
  animation: blink 1.3s ease-in-out infinite;
}

.card-elapsed {
  min-height: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  padding: 2px;
  text-align: center;
}

.elapsed-sub {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 820;
  letter-spacing: 0.05em;
  line-height: 1;
  text-transform: uppercase;
}

.elapsed-val {
  color: var(--accent);
  font-size: clamp(1.36rem, 3.4vw, 2rem);
  font-weight: 860;
  line-height: 1;
  letter-spacing: 0;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.48; } }
.elapsed-val.session-live {
  color: var(--coral);
  animation: pulse 1.3s ease-in-out infinite;
}

.card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.quick-add {
  min-width: 0;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 9px;
  overflow: hidden;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: #fff;
  background: var(--accent);
  font-size: 0.84rem;
  font-weight: 760;
  white-space: nowrap;
}
.quick-add:hover { filter: brightness(0.9); }

.session-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  background: var(--soft);
}
.session-btn:hover { filter: brightness(0.95); }
.session-btn.running {
  color: #fff;
  background: var(--coral);
  border-color: var(--coral);
}

.timeline-section {
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
  padding: 12px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.segmented button {
  min-width: 60px;
  min-height: 32px;
  border: 0;
  border-radius: 0;
  font-size: 0.82rem;
  font-weight: 720;
}

.timeline {
  display: grid;
  align-content: start;
  gap: 7px;
  overflow: visible;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  background: var(--panel-alt);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  font-size: 0.86rem;
  text-align: center;
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.entry-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent, var(--line));
  border-radius: var(--radius-sm);
  background: #fff;
  animation: rowIn 0.17s ease both;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}
.entry-row:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  transform: translateX(1px);
}

.entry-stamp { min-width: 0; }
.entry-time {
  font-size: 0.88rem;
  font-weight: 820;
  line-height: 1.1;
}
.entry-date {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.1;
  text-transform: uppercase;
}
.entry-main { min-width: 0; }

.entry-label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 820;
  line-height: 1.15;
}
.entry-label svg {
  flex: 0 0 auto;
  color: var(--accent, var(--blue));
}
.entry-label span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-meta {
  margin-top: 3px;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 0.76rem;
  line-height: 1.3;
}

.row-actions {
  display: flex;
  gap: 2px;
}

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  font-size: 1.18rem;
}
.icon-button:hover {
  color: var(--ink);
  background: #eef2f8;
  border-color: var(--line);
}

.ghost-button,
.secondary-button,
.primary-button {
  min-width: 82px;
  padding: 0 13px;
  font-size: 0.84rem;
  font-weight: 760;
}
.ghost-button {
  color: var(--muted);
  background: #fff;
}
.ghost-button:hover {
  color: var(--ink);
  background: #eef2f8;
}
.secondary-button { background: #f1f4f8; }
.secondary-button:hover { background: #e7ebf2; }
.primary-button {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}
.primary-button:hover { filter: brightness(0.92); }

.entry-dialog {
  width: min(700px, calc(100% - 20px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.entry-dialog::backdrop {
  background: rgba(10, 16, 36, 0.55);
  backdrop-filter: blur(4px);
}
.entry-dialog form {
  max-height: calc(100dvh - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 18px 20px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.form-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  overflow: auto;
  padding-right: 2px;
}

label,
fieldset {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: #fff;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  transition: border-color var(--t), box-shadow var(--t);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(49, 95, 159, 0.13);
}
textarea { resize: vertical; }
.full { grid-column: 1 / -1; }

.check-row {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.check-row legend { padding: 0 4px; }
.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-right: 14px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 560;
  letter-spacing: 0;
  text-transform: none;
}
.check-row input {
  width: auto;
  min-height: auto;
}

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 9px;
  align-items: center;
  margin: 14px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

#deleteFromDialog {
  color: var(--coral);
  background: transparent;
  border-color: transparent;
}
#deleteFromDialog:hover { background: var(--coral-soft); }

.export-box {
  min-height: min(270px, 54dvh);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  transform: translateX(-50%);
}
.toast {
  padding: 9px 18px;
  border-radius: 999px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 4px 22px rgba(0,0,0,0.24);
  font-size: 0.84rem;
  font-weight: 760;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
}
.toast--visible { opacity: 1; transform: translateY(0) scale(1); }
.toast--success { background: var(--mint); }
.toast--error { background: var(--coral); }
.toast--info { background: #485068; }

.hidden { display: none !important; }
.saving button {
  animation: pulse 1.1s ease-in-out infinite;
  pointer-events: none;
}

@media (max-width: 900px) {
  .app-shell { padding: 9px; gap: 8px; }
  .workspace {
    grid-template-rows: minmax(0, calc(100dvh - 84px)) auto;
    gap: 8px;
  }
  .capture-panel,
  .timeline-section { padding: 9px; }
  .event-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .event-card { padding: 8px; gap: 6px; }
  .elapsed-val { font-size: clamp(1.22rem, 5vw, 1.7rem); }
}

@media (max-width: 640px) {
  .topbar {
    min-height: 58px;
    padding: 8px 9px;
  }
  .brand { gap: 8px; }
  .brand-mark {
    width: 34px;
    height: 34px;
  }
  .brand-mark svg {
    width: 20px;
    height: 20px;
  }
  h1 { font-size: 1.02rem; }
  p { font-size: 0.74rem; }
  .ghost-button { min-width: 70px; padding: 0 9px; }
  .workspace { grid-template-rows: minmax(0, calc(100dvh - 76px)) auto; }
  .panel-head { display: none; }
  .capture-panel { grid-template-rows: auto minmax(0, 1fr); }
  .time-strip {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 6px;
  }
  .time-input {
    grid-column: 1 / -1;
    order: 2;
  }
  .strip-mode {
    display: none;
  }
  .chip {
    min-width: 0;
    padding: 0 6px;
  }
  .event-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .event-card {
    grid-template-rows: auto minmax(42px, 1fr) auto;
    padding: 7px;
  }
  .event-icon {
    width: 26px;
    height: 26px;
  }
  .card-label { font-size: 0.82rem; }
  .elapsed-sub { font-size: 0.58rem; }
  .quick-add {
    min-height: 32px;
    font-size: 0.78rem;
  }
  .session-btn {
    width: 32px;
    height: 32px;
  }
  .timeline-section { gap: 8px; }
  .entry-row {
    grid-template-columns: 46px minmax(0, 1fr) auto;
    gap: 7px;
    padding: 7px;
  }
  .entry-date { display: none; }
  .entry-meta {
    max-height: 2.6em;
    overflow: hidden;
  }
  .row-actions .icon-button {
    width: 28px;
    height: 28px;
  }
  .form-grid { grid-template-columns: 1fr; }
  .dialog-actions {
    grid-template-columns: 1fr 1fr;
  }
  .dialog-actions span { display: none; }
}

@media (max-height: 620px) and (min-width: 901px) {
  .app-shell { padding: 8px; gap: 8px; }
  .topbar { min-height: 56px; padding: 8px 10px; }
  .brand-mark {
    width: 34px;
    height: 34px;
  }
  .brand-mark svg {
    width: 20px;
    height: 20px;
  }
  .capture-panel,
  .timeline-section {
    padding: 9px;
  }
  .event-card {
    padding: 8px;
    gap: 6px;
  }
  .quick-add,
  .session-btn {
    min-height: 32px;
    height: 32px;
  }
  .elapsed-val { font-size: clamp(1.18rem, 3vw, 1.55rem); }
}
