/* UI components: buttons, inputs, cards, toggles */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: none;
  color: var(--danger);
  padding: 4px 8px;
  font-size: 13px;
}

.btn-danger:hover {
  background: rgba(232, 84, 84, 0.12);
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.btn-close:hover {
  color: var(--text);
}

/* Inputs */
.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--accent);
}

.input::placeholder {
  color: var(--text-dim);
}

input[type="time"].input {
  -webkit-appearance: textfield;
  appearance: textfield;
  min-width: 0;
  max-width: 100%;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b8fa3' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Form groups */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.form-group label .required {
  color: var(--danger);
  margin-left: 2px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 15px !important;
  color: var(--text) !important;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.form-actions .btn {
  flex: 1;
}

.form-category {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 14px;
  padding: 6px 10px;
  background: rgba(108, 140, 255, 0.08);
  border-radius: var(--radius-sm);
}

/* Cards (activity entries) */
.entry-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}

.entry-card:hover {
  border-color: var(--accent);
}

.entry-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.entry-card-category {
  font-weight: 600;
  font-size: 14px;
}

.entry-card-time {
  font-size: 13px;
  color: var(--text-dim);
}

.entry-card-fields {
  font-size: 13px;
  color: var(--text-dim);
}

.entry-card-fields span {
  margin-right: 12px;
}

.entry-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  justify-content: flex-end;
}

.entry-card-actions .btn {
  font-size: 12px;
  padding: 4px 10px;
}

.entry-card.editing {
  border-color: var(--accent);
  margin-bottom: calc(var(--nav-height) + 16px);
}

.entry-card-edit-form {
  margin-top: 10px;
}

.entry-card-edit-form .form-group {
  margin-bottom: 10px;
}

.entry-card-edit-form .form-actions {
  margin-top: 12px;
  padding-bottom: 4px;
  scroll-margin-bottom: calc(var(--nav-height) + 16px);
}

/* Category picker groups */
.category-group {
  margin-bottom: 6px;
}

.category-group-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s;
}

.category-group-header:hover {
  background: var(--bg-hover);
}

.category-group-header .arrow {
  margin-right: 8px;
  transition: transform 0.15s;
  font-size: 12px;
}

.category-group.open .arrow {
  transform: rotate(90deg);
}

.category-leaves {
  display: none;
  padding: 4px 0 4px 20px;
}

.category-group.open .category-leaves {
  display: block;
}

.category-leaf {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: background 0.15s;
}

.category-leaf:hover {
  background: var(--bg-hover);
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-hover);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

/* Routine progress */
.routine-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

#progress-label {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0;
}

/* Routine cards */
#routine-cards {
  padding-bottom: var(--nav-height);
}

.routine-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}

.routine-card-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  gap: 10px;
  -webkit-tap-highlight-color: transparent;
}

.routine-card-header:active {
  background: var(--bg-hover);
  border-radius: var(--radius);
}

.routine-card-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.routine-card-label {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
}

.routine-card-status {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.routine-card-check {
  font-size: 16px;
  font-weight: 700;
  color: var(--success);
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* Done state */
.routine-card.done {
  border-color: var(--success);
  background: rgba(76, 175, 124, 0.06);
}

/* Partial state (in progress, not fully done) */
.routine-card.partial {
  border-color: var(--warning);
  background: rgba(212, 168, 67, 0.06);
}

.routine-card.partial .routine-card-check {
  color: var(--warning);
}

/* Optional not-done state */
.routine-card.optional:not(.done):not(.partial) {
  border-style: dashed;
  opacity: 0.7;
}

/* Card body (expandable) */
.routine-card-body {
  padding: 0 14px 14px;
  overflow: hidden;
  min-width: 0;
}

.routine-card-body .form-group {
  margin-bottom: 10px;
}

.routine-card-body .input {
  width: 100%;
}

.routine-card-body .form-actions {
  margin-top: 12px;
}

.routine-card-info {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* Routine section headers */
.routine-section {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 18px 14px 6px;
}

.routine-section-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.routine-section-hint {
  font-size: 12px;
  color: var(--text-dim);
  opacity: 0.6;
}

/* Section progress bar (time goals) */
.section-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 8px;
}

.section-progress-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 72px;
}

.section-progress-track {
  flex: 1;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.section-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease, background 0.3s ease;
  width: 0;
  background: var(--warning);
}

.section-progress-fill.goal {
  background: var(--success);
}

.section-progress-fill.over {
  background: #4f8cff;
}

/* Saving state — prevent double-tap */
.routine-card.saving .routine-card-header {
  pointer-events: none;
  opacity: 0.6;
}
