*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #191919;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Toolbar ──────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #222;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  gap: 12px;
  height: 48px;
}

.app-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}

.toolbar-right {
  display: flex;
  gap: 5px;
  align-items: center;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: #3a3a3a;
  margin: 0 4px;
}

#zoom-controls {
  display: flex;
  gap: 5px;
  align-items: center;
}
#zoom-controls.hidden { display: none; }

.btn {
  background: #2e2e2e;
  color: #d0d0d0;
  border: 1px solid #3a3a3a;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn:hover { background: #3a3a3a; color: #fff; }

.btn-primary { background: #4a9eff; color: #fff; border-color: #4a9eff; }
.btn-primary:hover { background: #3a8eef; border-color: #3a8eef; }

.btn-danger { background: #c0392b; color: #fff; border-color: #c0392b; }
.btn-danger:hover { background: #a93226; }

.btn-toggle { min-width: 74px; }
.btn-toggle.active {
  background: rgba(74, 158, 255, 0.12);
  border-color: #4a9eff;
  color: #4a9eff;
}

/* ── Timeline scroll container ────────────────────────── */
.timeline-outer {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
  user-select: none;
}
.timeline-outer.dragging {
  cursor: grabbing !important;
}
.timeline-outer.dragging .tl-item {
  pointer-events: none;
}

.timeline-inner {
  position: relative;
}

/* ── Sticky header ────────────────────────────────────── */
.tl-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 52px;
  background: #222;
  border-bottom: 1px solid #3a3a3a;
}

.tl-header-corner {
  position: sticky;
  left: 0;
  z-index: 21;
  background: #222;
  border-right: 1px solid #3a3a3a;
  flex-shrink: 0;
}

.tl-header-dates {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.tl-month-label {
  position: absolute;
  top: 5px;
  padding-left: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
}

.tl-tick-label {
  position: absolute;
  bottom: 5px;
  font-size: 0.65rem;
  color: #555;
  pointer-events: none;
  white-space: nowrap;
}

.tl-tick-line {
  position: absolute;
  top: 0;
  width: 1px;
  pointer-events: none;
}

/* ── Category section ─────────────────────────────────── */
.tl-section {
  display: flex;
  border-bottom: 1px solid #252525;
}

.tl-label {
  position: sticky;
  left: 0;
  z-index: 10;
  background: #1d1d1d;
  border-right: 1px solid #2e2e2e;
  display: flex;
  align-items: flex-start;
  padding: 10px 10px 10px 12px;
  flex-shrink: 0;
}

.tl-label-text {
  font-size: 0.7rem;
  font-weight: 700;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.3;
  word-break: break-word;
}

.tl-label-uncat .tl-label-text {
  color: #444;
  font-style: italic;
}

.tl-rows-area {
  position: relative;
  flex-shrink: 0;
}

.tl-grid-line {
  position: absolute;
  top: 0;
  width: 1px;
  background: rgba(255,255,255,0.035);
  pointer-events: none;
  z-index: 1;
}

.today-line {
  position: absolute;
  top: 0;
  width: 2px;
  background: rgba(255, 75, 75, 0.7);
  pointer-events: none;
  z-index: 4;
  border-radius: 1px;
}

.today-dot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 75, 75, 0.9);
  pointer-events: none;
  z-index: 22;
}

/* ── Item bars ────────────────────────────────────────── */
.tl-item {
  position: absolute;
  border-radius: 5px;
  display: flex;
  align-items: center;
  padding: 0 9px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  z-index: 2;
  transition: filter 0.12s, box-shadow 0.12s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.tl-item:hover {
  filter: brightness(1.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  z-index: 3;
}
.tl-item span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Items are always pointer — both modes do something on click */
.tl-item { cursor: pointer; }

/* Empty state */
.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: #555;
  line-height: 1.8;
  font-size: 0.9rem;
}
.empty-state strong { color: #777; }

/* ── Item popup (view mode) ───────────────────────────── */
.item-popup {
  position: fixed;
  z-index: 60;
  background: #242424;
  border: 1px solid #3a3a3a;
  border-radius: 10px;
  width: 268px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.65);
  overflow: hidden;
  pointer-events: none;
}
.item-popup.hidden { display: none; }

.popup-header {
  padding: 11px 14px 9px;
}
.popup-name {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.popup-dates {
  font-size: 0.72rem;
  opacity: 0.75;
  font-weight: 500;
}
.popup-body {
  padding: 9px 14px 12px;
}
.popup-cat {
  font-size: 0.72rem;
  color: #777;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.popup-desc {
  font-size: 0.82rem;
  color: #bbb;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.popup-nodesc {
  font-size: 0.78rem;
  color: #444;
  font-style: italic;
}

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #242424;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  padding: 24px;
  width: 380px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 700;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal input[type="text"],
.modal input[type="date"],
.modal textarea {
  background: #2e2e2e;
  border: 1px solid #444;
  border-radius: 6px;
  color: #e0e0e0;
  padding: 7px 10px;
  font-size: 0.88rem;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.12s;
}
.modal textarea {
  resize: vertical;
  min-height: 64px;
  line-height: 1.5;
}
.modal input[type="text"]:focus,
.modal input[type="date"]:focus,
.modal textarea:focus {
  outline: none;
  border-color: #4a9eff;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}
.modal input[type="color"] {
  height: 34px;
  width: 50px;
  padding: 2px 3px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2e2e2e;
  cursor: pointer;
  flex-shrink: 0;
}
.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.1s, transform 0.1s;
  flex-shrink: 0;
}
.color-swatch:hover  { transform: scale(1.2); border-color: #fff; }
.color-swatch.active { border-color: #fff; }

.modal-btns {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

/* ── Passphrase modal extras ──────────────────────────── */
.modal-hint {
  font-size: 0.82rem;
  color: #888;
  line-height: 1.55;
  margin-top: -4px;
}
.modal-hint strong { color: #aaa; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 0.82rem !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: #aaa !important;
  font-weight: 400 !important;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #4a9eff;
  cursor: pointer;
  flex-shrink: 0;
}

.passphrase-error {
  font-size: 0.82rem;
  color: #e74c3c;
  padding: 4px 0;
}

/* ── Save status indicator ────────────────────────────── */
.save-status {
  font-size: 0.75rem;
  color: transparent;
  min-width: 60px;
  text-align: right;
  transition: color 0.3s;
}
.save-status.saving { color: #666; }
.save-status.saved  { color: #2ecc71; }
.save-status.error  { color: #e74c3c; }

/* ── Icon button ──────────────────────────────────────── */
.btn-icon {
  padding: 5px 8px;
  font-size: 0.9rem;
}

/* ── Table view ───────────────────────────────────────── */
.table-wrapper {
  padding: 16px 20px 32px;
  min-width: max-content;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  text-align: left;
  padding: 7px 10px;
  color: #555;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid #333;
  background: #1f1f1f;
  position: sticky;
  top: 0;
  z-index: 5;
  white-space: nowrap;
}

.data-table th:first-child { border-radius: 6px 0 0 0; }
.data-table th:last-child  { border-radius: 0 6px 0 0; }

/* Category group header rows */
.tbl-cat-row td {
  padding: 14px 10px 5px;
  color: #555;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid #2a2a2a;
  background: #191919;
}

.tbl-row {
  border-bottom: 1px solid #232323;
  transition: background 0.08s;
}
.tbl-row:hover { background: #202020; }

.tbl-cell { padding: 3px 6px; }

/* Color cell */
.tbl-color-cell {
  padding: 3px 10px;
  width: 42px;
  min-width: 42px;
}
.tbl-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.12s, transform 0.12s;
  flex-shrink: 0;
}
.tbl-swatch:hover { border-color: #fff; transform: scale(1.12); }
.tbl-color-input  { display: none; }

/* Table inputs */
.tbl-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: #d0d0d0;
  padding: 5px 8px;
  font-size: 0.84rem;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.1s, background 0.1s;
}
.tbl-input:hover  { border-color: #3a3a3a; background: #252525; }
.tbl-input:focus  { outline: none; border-color: #4a9eff; background: #2a2a2a; }

.tbl-date { min-width: 120px; color-scheme: dark; }
.tbl-name { min-width: 160px; }
.tbl-cat-input { min-width: 110px; }
.tbl-desc-input { min-width: 200px; }

.tbl-del-cell { padding: 3px 8px; width: 36px; min-width: 36px; }
.tbl-del-btn  { padding: 3px 8px; font-size: 1rem; line-height: 1; }

.table-add-btn {
  margin-top: 10px;
  display: inline-block;
}
