:root {
  --bg: #1c1c1e;
  --surface: #2c2c2e;
  --text: #f5f5f7;
  --text-muted: #98989d;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --danger: #ff453a;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

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

.header-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.header-actions .btn-header {
  height: 40px;
  padding: 0 12px;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.header-actions .btn-icon-only {
  width: 40px;
  height: 40px;
  padding: 0;
  min-width: 40px;
  min-height: 40px;
  max-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.header-actions .icon-settings {
  font-size: 1.1rem;
  line-height: 0;
  display: block;
}

.header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

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

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-icon:hover,
.btn-icon:focus {
  background: #3a3a3c;
}

.date-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px;
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

#current-date {
  font-weight: 600;
  font-size: 1rem;
}

.counters-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.counter-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.counter-info {
  flex: 1;
  min-width: 0;
}

.counter-name {
  font-weight: 600;
  margin: 0 0 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.counter-unit {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.counter-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.counter-value {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 2ch;
  text-align: right;
}

.counter-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.counter-actions .btn-icon {
  width: 36px;
  height: 36px;
  font-size: 1.2rem;
}

.counter-actions .btn-minus {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 8px 0;
}

.empty-state.hidden,
.loading.hidden,
.error.hidden {
  display: none;
}

.loading {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
}

.error {
  padding: 12px;
  margin-top: 16px;
  background: rgba(255, 69, 58, 0.15);
  color: var(--danger);
  border-radius: var(--radius);
}

/* Модальное окно добавления/редактирования */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal-overlay.hidden {
  display: none;
}

.modal-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.modal h2 {
  margin: 0 0 20px 0;
  font-size: 1.25rem;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 1px solid #3a3a3c;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.form-group select {
  cursor: pointer;
  appearance: auto;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

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

.btn-secondary {
  background: #3a3a3c;
  color: var(--text);
}

.btn-secondary:hover,
.btn-secondary:focus {
  background: #48484a;
}

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

.btn-danger:hover,
.btn-danger:focus {
  background: #ff6961;
}

.form-group-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.form-group-row label:first-child,
.form-group-row .form-group-row-label {
  margin-bottom: 0;
}

.form-group-row-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-hint {
  margin: 6px 0 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toggle {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
  padding: 6px;
  margin: -6px;
  cursor: pointer;
}

/* Скрываем нативный чекбокс (перебиваем .form-group input), показываем только .toggle-slider */
.form-group .toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  border: none;
  appearance: none;
  -webkit-appearance: none;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #3a3a3c;
  border-radius: 28px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

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

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