:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2f3d;
  --text: #e8eaef;
  --text-muted: #8b92a5;
  --primary: #6c8cff;
  --primary-hover: #5a7af5;
  --success: #3dd68c;
  --warning: #f5a623;
  --danger: #f56565;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: 'Inter', 'Noto Sans JP', system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sync-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.sync-dot--ok { background: var(--success); }
.sync-dot--syncing { background: var(--primary); animation: sync-pulse 1s ease infinite; }
.sync-dot--warn { background: var(--warning); }
.sync-dot--error { background: var(--danger); }
.sync-dot--idle { background: var(--text-muted); }

#btn-sync {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.modal__hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  min-height: 1.25rem;
  margin-top: 0.25rem;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.header__logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), #9b7dff);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.header__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1.125rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

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

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

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn--sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn--success {
  background: rgba(61, 214, 140, 0.15);
  color: var(--success);
  border: 1px solid rgba(61, 214, 140, 0.3);
}

.btn--success:hover {
  background: rgba(61, 214, 140, 0.25);
}

.btn--danger {
  background: rgba(245, 101, 101, 0.12);
  color: var(--danger);
  border: 1px solid rgba(245, 101, 101, 0.25);
}

.btn--danger:hover {
  background: rgba(245, 101, 101, 0.22);
}

.btn__icon {
  font-size: 1.125rem;
  line-height: 1;
}

/* Summary */
.summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .summary {
    grid-template-columns: repeat(4, 1fr);
  }
}

.summary__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.summary__value {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.summary__value--count {
  font-size: 1.125rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.375rem;
  overflow-x: auto;
}

.tabs__btn {
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

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

.tabs__btn--active {
  background: var(--primary);
  color: #fff;
}

.tabs__badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.125rem 0.5rem;
  border-radius: 99px;
  font-size: 0.6875rem;
}

.tabs__btn--active .tabs__badge {
  background: rgba(255, 255, 255, 0.25);
}

/* List & Cards */
.list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  transition: border-color 0.15s;
}

.card:hover {
  border-color: #3a4055;
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.card__title {
  font-size: 1rem;
  font-weight: 600;
}

.card__memo {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.card__status {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.25rem 0.625rem;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

.card__status--active {
  background: rgba(108, 140, 255, 0.15);
  color: var(--primary);
}

.card__status--done {
  background: rgba(61, 214, 140, 0.15);
  color: var(--success);
}

.card__status--sub {
  background: rgba(155, 125, 255, 0.15);
  color: #b49aff;
}

.card__stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.625rem;
  margin-bottom: 0.875rem;
}

@media (min-width: 480px) {
  .card__stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .card__stats--wide {
    grid-template-columns: repeat(3, 1fr);
  }
}

.stat {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
}

.stat__label {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-bottom: 0.125rem;
}

.stat__value {
  font-size: 0.9375rem;
  font-weight: 600;
}

.stat__value--highlight {
  color: var(--primary);
}

.stat__value--success {
  color: var(--success);
}

/* Progress bar */
.progress {
  margin-bottom: 0.875rem;
}

.progress__bar {
  height: 6px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #9b7dff);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.progress__label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
}

.card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty__icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.6;
}

.empty__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.empty__desc {
  font-size: 0.875rem;
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal__content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 2rem);
  max-width: 480px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal__title {
  font-size: 1.125rem;
  font-weight: 700;
}

.modal__close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

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

.modal__desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* Form */
.form__type-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  margin-bottom: 1.25rem;
}

.type-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-option__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  padding: 0.875rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.type-option input:checked + .type-option__card {
  border-color: var(--primary);
  background: rgba(108, 140, 255, 0.08);
}

.type-option__icon {
  font-size: 1.5rem;
}

.type-option__label {
  font-size: 0.8125rem;
  font-weight: 600;
}

.form__fields {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.field-row--hidden {
  display: none;
}

.field--hidden {
  display: none;
}

.field--computed {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
}

.field__computed {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
}

.field__input--readonly {
  color: var(--text-muted);
  cursor: default;
}

.card__period {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.field__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.field__input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.field__input:focus {
  outline: none;
  border-color: var(--primary);
}

.field__input::placeholder {
  color: #555d72;
}

select.field__input {
  cursor: pointer;
}

.field__input[type="date"],
.field__input[type="month"] {
  color-scheme: dark;
  cursor: pointer;
  min-height: 2.625rem;
}

.field__input[type="date"]::-webkit-calendar-picker-indicator,
.field__input[type="month"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.date-field {
  position: relative;
}

.date-field .field__input {
  width: 100%;
  padding-right: 2.75rem;
}

.date-field__btn {
  position: absolute;
  right: 0.375rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.date-field__btn:hover {
  background: var(--surface-hover);
  color: var(--primary);
}

.date-field__btn::before {
  content: '';
  width: 1.125rem;
  height: 1.125rem;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E") center / contain no-repeat;
}

.tab-panel {
  display: none;
}

.tab-panel--active {
  display: block;
}

/* Schedule */
.schedule-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.schedule-toolbar__field {
  flex: 1 1 12rem;
  min-width: 0;
}

.schedule-toolbar__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.schedule-toolbar__hint {
  flex: 1 1 100%;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

@media (min-width: 480px) {
  .schedule-toolbar__hint {
    flex: 1 1 auto;
    margin: 0 0 0.5rem;
  }
}

.schedule {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.schedule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
}

.schedule-card--empty {
  opacity: 0.55;
}

.schedule-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.schedule-card__title {
  font-size: 1rem;
  font-weight: 700;
}

.schedule-card__sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.schedule-card__total {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.schedule-card__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.schedule-item {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 0.625rem;
  font-size: 0.875rem;
}

.schedule-item__body {
  min-width: 0;
}

.schedule-item__main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.schedule-item__meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.schedule-item--empty {
  color: var(--text-muted);
  grid-template-columns: 1fr;
}

.schedule-item__type {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  white-space: nowrap;
}

.schedule-item__type--installment {
  background: rgba(108, 140, 255, 0.15);
  color: var(--primary);
}

.schedule-item__type--subscription {
  background: rgba(155, 125, 255, 0.15);
  color: #b49aff;
}

.schedule-item__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schedule-item__amount {
  font-weight: 600;
  white-space: nowrap;
}
